mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-09-28 15:14:45 +02:00
Accept array of dictionaries
This commit is contained in:
parent
5662f0401c
commit
0bb40b9f34
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "svelte-i18n",
|
"name": "svelte-i18n",
|
||||||
"version": "0.0.1",
|
"version": "0.0.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "svelte-i18n",
|
"name": "svelte-i18n",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/i18n.js",
|
"main": "dist/i18n.js",
|
||||||
"module": "dist/i18n.m.js",
|
"module": "dist/i18n.m.js",
|
||||||
|
@ -7,7 +7,7 @@ export { capital, title, upper, lower }
|
|||||||
|
|
||||||
export function i18n(store, { dictionary: initialDictionary }) {
|
export function i18n(store, { dictionary: initialDictionary }) {
|
||||||
const formatter = new Formatter()
|
const formatter = new Formatter()
|
||||||
let dictionary = {}
|
let dictionary
|
||||||
let currentLocale
|
let currentLocale
|
||||||
|
|
||||||
const getLocalizedMessage = (
|
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
|
return store
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
import { i18n } from '../src/index'
|
import { i18n } from '../src/index'
|
||||||
import { Store } from 'svelte/store.umd'
|
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 = {
|
const locales = {
|
||||||
'pt-br': {
|
'pt-br': {
|
||||||
test: 'teste',
|
test: 'teste',
|
||||||
@ -29,11 +29,8 @@ const locales = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
i18n(store, { dictionary: locales })
|
i18n(store, { dictionary: [locales] })
|
||||||
|
|
||||||
/**
|
|
||||||
* Dummy test
|
|
||||||
*/
|
|
||||||
describe('Utilities', () => {
|
describe('Utilities', () => {
|
||||||
it('should check if a variable is an object', () => {
|
it('should check if a variable is an object', () => {
|
||||||
expect(isObject({})).toBe(true)
|
expect(isObject({})).toBe(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user