Feature: localizable sandboxed plugins (manifest locales + api.i18n.t)#370
Merged
Merged
Conversation
The plugin runtime received the active locale (init payload + 'locale-change')
and plugins could declare a `locales` map, but none of it was usable: the
locales never reached the runtime, and buildPluginApi exposed no i18n. So
plugin code calling pluginApi.i18n.t(...) (as the External Link Warning plugin
does) always got undefined and fell back to English.
Thread plugin locales end to end and surface an i18n API:
- ServerPlugin gains `locales`; the upload route persists manifest.locales
(alongside configSchema/settingsSchema), and /api/plugins surfaces it to the
client so it flows registry -> client -> sandbox host-bridge -> runtime.
- runtime sets __PLUGIN_LOCALE__ at init (not only on later 'locale-change')
and buildPluginApi exposes `i18n.locale` + `i18n.t(key, vars)` resolving
against the plugin's declared locales (manifest.locales) with English/key
fallback and {placeholder} interpolation.
Lets any sandboxed plugin localize its strings from its manifest.
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
The sandbox already received the active locale (init payload + 'locale-change') and plugins could declare a
localesmap, but it was unusable: the locales never reached the runtime andbuildPluginApiexposed no i18n, so plugin UI was stuck in one language. This wires it up end-to-end and adds two related plugin-dialog fixes.Changes
ServerPlugingainslocales; the upload route persistsmanifest.localesand/api/pluginssurfaces it, so it flows registry -> client -> sandbox. The runtime sets__PLUGIN_LOCALE__at init and exposesapi.i18n.locale+api.i18n.t(key, vars)(resolves against the plugin'smanifest.locales, English/key fallback,{placeholder}interpolation). The sandbox locale is wired to the app locale ininitializePlugins. Plugin metadata sync is centralised in oneserverMeta()mapper so passthrough fields (incl.locales) can't be silently dropped.ui.confirm/ui.alertno longer time out after 30s while waiting for the user (the genericcallApitimeout is opt-out for these).--background/etc.; corrected to the real--color-*tokens), wraps long unbreakable text, and supports lightweight**bold**in messages.Type of Change
Checklist
npm run typecheck && npm run lintand there are no errorsnpm run build)locales/) if my changes affect user-facing textNotes for Reviewers
Real-world consumer: our localized fork of the "External Link Warning" plugin uses
api.i18n.tfor its dialog - https://github.com/dealerweb/bulwark-plugin-external-link-warning . The plugin-store test suite passes;plugin-storekeeps the sandbox locale in step via theplugin-loaderfacade rather than importinglib/plugin-sandbox/loaderdirectly.