-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translator] Use ICU parent locales as fallback locales #28070
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
Conversation
|
||
// Aliases contain the text "%%PARENT" followed by the aliased locale | ||
if (\preg_match('/%%Parent{"([^"]+)"}/', $content, $matches)) { | ||
if ('root' === $matches[1]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just understood why some have root
as a parent: az_Cyrl
would fall back to az
(Azerbaijani in Latin) otherwise (so has a script change). Will update to stop az
being a fallback in this case.
@@ -392,6 +397,10 @@ private function loadFallbackCatalogues($locale): void | |||
|
|||
protected function computeFallbackLocales($locale) | |||
{ | |||
if (null === $this->parentLocales) { | |||
$parentLocales = \json_decode(\file_get_contents(__DIR__.'/Resources/data/parents.json'), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe 8000 this comment to others. Learn more.
we don't fully-qualify all function calls in Symfony (to reduce the visual clutter). We only fully-qualify the function which can be optimized by the compiler (as the compiler cannot optimize them when it does not know for sure that the global function is the one being called)
@@ -401,10 +410,20 @@ protected function computeFallbackLocales($locale) | |||
$locales[] = $fallback; | |||
} | |||
|
|||
$parentLocale = $parentLocales[$locale] ?? null; | |||
|
|||
if ('root' === $parentLocale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a BC break, as it removes some of the existing fallbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a quick go and looks possible to keep track of deprecated fallbacks.
But this does raise a question of what should happen when the data changes, eg CLDR 27 (eg en_JE
switched from falling back from en_GB
to en_001
directly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should follow CLDR
what's the lowest branch for this patch? bug fix should target the lowest maintained branch; |
I'd describe |
* | ||
* @param string $sourceDir The directory with ICU files | ||
* | ||
* @return array An array with the locale as keys and the parent locales |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the type annotations should be replaced by real PHP types
Looking at previous ICU updates, the data is merged into patch releases so future changes here will presumably do the same. |
That's a new feature. Can you add a note in the CHANGELOG ? |
Travis failure is unrelated. |
48f4a81
to
e0f402f
Compare
Thank you @thewilkybarkid. |
…s (thewilkybarkid) This PR was squashed before being merged into the 4.2-dev branch (closes #28070). Discussion ---------- [Translator] Use ICU parent locales as fallback locales | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12319 | License | MIT | Doc PR | symfony/symfony-docs#10122 Currently the `Translator` fall backs based on the locale separator (eg `es_AR` to `es`), but the ICU data contains parent locales (eg `es_AR` is a child of `es_419`, as is `es_BO`, `es_EC` etc). This makes use of the ICU data to add add in these fallbacks. This means the specific locales can be used, but the translations can stored in these groupings (eg `es_419` for Latin American Spanish), as well as adding other sensible fallbacks (eg Cape Verdean Portuguese to `pt_PT`). Commits ------- e0f402f [Translator] Use ICU parent locales as fallback locales
…s (thewilkybarkid, javiereguiluz) This PR was merged into the master branch. Discussion ---------- Update translator fallback example to include ICU parents Changes the example to show symfony/symfony#28070. Commits ------- 7ccf603 Reworded and added the versionadded directive 54631df Update translator fallback example to include ICU parents
…ator (jvasseur) This PR was merged into the 4.4 branch. Discussion ---------- [Translation] Fix caching of parent locale 8089 s file in translator | Q | A | ------------- | --- | Branch? | 4.4 (this is the lowest maintained branch with this code) | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | | License | MIT | Doc PR | The `parentLocales` property was probably meant as a cache for the content of the `parents.json` file but instead the content is stored in a local variable and the property stays `null`. This means the file is read on each call to `computeFallbackLocales`. This PR update the code to what was probably meant to be. (Ref #28070) Commits ------- 02c9ac6 Fix caching of parent locales file in translator
Currently the
Translator
fall backs based on the locale separator (eges_AR
toes
), but the ICU data contains parent locales (eges_AR
is a child ofes_419
, as ises_BO
,es_EC
etc).This makes use of the ICU data to add add in these fallbacks. This means the specific locales can be used, but the translations can stored in these groupings (eg
es_419
for Latin American Spanish), as well as adding other sensible fallbacks (eg Cape Verdean Portuguese topt_PT
).