mirror of https://github.com/artf/grapesjs.git
6 changed files with 192 additions and 6 deletions
@ -0,0 +1,157 @@ |
|||||
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> |
||||
|
|
||||
|
## I18n |
||||
|
|
||||
|
You can customize the initial state of the module from the editor initialization |
||||
|
|
||||
|
```js |
||||
|
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 |
||||
|
|
||||
|
```js |
||||
|
const i18n = editor.I18n; |
||||
|
``` |
||||
|
|
||||
|
### Events |
||||
|
|
||||
|
- `i18n:add` - New set of messages is added |
||||
|
- `i18n:update` - The set of messages is updated |
||||
|
- `i18n:locale` - Locale changed |
||||
|
|
||||
|
## getConfig |
||||
|
|
||||
|
Get module configurations |
||||
|
|
||||
|
Returns **[Object][1]** Configuration object |
||||
|
|
||||
|
## setLocale |
||||
|
|
||||
|
Update current locale |
||||
|
|
||||
|
### Parameters |
||||
|
|
||||
|
- `locale` **[String][2]** Locale value |
||||
|
|
||||
|
### Examples |
||||
|
|
||||
|
```javascript |
||||
|
i18n.setLocale('it'); |
||||
|
``` |
||||
|
|
||||
|
Returns **this** |
||||
|
|
||||
|
## getLocale |
||||
|
|
||||
|
Get current locale |
||||
|
|
||||
|
Returns **[String][2]** Current locale value |
||||
|
|
||||
|
## getMessages |
||||
|
|
||||
|
Get all messages |
||||
|
|
||||
|
### Parameters |
||||
|
|
||||
|
- `lang` **[String][2]?** Specify the language of messages to return |
||||
|
- `opts` **[Object][1]?** Options (optional, default `{}`) |
||||
|
- `opts.debug` **[Boolean][3]?** Show warnings in case of missing language |
||||
|
|
||||
|
### Examples |
||||
|
|
||||
|
```javascript |
||||
|
i18n.getMessages(); |
||||
|
// -> { en: { hello: '...' }, ... } |
||||
|
i18n.getMessages('en'); |
||||
|
// -> { hello: '...' } |
||||
|
``` |
||||
|
|
||||
|
Returns **[Object][1]** |
||||
|
|
||||
|
## setMessages |
||||
|
|
||||
|
Set new set of messages |
||||
|
|
||||
|
### Parameters |
||||
|
|
||||
|
- `msg` **[Object][1]** Set of messages |
||||
|
|
||||
|
### Examples |
||||
|
|
||||
|
```javascript |
||||
|
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 |
||||
|
|
||||
|
- `msg` **[Object][1]** Set of messages to add |
||||
|
|
||||
|
### Examples |
||||
|
|
||||
|
```javascript |
||||
|
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 |
||||
|
|
||||
|
- `key` **[String][2]** Label to translate |
||||
|
- `opts` **[Object][1]?** Options for the translation (optional, default `{}`) |
||||
|
- `opts.params` **[Object][1]?** Params for the translation |
||||
|
- `opts.debug` **[Boolean][3]?** Show warnings in case of missing resources |
||||
|
|
||||
|
### Examples |
||||
|
|
||||
|
```javascript |
||||
|
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][2]** |
||||
|
|
||||
|
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object |
||||
|
|
||||
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String |
||||
|
|
||||
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean |
||||
Loading…
Reference in new issue