Closed BertOnline closed 6 years ago
The problematic method:
public static LocaleFacet createFor(final String localeString, final Log log) throws MojoExecutionException {
// Check sanity
Validate.notNull(log, "log");
Validate.notEmpty(localeString, "localeString");
final StringTokenizer tok = new StringTokenizer(localeString, ",", false);
final int numTokens = tok.countTokens();
if (numTokens > 3 || numTokens == 0) {
throw new MojoExecutionException("A localeString must consist of up to 3 comma-separated parts on the "
+ "form <language>[,<country>[,<variant>]]. Received incorrect value '" + localeString + "'");
}
Locale locale = null;
switch (numTokens) {
case 3:
locale = new Locale(tok.nextToken().trim(), tok.nextToken().trim(), tok.nextToken().trim());
break;
case 2:
locale = new Locale(tok.nextToken().trim(), tok.nextToken().trim());
break;
default:
locale = new Locale(tok.nextToken().trim());
break;
}
// All done.
return new LocaleFacet(log, locale);
}
Temporary solution:
public static LocaleFacet createFor(final String localeString, final Log log) throws MojoExecutionException {
// Check sanity
Validate.notNull(log, "log");
Validate.notEmpty(localeString, "localeString");
final StringTokenizer tok = new StringTokenizer(localeString, ",", false);
final int numTokens = tok.countTokens();
if (numTokens > 3 || numTokens == 0) {
throw new MojoExecutionException("A localeString must consist of up to 3 comma-separated parts on the "
+ "form <language>[,<country>[,<variant>]]. Received incorrect value '" + localeString + "'");
}
Locale locale = null;
switch (numTokens) {
case 3:
locale = new Locale(tok.nextToken().trim(), tok.nextToken().trim(), tok.nextToken().trim());
break;
case 2:
locale = new Locale(tok.nextToken().trim(), tok.nextToken().trim());
break;
default:
locale = new Locale(tok.nextToken().trim());
break;
}
// ###############################
if ("zh_CN".equals(localeString) || "zh".equals(localeString)) {
locale = Locale.SIMPLIFIED_CHINESE;
}
if ("zh_TW".equals(localeString)) {
locale = Locale.TRADITIONAL_CHINESE;
}
// ###############################
// All done.
return new LocaleFacet(log, locale);
}
}
The root cause is the java.util.Locale#convertOldISOCodes method, language = LocaleUtils.toLowerString(language).intern();
This is a problematic implementation within the JDK, as far as I can tell. However, this is a fairly simple problem to solve.
When the local setting in the configuration tab is 'zh' or 'zh_CN' or 'zh_TW', the generated source comment is in English. org.codehaus.mojo.jaxb2.shared.environment.locale.LocaleFacet#createFor method returns 'zh_cn' instead of 'zh_CN', so the constructor will set the property 'newLocale' to 'zh_cn', causing the Locale to fail to match the 'zh_CN' and eventually using the default value 'en'.