Skip to content

[Intl] Fixed support of Locale::getFallback #24157

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

Merged
merged 1 commit into from
Sep 30, 2017
Merged

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Sep 11, 2017

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


return locale_compose($localesSubTags);
}

if (false === $pos = strrpos($locale, '_')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also make the fallback work with -?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (self::$defaultFallback === $locale) {
return 'root';
}
if (function_exists('locale_parse')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks weird to me. This function is part of ext-intl, so the polyfill will never be used when this function exists

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the point. did I miss something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I missed the fact that this is not a class from the polyfill. so fine

@nicolas-grekas
Copy link
Member

Tests don't appreciate at all this change, see appveyor and travis... :)

@lyrixx lyrixx force-pushed the local branch 2 times, most recently from aa7300b to d419a78 Compare September 13, 2017 08:42
@lyrixx
Copy link
Member Author

lyrixx commented Sep 13, 2017

Here we go. The PR is green ;)

return 'root';
}
if (function_exists('locale_parse')) {
$localesSubTags = locale_parse($locale);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this variable be $localeSubTags instead of $localesSubTags?

array(null, 'root'),
);

if (function_exists('locale_parse')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also add these complex locales (sl_Latn_IT, etc.) to the normal tests when locale_parse() doesn't exist? The result would be of course different ... but I think we should test that too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added more tests.

@lyrixx
Copy link
Member Author

lyrixx commented Sep 13, 2017

Note: I don't understand something. PHP seems inconsistent:

  • the parameter of locale_parse should follow the FCP47 RFC. but I can also be an ISO_3166-1
  • the return of locale_compose seems the ISO_3166-1.

edit:

Anyway, with this patch, my issue issue is solved in both case (with or without the int function)

@lyrixx
Copy link
Member Author

lyrixx commented Sep 21, 2017

👍

@fabpot
Copy link
Member

fabpot commented Sep 30, 2017

Thank you @lyrixx.

@fabpot fabpot merged commit 2560552 into symfony:2.7 Sep 30, 2017
fabpot added a commit that referenced this pull request 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
This was referenced Oct 5, 2017
@lyrixx lyrixx deleted the local branch May 3, 2018 08:38
fabpot added a commit that referenced this pull request Dec 27, 2019
…cales (alanpoulain)

This PR was merged into the 3.4 branch.

Discussion
----------

[Translation] Use `locale_parse` for computing fallback locales

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

As done in this PR #24157 for the `Intl` component, the `Translation` component should use `locale_parse` as well when available.

It will allow to manage [BCP 47](https://tools.ietf.org/html/bcp47) locales, which is why it is considered a bugfix ([locale_set_default](https://www.php.net/manual/en/locale.setdefault.php) is using BCP 47 compliant locale).

As done with the forementioned PR, there is also a fallback to make it work with `-`.

Sadly, I think it will create some conflicts when merging it upstream since the modified code has changed little by little.

Commits
-------

3657c0e Use locale_parse for computing fallback locales
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants