简体   繁体   English

语言环境和ISO3CountryCodes

[英]Locale and ISO3CountryCodes

I have seen recently in java 1.7 that if I loop on Locales and get the ISO3Country code for the same then for Locale "CS" it gives me error "couldn't find 3 letter country code CS". 我最近在Java 1.7中看到,如果我在语言环境上循环并获得相同的ISO3Country代码,则对于语言环境“ CS”,它给我错误“找不到3个字母的国家代码CS”。 Is it expected behavior? 这是预期的行为吗? I also tested in java 1.6 but there I am not getting this error. 我也在Java 1.6中进行了测试,但没有收到此错误。

Locales[] locales =        GregorianCalender.getAvailableLocales();
For(Locale l: locales){
     System.out.println(l.getISO3CountryCode());
  }  

The short answer is: This is a country code for a country that no longer exists (Serbia and Montenegro), so the behavior may indeed be indeterminate. 简短的答案是:这是一个不再存在的国家(塞尔维亚和黑山)的国家代码,因此行为的确可能是不确定的。

ISO-3166 is divided into three parts. ISO-3166分为三个部分。 The first part, ISO-3166-1, defines these country codes and, in turn, has several parts. 第一部分,ISO-3166-1,定义了这些国家/地区代码,并且又分为几个部分。 The most relevant here are ISO-3166-1 alpha-2 and ISO-3166-1 alpha-3 which define the 2 and 3-letter country codes, respectively. 这里最相关的是ISO-3166-1 alpha-2ISO-3166-1 alpha-3 ,它们分别定义了2个字母和3个字母的国家/地区代码。

According to the alpha-2 table, "CS" is the country code for Serbia and Montenegro, a country that no longer exists. 根据alpha-2表,“ CS”是塞尔维亚和黑山(不再存在的国家)的国家代码。 It still has an entry in alpha-2, marked as "reserved for deletion", for backwards compatibility purposes. 它仍然具有alpha-2条目,标记为“保留删除”,以实现向后兼容。 It is probably also still in Java for backwards compatibility. 为了向后兼容,它可能仍在Java中。

The equivalent entry in alpha-3 is "SCG" and is also be marked as reserved. alpha-3中的等效项是“ SCG”,也被标记为保留。 I would expect this code to be returned to you, but can understand why it might not be. 我希望此代码可以返回给您,但可以理解为什么可能不会。 (Alternatively, ISO-3166-3 defines country codes for countries that no longer exist; they are four letters long and maybe "CSXX" is what should be returned here...) (或者, ISO-3166-3为不再存在的国家/地区定义了国家/地区代码;它们的长度为四个字母,也许应该在此处返回“ CSXX” ...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么ISO用于在Locale中定义countryId? - What ISO is used to define the countryId in a Locale? Java Locale 到国家/地区代码 (ISO 3166) - Java Locale to country codes (ISO 3166) 如何获取语言环境的iso2语言代码? - How to get iso2 language code for locale? 如果您有 ISO 国家代码 `US`、`FR`,如何获得区域设置代码(`Locale.US`、`Locale.FRANCE`)? - If you have the ISO country code `US`, `FR`, how do you get the Locale code (`Locale.US`, `Locale.FRANCE`)? 如何通过语言环境从国家名称获取iso2code - How to get iso2code from a country name by locale 如何从给定的 iso 语言代码中检索匹配的宏语言区域设置? - How to retrieve matching macrolanguage locale from a given iso language code? 如何处理ISO 8601日期/时间并将其格式化为用户的语言环境? - How can I handle ISO 8601 dates / Times and format them to the user's locale? "JDK Locale 类处理希伯来语 (he)、意第绪语 (yi) 和印度尼西亚语 (id) 的 ISO 语言代码" - JDK Locale class handling of ISO language codes for Hebrew (he), Yiddish (yi) and Indonesian (id) 在 Java-8 区域设置 Object 中转换为某些语言代码中的旧 ISO。 我如何在不更新 Java 版本的情况下解决此问题? - In Java-8 Locale Object convert to old ISO in some Language code. How can i fix this issue without update Java version? Struts2动态下拉错误:无法将请求的列表键“ CountryCodes2”解析为集合/数组/地图/枚举/迭代器类型 - Struts2 Dynamic DropDown Error: The requested list key 'CountryCodes2' could not be resolved as a collection/array/map/enumeration/iterator type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM