mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-11-16 09:59:58 +01:00
refactor: 💡 add dictionary type
This commit is contained in:
parent
02720aa6b6
commit
3423207c02
@ -1,9 +1,10 @@
|
||||
import { LocaleDictionary } from './../types/index'
|
||||
import { writable, derived } from 'svelte/store'
|
||||
import merge from 'deepmerge'
|
||||
|
||||
let dictionary: Record<string, Record<string, any>>
|
||||
let dictionary: LocaleDictionary
|
||||
|
||||
const $dictionary = writable<typeof dictionary>({})
|
||||
const $dictionary = writable<LocaleDictionary>({})
|
||||
$dictionary.subscribe(newDictionary => {
|
||||
dictionary = newDictionary
|
||||
})
|
||||
@ -16,11 +17,9 @@ function hasLocaleDictionary(locale: string) {
|
||||
return locale in dictionary
|
||||
}
|
||||
|
||||
function addMessagesTo(locale: string, ...partials: any[]) {
|
||||
function addMessagesTo(locale: string, ...partials: LocaleDictionary[]) {
|
||||
$dictionary.update(d => {
|
||||
dictionary[locale] = merge.all<any>(
|
||||
[dictionary[locale] || {}].concat(partials)
|
||||
)
|
||||
dictionary[locale] = merge.all([dictionary[locale] || {}].concat(partials))
|
||||
return d
|
||||
})
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
export interface LocaleDictionary {
|
||||
[key: string]: LocaleDictionary | LocaleDictionary[] | string | object
|
||||
}
|
||||
|
||||
export interface MessageObject {
|
||||
id?: string
|
||||
locale?: string
|
||||
|
Loading…
Reference in New Issue
Block a user