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 component bundles Trumbowyg's language files and, before the editor initialises, runs only the one matching the locale and sets it as the editor language. Locales without a translation keep the built-in English. 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.
This branch has not been deployed
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.
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.vuebundles Trumbowyg's language files withrequire.context. Increated(), before Trumbowyg initialises, it runs only the matching file and setsconfig.lang. Locales without a translation keep the built-in English, so existing behaviour is unchanged.This follows the same approach as the
datefield, which bundles flatpickr's locales.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
All 46 language files are bundled (about 57 KB raw, 16 KB gzipped), but only one is executed per page. Loading them lazily would delay the editor's initialisation until the file has been fetched. For comparison, the
datefield bundles flatpickr's locales the same way, at roughly four times the size.Testing
html-testing.mp4