Repository navigation
[Translator] Fall back to the application default locale - #4089
Merged
Merged
Conversation
feymo
force-pushed
the
feat/translator-default-locale
branch
from
October 15, 2026 17:59
0802560 to
370fad2
Compare
Contributor
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
||||||||||||
Kocal
force-pushed
the
feat/translator-default-locale
branch
from
October 18, 2026 10:40
370fad2 to
a81b073
Compare
Kocal
approved these changes
Oct 18, 2026
Member
|
Thank you @feymo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up of #4076 , which did the same for UX Router.
The translator reads its locale from
<html data-symfony-ux-translator-locale>or<html lang>. When both are missing, it falls back to a hard-codeden. The bundle does not dump the application default locale, so the JavaScript side cannot know it. Withframework.default_locale: frand a layout withoutlang, messages are translated in English.The dumped
index.jsfile now exports thekernel.default_localeparameter asdefaultLocale, andindex.d.tsdeclares it when TypeScript types are dumped.createTranslator()accepts it as a newdefaultLocaleoption:The locale is resolved in this order: the
localeoption,<html data-symfony-ux-translator-locale>,<html lang>, thedefaultLocaleoption, thenen. Atranslator.jsfile without the option keeps its current behavior, andgetDefaultLocale()is unchanged.default_locale: fr, nolangattributegetLocale()in the browserenfrgetLocale()withoutdocument(SSR)ReferenceError: document is not definedfrThis PR also fixes two bugs on the way:
document(server-side rendering, tests in Node),createTranslator()threw aReferenceError. It now skips the page attributes, which is also what makes the new option useful there.replace()only replaces the first match.<html lang="zh-Hant-TW">gavezh_Hant-TW, which matches no catalogue, and an ICU message inzh_Hant_TWthrewRangeError: Incorrect locale information provided. Both conversions now usereplaceAll().The Flex recipe needs a new
3.7version that passesdefaultLocale. I will open it on symfony/recipes once this is merged.