Skip to content

PluginI18n

Provides the texts of a plugin in several languages. define takes the texts of the plugin in each language and returns a function t that answers in the language that the app currently uses. When a language has no text for a key, the English text is used. No permission is needed.

A text that the plugin computed earlier does not change by itself when the person changes the language. The plugin watches ctx.keys.app.language and computes the text again.

const words = ctx.i18n.define({
en: { done: 'Done', count: '{n} rows' },
fr: { done: 'Terminé', count: '{n} lignes' },
});
ctx.ui.notice({ text: words.t('count', { n: 3 }) }); // '3 rows', or '3 lignes' in French
define<K>(bundles): object;

Registers the texts of the plugin.

Type Parameter Description
K extends string the union of the keys of the texts
Parameter Type Description
bundles { [language: string]: Readonly<Partial<Record<K, string>>>; en: Readonly<Record<K, string>>; } an object such as { en: {…}, fr: {…} }. English is required, because the app uses it for any text that another language does not have
bundles.en Readonly<Record<K, string>> -

object

an object with t(key, params?), which returns the text in the current language and replaces each {slot} of the text with the value of the same name in params

Name Type
t() (key, params?) => string

language(): string;

Returns the language that the app currently uses, as a code such as en.

string