mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-11-16 09:59:58 +01:00
feat: 🎸 addMessagesTo
method
This commit is contained in:
parent
a1dc268654
commit
d6b8664009
@ -9,6 +9,7 @@ export { $locale as locale, loadLocale as preloadLocale } from './stores/locale'
|
||||
export {
|
||||
$dictionary as dictionary,
|
||||
$locales as locales,
|
||||
addMessagesTo,
|
||||
} from './stores/dictionary'
|
||||
export { $loading as loading } from './stores/loading'
|
||||
export { $format as format, $format as _, $format as t } from './stores/format'
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { writable, derived } from 'svelte/store'
|
||||
import merge from 'deepmerge'
|
||||
|
||||
let dictionary: Record<string, Record<string, any>>
|
||||
|
||||
@ -15,8 +16,23 @@ function hasLocaleDictionary(locale: string) {
|
||||
return locale in dictionary
|
||||
}
|
||||
|
||||
function addMessagesTo(locale: string, ...partials: any[]) {
|
||||
$dictionary.update(d => {
|
||||
dictionary[locale] = merge.all<any>(
|
||||
[dictionary[locale] || {}].concat(partials)
|
||||
)
|
||||
return d
|
||||
})
|
||||
}
|
||||
|
||||
const $locales = derived([$dictionary], ([$dictionary]) =>
|
||||
Object.keys($dictionary)
|
||||
)
|
||||
|
||||
export { $dictionary, $locales, getDictionary, hasLocaleDictionary }
|
||||
export {
|
||||
$dictionary,
|
||||
$locales,
|
||||
getDictionary,
|
||||
hasLocaleDictionary,
|
||||
addMessagesTo,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user