-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Intl] Support ISO 3166-1 country codes #8492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Maybe a simple model transformer could do the trick. |
Unfortunately we rely on ICU for our localization data, and ICU does not provide the 3-letter codes. Do you know of any source that maps 2-letter codes to 3-letter codes? |
@bschussek CLDR iirc. |
Indeed, CLDR provides a mapping from alpha-2 to alpha-3 in the file codeMappings.json contained in json.zip. I suggest to make the following changes to Intl: Add the constants NUMERIC, ALPHA2 and ALPHA3 to Intl: class Intl
{
const NUMERIC = 0;
const ALPHA2 = 1;
const ALPHA3 = 2;
} Add the method public function getCountryCodes($format = Intl::ALPHA2); Add the parameter public function getCountryNames($locale = null, $indexBy = Intl::ALPHA2); Change In the same turn as implementing this, it would be nice to also add corresponding |
But, if you want to use ICU for country list, and just map alpha-2 to alpha-3 codes from CLDR, I have bad news for you. ICU and CLDR list of countries do not match. |
Why doesn't it match? |
@hhamon Not sure. It just does not get updated in sync. Some countries like South Sudan, Kosovo...are not recognized widely, and when new country becomes independent for example, ICU and CLDR will not update at the same time. They actually never have identical list of countries. Not sure why. |
Ok! I was able to get a complete list of countries with ISO2 and ISO3 code. |
Great. May be that CLDR is more complete then ICU. |
AFAIK ICU (a library) relies on CLDR (data) - see the ICU Downloads page for example, where they list the included CLDR data for each release. |
This is being worked on in #9206. |
@hhamon did you find a workaround for this problem ? |
Nice. I'm stuck with an LTS though, so I'm no going to use it rightaway, but I'll keep that in mind for future projects. |
@greg0ire This was in fact merged into 2.3. |
Oh, great, I'll have a look then! |
I'm running into this issue (SF 2.5) I can see |
It is true, this issue is related to countries and the suggested solution/workaround is for languages. As far as I know the alpha3 code for languages is defined in the ISO 639b standard, not the ISO 3166. So the issue is still open to me, and a bit confusing what the alpha2toalpha3 actually does. |
@davide-romanini not true, it's in ISO 3166-1. |
@Glideh no, we're not talking about language, we're talking about territories. |
Since this issue was opened the json linked by @webmozart is gone. CLDR is now on release 29, and the tools to generate the JSON are currently broke, afaik. However, you can find the 3-alpha, to 2-alpha character mapping in the file: <territoryAlias type="AAA" replacement="AA" reason="overlong"/> <!-- null -->
<territoryAlias type="ASC" replacement="AC" reason="overlong"/> <!-- Ascension Island -->
<territoryAlias type="AND" replacement="AD" reason="overlong"/> <!-- Andorra -->
<territoryAlias type="ARE" replacement="AE" reason="overlong"/> <!-- United Arab Emirates -->
<territoryAlias type="AFG" replacement="AF" reason="overlong"/> <!-- Afghanistan -->
<territoryAlias type="ATG" replacement="AG" reason="overlong"/> <!-- Antigua & Barbuda -->
<territoryAlias type="AIA" replacement="AI" reason="overlong"/> <!-- Anguilla -->
<territoryAlias type="ALB" replacement="AL" reason="overlong"/> <!-- Albania -->
<territoryAlias type="ARM" replacement="AM" reason="overlong"/> <!-- Armenia -->
<territoryAlias type="ANT" replacement="CW SX BQ" reason="overlong"/> <!-- null -->
<territoryAlias type="AGO" replacement="AO" reason="overlong"/> <!-- Angola -->
<territoryAlias type="ATA" replacement="AQ" reason="overlong"/> <!-- Antarctica -->
<territoryAlias type="ARG" replacement="AR" reason="overlong"/> <!-- Argentina -->
<territoryAlias type="ASM" replacement="AS" reason="overlong"/> <!-- American Samoa -->
<territoryAlias type="AUT" replacement="AT" reason="overlong"/> <!-- Austria -->
<territoryAlias type="AUS" replacement="AU" reason="overlong"/> <!-- Australia -->
<territoryAlias type="ABW" replacement="AW" reason="overlong"/> <!-- Aruba -->
<territoryAlias type="ALA" replacement="AX" reason="overlong"/> <!-- Åland Islands -->
<territoryAlias type="AZE" replacement="AZ" reason="overlong"/> <!-- Azerbaijan -->
<territoryAlias type="BIH" replacement="BA" reason="overlong"/> <!-- Bosnia & Herzegovina --> The comment may also be useful if the library you're using to access CLDR doesn't support this xml,
|
@EvanCarroll as I said and you confirmed again, this issue is concerned about country codes, and specifically 3-letter country codes, not language codes. So the suggested workaround:
seems to solve a completely different problem (and I think it just don't work anymore on latest Intl). So the point is: this issue has been closed, but the problem has not been solved. Maybe is a "won't fix"? At least people coming here should be informed that the feature is not available.. |
Hi,
I was wondering if we could extend the
CountryType
via an option to make it support ISO_3166-1 Alpha-3 country codes as listed here:http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
I'm currently working on a project where I need country codes as 3 characters instead of just 2.
Would it be possible to include a new
alpha3
option or something to support 3 characters country codes?Edit: I saw that @umpirsky already compiled a list of all countries data in several formats: http://dev.umpirsky.com/list-of-all-countries-in-all-languages-and-all-data-formats. I don't see any ISO 3166 support in these files...
@fabpot @bschussek any thoughts?
The text was updated successfully, but these errors were encountered: