Browse Source

Make work the init method with options

pull/2385/head
Artur Arseniev 6 years ago
parent
commit
6bd15289c3
  1. 5
      src/i18n/index.js
  2. 17
      test/specs/i18n/index.js

5
src/i18n/index.js

@ -29,7 +29,7 @@
* @module I18n
*/
import { keys, isUndefined } from 'underscore';
import messages from './locale';
import en from './locale/en';
export default () => {
const { language } = window.navigator || {};
@ -38,7 +38,7 @@ export default () => {
locale: localeDef,
localeFallback: 'en',
counter: 'n',
messages
messages: { en }
};
return {
@ -83,6 +83,7 @@ export default () => {
* @private
*/
init(opts = {}) {
this.config = { ...config, ...opts };
this.em = opts.em;
return this;
},

17
test/specs/i18n/index.js

@ -24,6 +24,23 @@ describe('I18n', () => {
expect(obj.getLocale()).toBeTruthy();
});
test('Init with config', () => {
const locale = 'it';
const localeFallback = 'it';
const msg = 'Hello!!!';
obj.init({
em,
locale,
localeFallback,
messages: {
en: { msg }
}
});
expect(obj.getLocale()).toBe(locale);
expect(obj.getConfig().localeFallback).toBe(localeFallback);
expect(obj.getLocale()).toBe(locale);
});
test('setLocale and getLocale methods', () => {
const localeBefore = obj.getLocale();
const localeNew = `${localeBefore}2`;

Loading…
Cancel
Save