Java user.region、user.language、user.country 和 user.variant 之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18918375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between user.region, user.language, user.country and user.variant?
提问by rodolfo42
I've recently had a problem with Java locales in my system, and I was trying to run a project with this configuration:
我最近在我的系统中遇到了 Java 语言环境的问题,我试图用这个配置运行一个项目:
-Duser.language=pt_BR
-Duser.country=BR
After googling, I found this sitewhich had me changing my configuration to:
谷歌搜索后,我发现这个网站让我将我的配置更改为:
-Duser.language=pt
-Duser.region=BR
-Duser.country=BR
And the problem was gone. Additionaly I've found pages like thistalking about using another property called user.variant
.
问题就解决了。另外我发现像这样的页面谈论使用另一个名为user.variant
.
I'm not after LC_* properties, I'm just trying to find out what's the difference between these four properties?
我不是在追求 LC_* 属性,我只是想找出这四个属性之间的区别是什么?
user.language
user.region
user.country
user.variant
Thanks
谢谢
采纳答案by René Link
Please take a look at the javadoc of Locale
http://docs.oracle.com/javase/7/docs/api/java/util/Locale.html
请看一下http://docs.oracle.com/javase/7/docs/api/java/util/Locale.html的javadocLocale
It describes language, variant, and so on.
它描述语言、变体等。
回答by alain.janinm
If one day the link above breaks...
如果有一天上面的链接断开了......
Copy pasted from https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html
从https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html复制粘贴
user.language
用户语言
ISO 639alpha-2 or alpha-3 language code, or registered language subtags up to 8 alpha letters (for future enhancements). When a language has both an alpha-2 code and an alpha-3 code, the alpha-2 code must be used. You can find a full list of valid language codes in the IANA Language Subtag Registry (search for "Type: language"). The language field is case insensitive, but Locale always canonicalizes to lower case. Well-formed language values have the form [a-zA-Z]{2,8}. Note that this is not the the full BCP47 language production, since it excludes extlang. They are not needed since modern three-letter language codes replace them. Example: "en" (English), "ja" (Japanese), "kok" (Konkani)
ISO 639alpha-2 或 alpha-3 语言代码,或最多 8 个字母的注册语言子标签(用于未来增强)。当一种语言同时具有 alpha-2 代码和 alpha-3 代码时,必须使用 alpha-2 代码。您可以在 IANA 语言子标签注册表中找到有效语言代码的完整列表(搜索“类型:语言”)。语言字段不区分大小写,但 Locale 始终规范化为小写。格式良好的语言值的形式为 [a-zA-Z]{2,8}。请注意,这不是完整的 BCP47 语言产品,因为它不包括 extlang。不需要它们,因为现代三字母语言代码取代了它们。示例:“en”(英语)、“ja”(日语)、“kok”(Konkani)
user.region/user.country
用户.地区/用户.国家
ISO 3166alpha-2 country code or UN M.49 numeric-3 area code. You can find a full list of valid country and region codes in the IANA Language Subtag Registry (search for "Type: region"). The country (region) field is case insensitive, but Locale always canonicalizes to upper case. Well-formed country/region values have the form [a-zA-Z]{2} | [0-9]{3} Example: "US" (United States), "FR" (France), "029" (Caribbean)
ISO 3166alpha-2 国家代码或 UN M.49 numeric-3 区号。您可以在 IANA 语言子标签注册表中找到有效国家和地区代码的完整列表(搜索“类型:地区”)。country (region) 字段不区分大小写,但 Locale 始终规范化为大写。格式正确的国家/地区值的格式为 [a-zA-Z]{2} | [0-9]{3} 示例:“US”(美国)、“FR”(法国)、“029”(加勒比)
user.variant
用户变体
Any arbitrary value used to indicate a variation of a Locale. Where there are two or more variant values each indicating its own semantics, these values should be ordered by importance, with most important first, separated by underscore('_'). The variant field is case sensitive.
Note: IETF BCP 47 places syntactic restrictions on variant subtags. Also BCP 47 subtags are strictly used to indicate additional variations that define a language or its dialects that are not covered by any combinations of language, script and region subtags. You can find a full list of valid variant codes in the IANA Language Subtag Registry (search for "Type: variant").
However, the variant field in Locale has historically been used for any kind of variation, not just language variations. For example, some supported variants available in Java SE Runtime Environments indicate alternative cultural behaviors such as calendar type or number script. In BCP 47 this kind of information, which does not identify the language, is supported by extension subtags or private use subtags.
Well-formed variant values have the form SUBTAG (('_'|'-') SUBTAG)* where SUBTAG = [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}. (Note: BCP 47 only uses hyphen ('-') as a delimiter, this is more lenient).
Example: "polyton" (Polytonic Greek), "POSIX"
用于指示区域设置变体的任意值。如果有两个或多个变体值,每个值都表示自己的语义,则这些值应按重要性排序,最重要的在前,用下划线('_')分隔。变体字段区分大小写。
注意:IETF BCP 47 对变体子标签设置了句法限制。此外,BCP 47 子标签严格用于指示定义语言或其方言的其他变体,这些变体未包含在语言、文字和地区子标签的任何组合中。您可以在 IANA 语言子标签注册表中找到有效变体代码的完整列表(搜索“类型:变体”)。
但是,Locale 中的变体字段历来用于任何类型的变体,而不仅仅是语言变体。例如,Java SE 运行时环境中可用的一些受支持变体表示替代的文化行为,例如日历类型或数字脚本。在 BCP 47 中,这种不识别语言的信息由扩展子标签或私人使用子标签支持。
格式正确的变体值的形式为 SUBTAG (('_'|'-') SUBTAG)* 其中 SUBTAG = [0-9][0-9a-zA-Z]{3} | [0-9a-zA-Z]{5,8}。(注意:BCP 47 仅使用连字符 ('-') 作为分隔符,这更宽松)。
示例:“polyton”(Polytonic 希腊语)、“POSIX”