@dcloudio/uni-i18n
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -141,2 +141,3 @@ 'use strict'; | ||
} | ||
const watchers = []; | ||
var index = { | ||
@@ -151,4 +152,8 @@ init(options) { | ||
setLocale(locale) { | ||
const oldLocale = curLocale; | ||
curLocale = normalizeLocale(locale); | ||
curMessages = messages[curLocale]; | ||
watchers.forEach((watcher) => { | ||
watcher(curLocale, oldLocale); | ||
}); | ||
}, | ||
@@ -158,2 +163,8 @@ getLocale() { | ||
}, | ||
watchLocale(fn) { | ||
const index = watchers.push(fn) - 1; | ||
return () => { | ||
watchers.splice(index, 1); | ||
}; | ||
}, | ||
t(key, values) { | ||
@@ -160,0 +171,0 @@ if (!hasOwn(curMessages, key)) { |
@@ -8,2 +8,3 @@ | ||
getLocale(): BuiltInLocale; | ||
watchLocale(fn: LocaleWatcher): () => void; | ||
t(key: string, values?: Record<string, unknown> | unknown[] | undefined): string; | ||
@@ -23,2 +24,4 @@ }; | ||
declare type LocaleWatcher = (newLocale: BuiltInLocale, oldLocale: BuiltInLocale) => void; | ||
export { } |
@@ -139,2 +139,3 @@ const isObject = (val) => val !== null && typeof val === 'object'; | ||
} | ||
const watchers = []; | ||
var index = { | ||
@@ -149,4 +150,8 @@ init(options) { | ||
setLocale(locale) { | ||
const oldLocale = curLocale; | ||
curLocale = normalizeLocale(locale); | ||
curMessages = messages[curLocale]; | ||
watchers.forEach((watcher) => { | ||
watcher(curLocale, oldLocale); | ||
}); | ||
}, | ||
@@ -156,2 +161,8 @@ getLocale() { | ||
}, | ||
watchLocale(fn) { | ||
const index = watchers.push(fn) - 1; | ||
return () => { | ||
watchers.splice(index, 1); | ||
}; | ||
}, | ||
t(key, values) { | ||
@@ -158,0 +169,0 @@ if (!hasOwn(curMessages, key)) { |
{ | ||
"name": "@dcloudio/uni-i18n", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "@dcloudio/uni-i18n", | ||
@@ -5,0 +5,0 @@ "main": "dist/uni-i18n.cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23145
364