From 0bb40b9f34cc96f4ab20b138f00ab52f28b808ed Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Sun, 12 Aug 2018 00:10:40 -0300 Subject: [PATCH] Accept array of dictionaries --- package-lock.json | 2 +- package.json | 2 +- src/index.js | 8 ++++++-- test/index.test.js | 9 +++------ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4c56166..00e56a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte-i18n", - "version": "0.0.1", + "version": "0.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 836179a..73bb4e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-i18n", - "version": "0.0.3", + "version": "0.0.4", "license": "MIT", "main": "dist/i18n.js", "module": "dist/i18n.m.js", diff --git a/src/index.js b/src/index.js index f9af24d..4f18e6b 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 = ( @@ -83,7 +83,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 f747a0a..162523b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -2,9 +2,9 @@ import { i18n } from '../src/index' import { Store } from 'svelte/store.umd' -import { capital, title, upper, lower, isObject, warn } from '../src/utils' +import { capital, title, upper, lower, isObject } from '../src/utils' -const store = new Store() +let store = new Store() const locales = { 'pt-br': { test: 'teste', @@ -29,11 +29,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)