Localize Redactor editor UI based on Bolt backend locale#41
Open
Vondry wants to merge 4 commits into
Open
Conversation
The editor language was only settable via a static `lang:` in `bolt-redactor.yaml`, so on a multi-locale Bolt install every admin saw the editor in the same hard-coded language regardless of the locale they'd chosen for the backend. Bolt already resolves a per-user backend locale (LocaleSubscriber sets the request locale from the user's `_backend_locale`); the editor just never consulted it. - RedactorConfig now sets `lang` to the current request locale (RequestStack) after the config merge, so the toolbar always follows each user's Bolt locale. It is intentionally not overridable — the language is driven solely by the user's Bolt admin locale. - redactor_includes() auto-loads the matching `assets/redactor/langs/<code>.js` for the resolved locale, so users no longer add it to `includes` manually. English is built in; locales without a shipped translation are skipped and Redactor falls back to English on its own. - Document the behaviour in the README.
The formattingAdd 'small' entry used a hard-coded 'Small' title, so it showed English in every locale. Switch it to the '## small ##' i18n placeholder and add a 'small' entry to every langs/<locale>.js. Also always load langs/en.js (previously skipped for English), so its normalized table overrides redactor.min.js' built-in 'en' and provides the new 'small' label.
resolveLocale() set lang to the raw request locale even when no matching langs/<code>.js is shipped, while redactor_includes() skipped the missing file. This leaves the config pointing at a language table that was never loaded, which can leave the toolbar unlocalized or broken. Resolve the locale against the actually-shipped language file so lang and the loaded file always agree, falling back to English otherwise.
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.
Summary
This MR makes the Redactor editor UI follow the current Bolt backend locale and normalizes bundled Redactor translation files so plugin and format labels can be localized consistently.
Changes
langoption from the current request locale resolved by Bolt.assets/redactor/langs/<code>.jsfile fromredactor_includes().langs/en.jstoo, so its normalized table overrides the built-in English shipped inredactor.min.js; unsupported locales still fall back to Redactor's built-in English when no file exists.smallformat label: switch theformattingAddentry from a hard-coded'Small'title to the## small ##i18n placeholder and add asmallkey to every bundledlangs/<code>.js(previously it read "Small" in every locale, and empty under English).inlinestyleandpropertiesplugins to read more labels through Redactor's language system.Testing
bolt-cms-redactor-localized.mp4