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 ISO 3166-1 standard currently comprises 249 countries, 193 of which are sovereign states that are members of the United Nations.
ISO 3166-1 numeric (or numeric-3) codes are three-digit country codes defined in ISO 3166-1, part of the ISO 3166 standard published by the International Organization for Standardization (ISO), to represent countries, dependent territories, and special areas of geographical interest.
Each complete ISO 3166-2 code can then be used to uniquely identify a country subdivision in a global context. As of 3 March 2022 there are 5,048 codes defined in ISO 3166-2. For some countries, codes are defined for more than one level of subdivisions.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With