Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
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 haveroot as a parent:az_Cyrl would fall back toaz (Azerbaijani in Latin) otherwise (so has a script change). Will update to stopaz being a fallback in this case.
| protectedfunctioncomputeFallbackLocales($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 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)
| $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, egCLDR 27 (egen_JE switched from falling back fromen_GB toen_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
nicolas-grekas commentedJul 28, 2018
what's the lowest branch for this patch? bug fix should target the lowest maintained branch; |
thewilkybarkid commentedAug 3, 2018
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
thewilkybarkid commentedAug 5, 2018
Looking at previous ICU updates, the data is merged into patch releases so future changes here will presumably do the same. |
fabpot commentedAug 27, 2018
That's a new feature. Can you add a note in the CHANGELOG ? |
thewilkybarkid commentedAug 27, 2018
Travis failure is unrelated. |
fabpot commentedAug 28, 2018
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#10122Currently 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 parentsChanges the example to showsymfony/symfony#28070.Commits-------7ccf603 Reworded and added the versionadded directive54631df 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 locales 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
Uh oh!
There was an error while loading.Please reload this page.
Currently the
Translatorfall backs based on the locale separator (eges_ARtoes), but the ICU data contains parent locales (eges_ARis a child ofes_419, as ises_BO,es_ECetc).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_419for Latin American Spanish), as well as adding other sensible fallbacks (eg Cape Verdean Portuguese topt_PT).