简体   繁体   中英

When does Local.getCountry() return a UN M.49 3-digit code instead of an ISO 3166 2-letter code?

The description of Local.getCountry() says:

Returns the country/region code for this locale, which should either be the empty string, an uppercase ISO 3166 2-letter code, or a UN M.49 3-digit code.

I wonder when is an ISO 3166 2-letter code returned and when a UN M.49 3-digit code ?

Example:

Locale locale = new Locale("de", "AT");
Log.i(TAG, "country code: " + locale.getCountry()); //returns "AT" which is an ISO 3166 2-letter code

The return type depends on the country of the created Locale, thus it depends on how the Locale is created. The IANA specifies the country / region codes and supports UN M.49 and ISO 3166 2.

Locale.getCountry() returns the code specified by the IANA List , which is either ISO or UN. Search for "Type: region":

Example UN M.49:

Type: region
Subtag: 053
Description: Australia and New Zealand
Added: 2005-10-16
%%

Example Iso 3166 2:

Type: region
Subtag: VA
Description: Holy See (Vatican City State)
Added: 2005-10-16
%%

Source: https://developer.android.com/reference/java/util/Locale

If I remember correctly there are several Locales that will return 001 (aka "World") as the UN M.49 code, specifically the root locale. I've personally not seen any other UN M.49 code being used (but that doesn't mean that no others are used).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM