Skip to content

Translate the html field editor into the backend locale - #3846

Open
Vondry wants to merge 3 commits into
bolt:6.2from
Vondry:feature/html-editor-locale-6.2
Open

Vondry wants to merge 3 commits into
bolt:6.2from
Vondry:feature/html-editor-locale-6.2

Conversation

@Vondry

@Vondry Vondry commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Testing

  • Languages are switched as expected and only appropriate translation file is lazily loaded
html-editor-test-on-6.2.mp4

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.
@Vondry
Vondry marked this pull request as draft October 25, 2026 18:16
Trumbowyg's my.min.js, meant to be Malay, registers itself as `id`, so
with Malay (`ms`) aliased to it the editor looked up a language that was
never registered. Removing `_dir` from it threw in created(), and the
editor was never rendered.

Malay is no longer aliased, so it stays in English and fetches nothing.
A loaded file that registers no language under its name also falls back
to English instead of failing.
Html.vue builds its language context with webpack's
import.meta.webpackContext(), which Vite does not implement, so the spec
could not even import the component. A transform in vitest.config.ts
rewrites the call to a stand-in that lists the directory as lazy imports,
so the specs load Trumbowyg's real language files.

The new specs cover locale matching and fallback, the aliases, the
locales that stay in English, a failed load, a misnamed file, and the
right-to-left translations keeping the editing direction.
@Vondry
Vondry force-pushed the feature/html-editor-locale-6.2 branch from 33e8d21 to 77039ef Compare October 25, 2026 18:39
@Vondry
Vondry marked this pull request as ready for review October 26, 2026 11:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant