Skip to content

[Intl] Locale::getFallback does not split on dash #24154

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
lyrixx opened this issue Sep 11, 2017 · 5 comments
Closed

[Intl] Locale::getFallback does not split on dash #24154

lyrixx opened this issue Sep 11, 2017 · 5 comments
Labels
Bug Intl RFC RFC = Request For Comments (proposals about features that you want to be discussed) Status: Needs Review

Comments

@lyrixx
Copy link
Member

lyrixx commented Sep 11, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes
Symfony version 3.3.8 (but all others I guess, did not check yet)

Hello.

I just hit an issue with the country type and the Intl component.

According to PHP, the first parameter of Locale::setDefault
should be a BCP 47 compliant tag.

So according to the RFC, it should be something like fr or fr-FR.
In my case it's fr-FR.

Now the CountryType use the Locale::getDefault. Refs:

Then symfony will use will default locale to find the best locale by "fallbacking" on "wider" locale (fr_FR -> fr)

And here
there is something wrong IMHO. Symfony only try to split the local with an underscore (_) and not
with a dash (-). But the RFC states the locale should use an underscore and not a dash.


Some facts to take in consideration:

  • The Translator component use another RFC for the format of the locale. (fr_FR);
  • The Validator component use another RFC for the format of the locale. (fr_FR);
  • It's really weird I'm the first one to hit this issue => Did I miss something ?

What I suggest: We could update the Locale::getFallback method to support splitting on -.

WDYT? I can make the PR if this RFC is accepted.


I pushed a reproducer

@lyrixx lyrixx added Intl RFC RFC = Request For Comments (proposals about features that you want to be discussed) Bug labels Sep 11, 2017
@fabpot
Copy link
Member

fabpot commented Sep 11, 2017

For reference, see discussion on #2468 as well

@lyrixx
Copy link
Member Author

lyrixx commented Sep 11, 2017

We could use locale_parse instead of our local implementation. We will cover more cases. More over I don't see pitfall here.
`

@fabpot
Copy link
Member

fabpot commented Sep 11, 2017

PR more than welcome :)

fabpot added a commit that referenced this issue Sep 30, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

[Intl] Fixed support of Locale::getFallback

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24154
| License       | MIT
| Doc PR        |

Commits
-------

2560552 [Intl] Fixed support of Locale::getFallback
@lyrixx lyrixx closed this as completed Oct 1, 2017
@aliechti
Copy link

aliechti commented Dec 14, 2017

Is it possible to get this change into Symfony 4?
It would require 2 more lines at \Symfony\Component\Translation\Translator::computeFallbackLocales. Or is this something different and I missed something?

@xabbuh
Copy link
Member

xabbuh commented Dec 14, 2017

@thejahweh I can see the change in Symfony 4: https://github.com/symfony/symfony/blob/4.0/src/Symfony/Component/Intl/Locale.php#L70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Intl RFC RFC = Request For Comments (proposals about features that you want to be discussed) Status: Needs Review
Projects
None yet
Development

No branches or pull requests

5 participants