I18n API
This API provides methods for the Internalization that can be used in plugins.
t
|
Performs translation of the passed string depended on the i18n dictionary |
Performs translation with automatically added namespace like tools.${toolName}
or blockTunes.${tuneName}
t(dictKey: string): string;
string
|
String to translate. Actually, the key from the i18n dictionary under the corresponding section. |
string
|
Translated string. The value from the i18n dictionary. |
/**
* 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': 'Загрузить изображение',
}
}
}
},
})
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': 'Содержание скрыто',
}
}
}
},
})