Accept array of dictionaries

This commit is contained in:
Christian Kaisermann 2018-08-12 00:10:40 -03:00
parent 5662f0401c
commit 0bb40b9f34
4 changed files with 11 additions and 10 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "svelte-i18n",
"version": "0.0.1",
"version": "0.0.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -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",

View File

@ -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
}

View File

@ -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)