diff --git a/src/index.js b/src/index.js index f0ebeb8..01afef7 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ export { capital, title, upper, lower } export function i18n(store, { dictionary: initialDictionary }) { const formatter = new Formatter() - let dictionary = {} + let dictionary let currentLocale const getLocalizedMessage = ( @@ -94,7 +94,11 @@ export function i18n(store, { dictionary: initialDictionary }) { }, } - store.i18n.extendDictionary(initialDictionary) + if (Array.isArray(initialDictionary)) { + dictionary = deepmerge.all(initialDictionary) + } else { + initialDictionary = dictionary + } return store } diff --git a/test/index.test.js b/test/index.test.js index f234056..27fc7c6 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,7 +4,7 @@ import { i18n } from '../src/index' import { Store } from 'svelte/store.umd' import { capital, title, upper, lower, isObject } from '../src/utils' -const store = new Store() +let store = new Store() const locales = { 'pt-br': { test: 'teste', @@ -30,11 +30,8 @@ const locales = { }, } -i18n(store, { dictionary: locales }) +i18n(store, { dictionary: [locales] }) -/** - * Dummy test - */ describe('Utilities', () => { it('should check if a variable is an object', () => { expect(isObject({})).toBe(true)