java.util.Locale constructor does not workwhen using "gsw" as a Swiss language locale in Java 8

huangapple 未分类评论44阅读模式
英文:

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); 

huangapple
  • 本文由 发表于 2020年4月9日 21:57:08
  • 转载请务必保留本文链接:https://java.coder-hub.com/61122837.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定