cbvirtua 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/md.txt +24 -0
- package/package.json +1 -1
- package/vue-i18n-dev.zip +0 -0
package/md.txt
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default class CustomFormatter {
|
|
2
|
+
constructor (options = {}) {
|
|
3
|
+
this._locale = options.locale || 'en-US'
|
|
4
|
+
this._formatter = new MessageFormat(this._locale)
|
|
5
|
+
this._caches = Object.create(null)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interpolate (message, values) {
|
|
9
|
+
let fn = this._caches[message]
|
|
10
|
+
if (!fn) {
|
|
11
|
+
fn = this._formatter.compile(message, this._locale)
|
|
12
|
+
this._caches[message] = fn
|
|
13
|
+
}
|
|
14
|
+
return [fn(values)]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 在 Vue 的原型中挂载 $t 方法,这是我们为什么能够直接在模板中使用的原因
|
|
19
|
+
// 把 VueI18n 对象实例的方法都注入到 Vue 实例上
|
|
20
|
+
Vue.prototype.$t = function (key: Path, ...values: any): TranslateResult {
|
|
21
|
+
const i18n = this.$i18n
|
|
22
|
+
// 代理模式的使用
|
|
23
|
+
return i18n._t(key, i18n.locale, i18n._getMessages(), this, ...values)
|
|
24
|
+
}
|
package/package.json
CHANGED
package/vue-i18n-dev.zip
ADDED
|
Binary file
|