Feature modules: a feature ported from a plugin keeps that plugin's words (words), so nothing is retranslated; the keep-my-changes question takes its own line
This commit is contained in:
parent
6cfe6b4f4a
commit
01763ccdba
3 changed files with 27 additions and 6 deletions
|
|
@ -80,7 +80,8 @@ export type FeatureContext<Api> = {
|
|||
/** A palette command under the area's name (counts towards `AREA_COMMAND_BUDGET`), removed on stop. */
|
||||
command(definition: CommandDefinition): void;
|
||||
/**
|
||||
* The feature's word `key`: `plugin.<area namespace>.<name>.<key>` in the app's catalog. (Not
|
||||
* The feature's word `key`: `plugin.<area namespace>.<name>.<key>` in the app's catalog, or
|
||||
* `plugin.<words>.<key>` for a module that names its own namespace (`words`). (Not
|
||||
* named `t`: the i18n tools read `t('…')` as a whole catalog key.)
|
||||
*/
|
||||
text(key: string, params?: Params): string;
|
||||
|
|
@ -99,6 +100,12 @@ export type FeatureModule<Api> = {
|
|||
id: string;
|
||||
/** Selectors it depends on, by name (read them back with `ctx.selector(name)`). */
|
||||
probes?: Readonly<Record<string, Probe>>;
|
||||
/**
|
||||
* Where its words are in the catalog. Default: `plugin.<area namespace>.<name>.<key>`. A feature
|
||||
* ported from a plugin names that plugin's namespace (`focus-mode`) and keeps its keys
|
||||
* (`plugin.focus-mode.<key>`, its label `plugin.focus-mode.name`): nothing is retranslated.
|
||||
*/
|
||||
words?: string;
|
||||
/** Storage namespace (default `<area namespace>.<name>`; a ported plugin keeps its old one). */
|
||||
storage?: string;
|
||||
/** The key its settings are stored under (default `settings`). */
|
||||
|
|
@ -201,8 +208,13 @@ export function createFeatureRegistry<Api extends RegistryApi>(options: FeatureR
|
|||
const english = () => options.english?.() ?? /^en\b/i.test(doc.documentElement?.getAttribute?.('lang') ?? 'en');
|
||||
const settled = () => options.settled?.() ?? !!doc.body?.firstElementChild;
|
||||
const words = (area: AreaSpec) => api.i18n.namespace(area.namespace);
|
||||
/** A feature's word `key`: under its own namespace when it names one (`words`), else under its area's. */
|
||||
const wordOf = (module: FeatureModule<Api>, area: AreaSpec, key: string, params?: Params) =>
|
||||
(module.words ? api.i18n.namespace(module.words).t(key, params) : words(area).t(`${featureName(module.id)}.${key}`, params));
|
||||
/** A feature's label in the page, when the page has it (`plugin.*` words only reach a site tab). */
|
||||
const featureLabel = (spec: FeatureSpec, area: AreaSpec) => {
|
||||
const legacy = modules.get(spec.id)?.words;
|
||||
if (legacy) { const own = api.i18n.namespace(legacy); return own.has('name') ? own.t('name') : null; }
|
||||
const i18n = words(area);
|
||||
const key = `feature.${featureName(spec.id)}.label`;
|
||||
return i18n.has(key) ? i18n.t(key) : null;
|
||||
|
|
@ -286,7 +298,7 @@ export function createFeatureRegistry<Api extends RegistryApi>(options: FeatureR
|
|||
scope.commands.register(definition);
|
||||
entry.commands += 1;
|
||||
},
|
||||
text: (key, params) => words(area).t(`${name}.${key}`, params),
|
||||
text: (key, params) => wordOf(module, area, key, params),
|
||||
get storage() { return api.storage(module.storage ?? `${area.namespace}.${name}`); },
|
||||
settings: entry.settings,
|
||||
selector: probe => selectorOf(module, probe),
|
||||
|
|
@ -378,8 +390,7 @@ export function createFeatureRegistry<Api extends RegistryApi>(options: FeatureR
|
|||
const h = ui.h;
|
||||
const forms = entries.map(entry => {
|
||||
const name = featureName(entry.module.id);
|
||||
const i18n = words(area);
|
||||
return { entry, title: featureLabel(entry.spec, area) ?? name, form: buildSettingsForm(h, entry.module.settings!, entry.settings.get(), key => i18n.t(`${name}.${key}`)) };
|
||||
return { entry, title: featureLabel(entry.spec, area) ?? name, form: buildSettingsForm(h, entry.module.settings!, entry.settings.get(), key => wordOf(entry.module, area, key)) };
|
||||
});
|
||||
const single = forms.length === 1 && !notes.length ? forms[0]! : null;
|
||||
ui.dialog({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue