Repository navigation
Conversation
The html field's Trumbowyg editor always showed its toolbar in English, although Trumbowyg ships translations for 46 languages. They were never loaded, and the editor was never told which language to use. The field template now passes the request locale to the component, the same locale the rest of the backend UI is rendered in. The language files are split into lazy chunks named trumbowyg-lang-<file>.js, so only the one matching the locale is fetched, and the editor is rendered once it has loaded. Locales without a translation keep the built-in English and fetch nothing. Locales are matched from the most to the least specific part (sr_Latn_RS -> sr_latn -> sr), with aliases for the codes Trumbowyg names differently from ISO (uk -> ua, sr -> rs, nn -> nb, zh_Hant -> zh_tw, ...). ISO `my` is Burmese while Trumbowyg's `my` is Malay, so it is never matched as-is. The Arabic, Hebrew and Persian translations also switch the editable area to right-to-left. That direction belongs to the content being edited, not to the backend language, so it is dropped and only the labels are used.
Member
|
This is new functionality, not a bugfix. Belongs in 6.2, but I cannot reopen the previous PR. |
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.
Supersedes #3825, which targeted 6.2 by mistake. It also addresses the review there: language files are now loaded lazily instead of bundled.
The
htmlfield's Trumbowyg editor always shows its toolbar in English, regardless of the backend locale. Trumbowyg ships translations for 46 languages (trumbowyg/dist/langs), but Bolt never loaded one or set the editor'slangoption, so it always used the built-in English.This is part of an effort to localize the Bolt admin UI, alongside the related PRs for the other rich-text editors:
All three take the editor's UI language from the Bolt backend locale, so the core
htmlfield and both extension fields behave consistently.Changes
html.html.twigpassesapp.request.localeto<editor-html>. This is the locale the surrounding backend UI is rendered in, and the same one the Redactor and Article PRs use. The content edit locale (edit_locale) is separate and does not affect it.Html.vueregisters Trumbowyg's language files with a lazyrequire.context, so webpack emits each one as its own chunk. Increated()it fetches only the matching file, setsconfig.lang, and then renders Trumbowyg, which reads its language when it initialises. Locales without a translation keep the built-in English and fetch nothing, so existing behaviour is unchanged. If the chunk fails to load, the editor falls back to English.Locale matching
Bolt locales are lowercased and matched from the most to the least specific part:
sr_Latn_RS→sr_latn→sr,de_AT→de.Trumbowyg uses non-ISO names for some languages, so these are aliased:
ukuasr,sr_Latnrs,rs_latinbebyfil,tlphmsmyno,nnnbzh,zh_Hanszh_cnzh_Hant,zh_HK,zh_MOzh_twISO
myis Burmese, while Trumbowyg'smyis Malay, somyis never matched as-is and falls back to English.Right-to-left languages
Trumbowyg's
ar,heandfatranslations also set_dir: 'rtl', which Trumbowyg applies to the editable area. Text direction belongs to the content being edited, not to the backend language, so_diris removed after loading. Only the labels are translated, and editing stays left-to-right as before.Bundle size
The language files are not part of
bolt.js. Each is a separate chunk of about 1 KB (trumbowyg-lang-cs-min-js.jsfor Czech), and only the one for the current locale is requested. On an English backend, no extra request is made.Testing
test.mp4