Skip to content

[Intl][Form] Support ISO 3166-1 Alpha-3 country codes #20313

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

Closed
TerjeBr opened this issue Oct 26, 2016 · 14 comments · Fixed by #33791
Closed

[Intl][Form] Support ISO 3166-1 Alpha-3 country codes #20313

TerjeBr opened this issue Oct 26, 2016 · 14 comments · Fixed by #33791

Comments

@TerjeBr
Copy link

TerjeBr commented Oct 26, 2016

Could we please extend the form type CountryType via an option to make it support ISO_3166-1 Alpha-3 country codes?

Sources for the country codes:

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?

(This was first raised in #8492 but that issue was closed without being resolved properly)

@TerjeBr TerjeBr changed the title [Intl] Support ISO 3166-1 country codes [Intl][Form] Support ISO 3166-1 country codes Oct 26, 2016
@TerjeBr TerjeBr changed the title [Intl][Form] Support ISO 3166-1 country codes [Intl][Form] Support ISO 3166-1 Alpha-3 country codes Oct 28, 2016
@ldt
Copy link

ldt commented Feb 16, 2017

In our app, we have reset the list of nationalities to handle it:

        $nationalities = array_flip(Intl::getRegionBundle()->getCountryNames());
        $nationalities = array_map([$this, 'getISO3Code'], $nationalities);

        $builder
            ->add(
                'nationality',
                CountryType::class,
                [
                    'required' => $required,
                    'label'    => 'nationality',
                    'attr'     => [
                        'data-field'    => 'nationality',
                    ],
                    'choices' => $nationalities,
                    'preferred_choices' => array('FRA'),
                ]
            )

And it works fine in 3.1.x.
I recently tried to upgrade to 3.2.3 and I got 2 letters country codes so I had to downgrade back to 3.1.10. Any clues what could be involved?

@HeahDude
Copy link
Contributor

Hi @idt this is related to #20771.

@xabbuh
Copy link
Member

xabbuh commented Jul 22, 2019

@ro0NL Would we be able to provide access to the three-letter codes through the Intl API?

@surelygroup
Copy link

Have a look at #8492 (comment)

@ro0NL
Copy link
Contributor

ro0NL commented Jul 22, 2019

Seems ICU has the same dataset available (from #8492 (comment))

https://github.com/unicode-org/icu/blob/13889bece13f51b0e9b3eef16cd34490c96da291/icu4c/source/data/misc/metadata.txt#L3840-L3843

So we could investigate this :)

Moreover, for languages we maintain the mapping ourselves:

private static $preferredAlpha2ToAlpha3Mapping = [

But AFAIK it's also available in ICU, e.g. https://github.com/unicode-org/icu/blob/13889bece13f51b0e9b3eef16cd34490c96da291/icu4c/source/data/misc/metadata.txt#L14-L17

To be able to extract the "alpha3" lists we first need to understand the format. I think we need all codes only with reason=overlong.

@xabbuh
Copy link
Member

xabbuh commented Jul 22, 2019

Okay, so once the API from the Intl component allows us to access these data we should be able to extend the CountryType accordingly.

@surelygroup
Copy link

Be aware of the difference between language codes and region codes. They are not the same.

Region is about geographic country names.

Language codes is about codes for the different spoken languages.

The tables @ro0NL linked to seemed to all be about language codes and not region codes.

@TerjeBr
Copy link
Author

TerjeBr commented Jul 22, 2019

Please have a look at symfony/intl#10

I hope that can bring this issue closer to an implementation.

@TerjeBr
Copy link
Author

TerjeBr commented Jul 22, 2019

Make that PR #32663 instead.

@TerjeBr
Copy link
Author

TerjeBr commented Jul 23, 2019

Make that PR #32676 instead.

fabpot added a commit that referenced this issue Aug 9, 2019
…braten-certua)

This PR was merged into the 4.4 branch.

Discussion
----------

[Intl] Support ISO 3166-1 Alpha-3 country codes

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20313
| Doc PR | symfony/symfony-docs#12105
| License       | MIT

This is a pre-requiste for fixing #20313 and only handles the changes to the INTL component.

Commits
-------

848f60e Support ISO 3166-1 Alpha-3 country codes
@TerjeBr
Copy link
Author

TerjeBr commented Aug 13, 2019

The necessarry support in the Intl library has now been merged in #32988

@ro0NL
Copy link
Contributor

ro0NL commented Aug 13, 2019

Next step alpha3 => true for form types? Or what's the proposal :)

@TerjeBr
Copy link
Author

TerjeBr commented Aug 13, 2019

Yes, but I might not have time for it until next week, or even later. Sorry.

But it should be a simple task now for anyone to pick up. If someone feels like it, feel free to submit a PR.

@fabpot fabpot closed this as completed Oct 3, 2019
fabpot added a commit that referenced this issue Oct 3, 2019
…ry codes (creiner)

This PR was squashed before being merged into the 4.4 branch (closes #33791).

Discussion
----------

[Form] Added CountryType option for using alpha3 country codes

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fixes #20313
| License       | MIT
| Doc PR        | -

In the linked issue #20313 was a proposal to add an alpha3 option to the country type.
Here it is..
Hopefully I've made no mistake, so when the code is fine, I will create a documentation PR.. :-)

Commits
-------

d07f5a3 [Form] Added CountryType option for using alpha3 country codes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants