|
|
@ -4,6 +4,7 @@ |
|
|
* const editor = grapesjs.init({ |
|
|
* const editor = grapesjs.init({ |
|
|
* i18n: { |
|
|
* i18n: { |
|
|
* locale: 'en', |
|
|
* locale: 'en', |
|
|
|
|
|
* localeFallback: 'en', |
|
|
* messages: { |
|
|
* messages: { |
|
|
* en: { |
|
|
* en: { |
|
|
* hello: 'Hello', |
|
|
* hello: 'Hello', |
|
|
@ -89,6 +90,8 @@ export default () => { |
|
|
/** |
|
|
/** |
|
|
* Get all messages |
|
|
* Get all messages |
|
|
* @param {String} [lang] Specify the language of messages to return |
|
|
* @param {String} [lang] Specify the language of messages to return |
|
|
|
|
|
* @param {Object} [opts] Options |
|
|
|
|
|
* @param {Boolean} [opts.noWarn] Avoid warnings in case of missing language |
|
|
* @returns {Object} |
|
|
* @returns {Object} |
|
|
* @example |
|
|
* @example |
|
|
* i18n.getMessages(); |
|
|
* i18n.getMessages(); |
|
|
@ -96,8 +99,14 @@ export default () => { |
|
|
* i18n.getMessages('en'); |
|
|
* i18n.getMessages('en'); |
|
|
* // -> { hello: '...' }
|
|
|
* // -> { hello: '...' }
|
|
|
*/ |
|
|
*/ |
|
|
getMessages(lang) { |
|
|
getMessages(lang, opts = {}) { |
|
|
const { messages } = this.config; |
|
|
const { em, config } = this; |
|
|
|
|
|
const { messages } = config; |
|
|
|
|
|
!opts.noWarn && |
|
|
|
|
|
lang && |
|
|
|
|
|
!messages[lang] && |
|
|
|
|
|
em && |
|
|
|
|
|
em.logWarning(`'${lang}' i18n lang set not found`); |
|
|
return lang ? messages[lang] : messages; |
|
|
return lang ? messages[lang] : messages; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -159,6 +168,7 @@ export default () => { |
|
|
* @param {String} key Label to translate |
|
|
* @param {String} key Label to translate |
|
|
* @param {Object} [params] Params for the translation |
|
|
* @param {Object} [params] Params for the translation |
|
|
* @param {Object} [opts] Options for the translation |
|
|
* @param {Object} [opts] Options for the translation |
|
|
|
|
|
* @param {Boolean} [opts.noWarn] Avoid warnings in case of missing resources |
|
|
* @returns {String} |
|
|
* @returns {String} |
|
|
* @example |
|
|
* @example |
|
|
* obj.setMessages({ |
|
|
* obj.setMessages({ |
|
|
@ -176,7 +186,7 @@ export default () => { |
|
|
const { em } = this; |
|
|
const { em } = this; |
|
|
const param = params || {}; |
|
|
const param = params || {}; |
|
|
const locale = opts.l || this.getLocale(); |
|
|
const locale = opts.l || this.getLocale(); |
|
|
const msgSet = this.getMessages(locale) || {}; |
|
|
const msgSet = this.getMessages(locale, opts) || {}; |
|
|
const reg = new RegExp(`\{([\\w\\d-]*)\}`, 'g'); |
|
|
const reg = new RegExp(`\{([\\w\\d-]*)\}`, 'g'); |
|
|
let result = msgSet[key]; |
|
|
let result = msgSet[key]; |
|
|
!result && |
|
|
!result && |
|
|
|