Skip to content

05. Plugins Translations

github-actions[bot] edited this page Feb 26, 2025 · 1 revision

addTranslations(namespace, translations)

Add all the plugins translations in one command, this function is only recommended for plugins with a few translations and single file plugins, if there are many translations it is recommended to use addTranslationFiles() described below.

namespace should be the plugins name eg: plugin-conference

translations requires an object with a key for each language supported

'en-us' is used for fallback so must be provided

Example:

kiwi.addTranslations('plugin-ignorelist', {
    'en-us': {
        ignore_list: 'Ignore List',
        ignore_list_empty: 'ignore list empty'
    },
    'es-es': {
        ignore_list: 'Lista de ignorados',
        ignore_list_empty: 'lista de ignorados vacia',
    },
});

addTranslationFiles(namespace, url, fallbackLocale)

Add a namespace with url to translation files

namespace should be the plugins name eg: plugin-conference

url path to the language json file

fallbackLocale optional fallback 'en-us' translations [if not provided will be requested from url]

supported url replacements:

  • {{lng}} is replaced with language eg: 'en-us'
  • {{ns}} is replaced with namespace eg: 'plugin-conference'

'en-us' is used for fallback so a file for it must be provided

Example:

import FallbackLocale from '../res/locales/en-us.json'; // note: import is only supported in webpack bundles

kiwi.addTranslationFiles(
    'plugin-ignorelist',
    'static/plugins/plugin-ignorelist/locales/{{lng}}.json',
    FallbackLocale, // optional
);

Using Translations

within <template>

<div>{{ $t('plugin-ignorelist:ignore_list_empty') }}</div>

within javascript

const TextFormatting = kiwi.require('helpers/TextFormatting');
const myTranslation = TextFormatting.t('plugin-ignorelist:ignore_list');
Clone this wiki locally