mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Adds country name support to Locale
This commit is contained in:
parent
f6055c5f78
commit
2e5cdc109b
|
@ -34,8 +34,9 @@ public class LocaleNativeGenerator implements Generator, DependencyPlugin {
|
||||||
switch (methodRef.getName()) {
|
switch (methodRef.getName()) {
|
||||||
case "getDisplayCountry":
|
case "getDisplayCountry":
|
||||||
writer.append("var result = ").appendClass("java.util.Locale").append(".$CLDR[$rt_ustr(")
|
writer.append("var result = ").appendClass("java.util.Locale").append(".$CLDR[$rt_ustr(")
|
||||||
.append(context.getParameterName(1)).append(")].territories[$rt_ustr(")
|
.append(context.getParameterName(1)).append(")];").softNewLine();
|
||||||
.append(context.getParameterName(2)).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();
|
writer.append("return result ? $rt_str(result) : null").softNewLine();
|
||||||
break;
|
break;
|
||||||
case "getDisplayLanguage":
|
case "getDisplayLanguage":
|
||||||
|
|
|
@ -30,12 +30,30 @@ public class LocaleTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void localeNamesProvided() {
|
public void languageNamesProvided() {
|
||||||
Locale english = new Locale("en", "US");
|
Locale english = new Locale("en", "");
|
||||||
|
Locale usEnglish = new Locale("en", "US");
|
||||||
Locale russian = new Locale("ru", "RU");
|
Locale russian = new Locale("ru", "RU");
|
||||||
assertEquals("English", english.getDisplayLanguage(english));
|
assertEquals("English", english.getDisplayLanguage(english));
|
||||||
|
assertEquals("English", english.getDisplayLanguage(usEnglish));
|
||||||
assertEquals("Russian", russian.getDisplayLanguage(english));
|
assertEquals("Russian", russian.getDisplayLanguage(english));
|
||||||
|
assertEquals("English", english.getDisplayLanguage(usEnglish));
|
||||||
|
assertEquals("Russian", russian.getDisplayLanguage(usEnglish));
|
||||||
assertEquals("английский", english.getDisplayLanguage(russian));
|
assertEquals("английский", english.getDisplayLanguage(russian));
|
||||||
assertEquals("русский", russian.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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user