Browse Source

Add locales methods to i18n

pull/2385/head
Artur Arseniev 7 years ago
parent
commit
88135630ee
  1. 32
      src/i18n/index.js

32
src/i18n/index.js

@ -25,11 +25,9 @@
import messages from './messages';
export default () => {
let em;
let config;
const { language } = window.navigator || {};
const localeDef = language ? language.split('-')[0] : 'en';
const configDef = {
const config = {
locale: localeDef,
localeFallback: 'en',
counter: 'n',
@ -39,12 +37,34 @@ export default () => {
return {
name: 'I18n',
config,
/**
* Get module configurations
* @returns {Object} Configuration object
*/
getConfig() {
return config;
return this.config;
},
/**
* Update current locale
* @param {String} locale Locale value
* @returns {this}
* @example
* i18n.setLocale('it');
*/
setLocale(locale) {
this.config.locale = locale;
return this;
},
/**
* Get current locale
* @returns {String} Current locale value
*/
getLocale() {
return this.config.locale;
},
/**
@ -53,9 +73,7 @@ export default () => {
* @private
*/
init(opts = {}) {
config = { ...configDef, ...opts };
em = opts.em;
this.em = em;
this.em = opts.em;
return this;
}
};

Loading…
Cancel
Save