I18n API

This API provides methods for the Internalization that can be used in plugins.

Available methods

t Performs translation of the passed string depended on the i18n dictionary

t(dictKey: string)

Performs translation with automatically added namespace like tools.${toolName}  or blockTunes.${tuneName}

t(dictKey: string): string;

Parameters

string String to translate. Actually, the key from the i18n dictionary under the corresponding section.

Return value

string Translated string. The value from the i18n dictionary.

Example for Block and Inline Tools

/** * Using in a plugin */ class SimpleImage { constructor({data, api}){ this.api = api; } render(){ const button = document.createElement('button'); button.textContent = this.api.i18n.t('Upload an image'); return button; } } /** * Editor.js initialization * Example of passing i18n dictionary */ new Editorjs({ // ... tools: { image: SimpleImage, }, i18n: { messages: { tools: { image: { 'Upload an image': 'Загрузить изображение', } } } }, })

Example for Block Tunes

class SpoilerTune { constructor({ api }) { this.api = api; } render() { const button = document.createElement('button'); button.textContent = this.api.i18n.t('Hide content'); return button; } } /** * Editor.js initialization * Example of passing i18n dictionary */ new Editorjs({ // ... tools: { spoiler: SpoilerTune, }, tunes: ['spoiler'] i18n: { messages: { blockTunes: { spoiler: { 'Hide content': 'Содержание скрыто', } } } }, })