Adds country name support to Locale

This commit is contained in:
konsoletyper 2014-05-14 21:29:32 +04:00
parent f6055c5f78
commit 2e5cdc109b
2 changed files with 23 additions and 4 deletions

View File

@ -34,8 +34,9 @@ public class LocaleNativeGenerator implements Generator, DependencyPlugin {
switch (methodRef.getName()) {
case "getDisplayCountry":
writer.append("var result = ").appendClass("java.util.Locale").append(".$CLDR[$rt_ustr(")
.append(context.getParameterName(1)).append(")].territories[$rt_ustr(")
.append(context.getParameterName(2)).append(")];").softNewLine();
.append(context.getParameterName(1)).append(")];").softNewLine();
writer.append("result = result ? result.territories[$rt_ustr(")
.append(context.getParameterName(2)).append(")] : undefined;").softNewLine();
writer.append("return result ? $rt_str(result) : null").softNewLine();
break;
case "getDisplayLanguage":

View File

@ -30,12 +30,30 @@ public class LocaleTest {
}
@Test
public void localeNamesProvided() {
Locale english = new Locale("en", "US");
public void languageNamesProvided() {
Locale english = new Locale("en", "");
Locale usEnglish = new Locale("en", "US");
Locale russian = new Locale("ru", "RU");
assertEquals("English", english.getDisplayLanguage(english));
assertEquals("English", english.getDisplayLanguage(usEnglish));
assertEquals("Russian", russian.getDisplayLanguage(english));
assertEquals("English", english.getDisplayLanguage(usEnglish));
assertEquals("Russian", russian.getDisplayLanguage(usEnglish));
assertEquals("английский", english.getDisplayLanguage(russian));
assertEquals("русский", russian.getDisplayLanguage(russian));
}
@Test
public void countryNamesProvided() {
Locale usEnglish = new Locale("en", "US");
Locale gbEnglish = new Locale("en", "GB");
Locale russian = new Locale("ru", "RU");
assertEquals("United Kingdom", gbEnglish.getDisplayCountry(usEnglish));
assertEquals("United States", usEnglish.getDisplayCountry(usEnglish));
assertEquals("Russia", russian.getDisplayCountry(usEnglish));
// JVM gives here name that differs to the name provided by CLDR
//assertEquals("Соединенное Королевство", gbEnglish.getDisplayCountry(russian));
assertEquals("Соединенные Штаты", usEnglish.getDisplayCountry(russian));
assertEquals("Россия", russian.getDisplayCountry(russian));
}
}