mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.1 KiB
3.1 KiB
I18n
You can customize the initial state of the module from the editor initialization
const editor = grapesjs.init({
i18n: {
locale: 'en',
localeFallback: 'en',
messages: {
en: {
hello: 'Hello',
},
...
}
}
})
Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
const i18n = editor.I18n;
Events
i18n:add- New set of messages is addedi18n:update- The set of messages is updatedi18n:locale- Locale changed
getConfig
Get module configurations
Returns Object Configuration object
setLocale
Update current locale
Parameters
localeString Locale value
Examples
i18n.setLocale('it');
Returns this
getLocale
Get current locale
Returns String Current locale value
getMessages
Get all messages
Parameters
langString? Specify the language of messages to returnoptsObject? Options (optional, default{})opts.debugBoolean? Show warnings in case of missing language
Examples
i18n.getMessages();
// -> { en: { hello: '...' }, ... }
i18n.getMessages('en');
// -> { hello: '...' }
Returns Object
setMessages
Set new set of messages
Parameters
msgObject Set of messages
Examples
i18n.getMessages();
// -> { en: { msg1: 'Msg 1', msg2: 'Msg 2', } }
i18n.setMessages({ en: { msg2: 'Msg 2 up', msg3: 'Msg 3', } });
// Set replaced
i18n.getMessages();
// -> { en: { msg2: 'Msg 2 up', msg3: 'Msg 3', } }
Returns this
addMessages
Update messages
Parameters
msgObject Set of messages to add
Examples
i18n.getMessages();
// -> { en: { msg1: 'Msg 1', msg2: 'Msg 2', } }
i18n.addMessages({ en: { msg2: 'Msg 2 up', msg3: 'Msg 3', } });
// Set updated
i18n.getMessages();
// -> { en: { msg1: 'Msg 1', msg2: 'Msg 2 up', msg3: 'Msg 3', } }
Returns this
t
Translate the locale message
Parameters
Examples
obj.setMessages({
en: { msg: 'Msg', msg2: 'Msg {test}'},
it: { msg2: 'Msg {test} it'},
});
obj.t('msg');
// -> outputs `Msg`
obj.t('msg2', { params: { test: 'hello' } }); // use params
// -> outputs `Msg hello`
obj.t('msg2', { l: 'it', params: { test: 'hello' } }); // custom local
// -> outputs `Msg hello it`
Returns String