英文:
java.util.Locale constructor does not workwhen using "gsw" as a Swiss language locale in Java 8
问题
上下文:
一个客户请我帮他解决一个问题,即如何使用指定的区域设置(Locale)参数来格式化 Joda DateTime。
问题:
在使用“gsw”(瑞士德语)作为语言时,似乎无法影响翻译(在我的情况下会回退到英语)。
“gsw”是 ISO639-2 的一部分(这是 ISO639 alpha-3,Java 区域设置声称支持它,https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html)。
我已经核实了以确保百分之百,gsw 是 alpha-3 的一部分,但它不是 alpha-2(ISO639-1)的一部分:https://www.loc.gov/standards/iso639-2/php/English_list.php
我尝试过其他属于 alpha-3 但不在 alpha-2 中的语言,结果看到了相同奇怪的行为。
是我可能没有充分阅读区域设置帮助中心吗?
代码:
// 所有类型都属于 joda.time,除了 Locale,它属于 java.util
DateTimeZone dtZone = DateTimeZone.forID(IANATimezone);
DateTime dtus = dateTime.withZone(dtZone);
Locale locale = new Locale(Language, Region);
DateTimeFormatter dtf = DateTimeFormat.fullDateTime().withLocale(locale);
英文:
The context:
A customer asked me to help him with a method to format a Joda DateTime with a Locale specified as a parameter.
The problem:
Using "gsw" (Swiss German) as a language does not seem to have an effect on the translation (falls back to English in my case).
"gsw" is part of ISO639-2 (which is ISO639 alpha-3, which the Java locale says it supports, https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html).
I verified to be 100% sure and gsw is part of alpha-3, but it wasn't part of alpha-2 (ISO639-1): https://www.loc.gov/standards/iso639-2/php/English_list.php
I've tried with other languages which are part of alpha-3 but were not present in alpha-2 and I see the same strange behavior.
Have I might not read well enough the Locale helpcenter?
The code:
//all are types belong to joda.time, except Locale, which is java.util
DateTimeZone dtZone = DateTimeZone.forID(IANATimezone);
DateTime dtus = dateTime.withZone(dtZone);
Locale locale = new Locale(Language, Region);
DateTimeFormatter dtf = DateTimeFormat.fullDateTime().withLocale(locale);
专注分享java语言的经验与见解,让所有开发者获益!
评论