vue-i18n 9.2.0-beta.9 → 9.2.0
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/dist/vue-i18n.cjs.js +646 -166
- package/dist/vue-i18n.cjs.prod.js +631 -160
- package/dist/vue-i18n.d.ts +266 -316
- package/dist/vue-i18n.esm-browser.js +1000 -226
- package/dist/vue-i18n.esm-browser.prod.js +3 -3
- package/dist/vue-i18n.esm-bundler.js +667 -182
- package/dist/vue-i18n.global.js +1000 -225
- package/dist/vue-i18n.global.prod.js +3 -3
- package/dist/vue-i18n.runtime.esm-browser.js +962 -209
- package/dist/vue-i18n.runtime.esm-browser.prod.js +3 -3
- package/dist/vue-i18n.runtime.esm-bundler.js +667 -182
- package/dist/vue-i18n.runtime.global.js +962 -208
- package/dist/vue-i18n.runtime.global.prod.js +3 -3
- package/index.mjs +1 -0
- package/package.json +20 -7
package/dist/vue-i18n.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* vue-i18n v9.2.0
|
|
3
|
-
* (c)
|
|
2
|
+
* vue-i18n v9.2.0
|
|
3
|
+
* (c) 2022 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
@@ -19,10 +19,10 @@ var vue = require('vue');
|
|
|
19
19
|
*
|
|
20
20
|
* @VueI18nGeneral
|
|
21
21
|
*/
|
|
22
|
-
const VERSION = '9.2.0
|
|
22
|
+
const VERSION = '9.2.0';
|
|
23
23
|
|
|
24
24
|
let code$1 = coreBase.CoreWarnCodes.__EXTEND_POINT__;
|
|
25
|
-
const inc$1 = () => code$1
|
|
25
|
+
const inc$1 = () => ++code$1;
|
|
26
26
|
const I18nWarnCodes = {
|
|
27
27
|
FALLBACK_TO_ROOT: code$1,
|
|
28
28
|
NOT_SUPPORTED_PRESERVE: inc$1(),
|
|
@@ -30,8 +30,7 @@ const I18nWarnCodes = {
|
|
|
30
30
|
NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc$1(),
|
|
31
31
|
NOT_SUPPORTED_GET_CHOICE_INDEX: inc$1(),
|
|
32
32
|
COMPONENT_NAME_LEGACY_COMPATIBLE: inc$1(),
|
|
33
|
-
NOT_FOUND_PARENT_SCOPE: inc$1()
|
|
34
|
-
NOT_SUPPORT_MULTI_I18N_INSTANCE: inc$1() // 14
|
|
33
|
+
NOT_FOUND_PARENT_SCOPE: inc$1() // 13
|
|
35
34
|
};
|
|
36
35
|
const warnMessages = {
|
|
37
36
|
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
|
|
@@ -40,15 +39,14 @@ const warnMessages = {
|
|
|
40
39
|
[I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supported 'preserveDirectiveContent'.`,
|
|
41
40
|
[I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
|
|
42
41
|
[I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
|
|
43
|
-
[I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope
|
|
44
|
-
[I18nWarnCodes.NOT_SUPPORT_MULTI_I18N_INSTANCE]: `Not support multi i18n instance.`
|
|
42
|
+
[I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`
|
|
45
43
|
};
|
|
46
44
|
function getWarnMessage(code, ...args) {
|
|
47
45
|
return shared.format(warnMessages[code], ...args);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
let code = coreBase.CompileErrorCodes.__EXTEND_POINT__;
|
|
51
|
-
const inc = () => code
|
|
49
|
+
const inc = () => ++code;
|
|
52
50
|
const I18nErrorCodes = {
|
|
53
51
|
// composer module errors
|
|
54
52
|
UNEXPECTED_RETURN_TYPE: code,
|
|
@@ -70,8 +68,12 @@ const I18nErrorCodes = {
|
|
|
70
68
|
NOT_COMPATIBLE_LEGACY_VUE_I18N: inc(),
|
|
71
69
|
// bridge support vue 2.x only
|
|
72
70
|
BRIDGE_SUPPORT_VUE_2_ONLY: inc(),
|
|
71
|
+
// need to define `i18n` option in `allowComposition: true` and `useScope: 'local' at `useI18n``
|
|
72
|
+
MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION: inc(),
|
|
73
|
+
// Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly
|
|
74
|
+
NOT_AVAILABLE_COMPOSITION_IN_LEGACY: inc(),
|
|
73
75
|
// for enhancement
|
|
74
|
-
__EXTEND_POINT__: inc() //
|
|
76
|
+
__EXTEND_POINT__: inc() // 29
|
|
75
77
|
};
|
|
76
78
|
function createI18nError(code, ...args) {
|
|
77
79
|
return coreBase.createCompileError(code, null, { messages: errorMessages, args } );
|
|
@@ -88,7 +90,9 @@ const errorMessages = {
|
|
|
88
90
|
[I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`,
|
|
89
91
|
[I18nErrorCodes.NOT_INSLALLED_WITH_PROVIDE]: 'Need to install with `provide` function',
|
|
90
92
|
[I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N]: 'Not compatible legacy VueI18n.',
|
|
91
|
-
[I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY]: 'vue-i18n-bridge support Vue 2.x only'
|
|
93
|
+
[I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY]: 'vue-i18n-bridge support Vue 2.x only',
|
|
94
|
+
[I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION]: 'Must define ‘i18n’ option or custom block in Composition API with using local scope in Legacy API mode',
|
|
95
|
+
[I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY]: 'Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly'
|
|
92
96
|
};
|
|
93
97
|
|
|
94
98
|
const TransrateVNodeSymbol =
|
|
@@ -98,7 +102,9 @@ const NumberPartsSymbol = /* #__PURE__*/ shared.makeSymbol('__numberParts');
|
|
|
98
102
|
const EnableEmitter = /* #__PURE__*/ shared.makeSymbol('__enableEmitter');
|
|
99
103
|
const DisableEmitter = /* #__PURE__*/ shared.makeSymbol('__disableEmitter');
|
|
100
104
|
const SetPluralRulesSymbol = shared.makeSymbol('__setPluralRules');
|
|
101
|
-
shared.makeSymbol('__intlifyMeta');
|
|
105
|
+
shared.makeSymbol('__intlifyMeta');
|
|
106
|
+
const InejctWithOption = /* #__PURE__*/ shared.makeSymbol('__injectWithOption');
|
|
107
|
+
const __VUE_I18N_BRIDGE__ = '__VUE_I18N_BRIDGE__';
|
|
102
108
|
|
|
103
109
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
104
110
|
/**
|
|
@@ -206,9 +212,51 @@ function deepCopy(src, des) {
|
|
|
206
212
|
function getComponentOptions(instance) {
|
|
207
213
|
return instance.type ;
|
|
208
214
|
}
|
|
215
|
+
function adjustI18nResources(global, options, componentOptions // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
216
|
+
) {
|
|
217
|
+
let messages = shared.isObject(options.messages) ? options.messages : {};
|
|
218
|
+
if ('__i18nGlobal' in componentOptions) {
|
|
219
|
+
messages = getLocaleMessages(global.locale.value, {
|
|
220
|
+
messages,
|
|
221
|
+
__i18n: componentOptions.__i18nGlobal
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
// merge locale messages
|
|
225
|
+
const locales = Object.keys(messages);
|
|
226
|
+
if (locales.length) {
|
|
227
|
+
locales.forEach(locale => {
|
|
228
|
+
global.mergeLocaleMessage(locale, messages[locale]);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
{
|
|
232
|
+
// merge datetime formats
|
|
233
|
+
if (shared.isObject(options.datetimeFormats)) {
|
|
234
|
+
const locales = Object.keys(options.datetimeFormats);
|
|
235
|
+
if (locales.length) {
|
|
236
|
+
locales.forEach(locale => {
|
|
237
|
+
global.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// merge number formats
|
|
242
|
+
if (shared.isObject(options.numberFormats)) {
|
|
243
|
+
const locales = Object.keys(options.numberFormats);
|
|
244
|
+
if (locales.length) {
|
|
245
|
+
locales.forEach(locale => {
|
|
246
|
+
global.mergeNumberFormat(locale, options.numberFormats[locale]);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function createTextNode(key) {
|
|
253
|
+
return vue.createVNode(vue.Text, null, key, 0)
|
|
254
|
+
;
|
|
255
|
+
}
|
|
209
256
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
210
257
|
|
|
211
258
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
259
|
+
// extend VNode interface
|
|
212
260
|
const DEVTOOLS_META = '__INTLIFY_META__';
|
|
213
261
|
let composerID = 0;
|
|
214
262
|
function defineCoreMissingHandler(missing) {
|
|
@@ -294,9 +342,12 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
294
342
|
let _postTranslation = shared.isFunction(options.postTranslation)
|
|
295
343
|
? options.postTranslation
|
|
296
344
|
: null;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
345
|
+
// prettier-ignore
|
|
346
|
+
let _warnHtmlMessage = __root
|
|
347
|
+
? __root.warnHtmlMessage
|
|
348
|
+
: shared.isBoolean(options.warnHtmlMessage)
|
|
349
|
+
? options.warnHtmlMessage
|
|
350
|
+
: true;
|
|
300
351
|
let _escapeParameter = !!options.escapeParameter;
|
|
301
352
|
// custom linked modifiers
|
|
302
353
|
// prettier-ignore
|
|
@@ -311,6 +362,7 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
311
362
|
// eslint-disable-next-line prefer-const
|
|
312
363
|
let _context;
|
|
313
364
|
function getCoreContext() {
|
|
365
|
+
_isGlobal && coreBase.setFallbackContext(null);
|
|
314
366
|
const ctxOptions = {
|
|
315
367
|
version: VERSION,
|
|
316
368
|
locale: _locale.value,
|
|
@@ -344,7 +396,9 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
344
396
|
? _context.__v_emitter
|
|
345
397
|
: undefined;
|
|
346
398
|
}
|
|
347
|
-
|
|
399
|
+
const ctx = coreBase.createCoreContext(ctxOptions);
|
|
400
|
+
_isGlobal && coreBase.setFallbackContext(ctx);
|
|
401
|
+
return ctx;
|
|
348
402
|
}
|
|
349
403
|
_context = getCoreContext();
|
|
350
404
|
coreBase.updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
|
@@ -414,10 +468,18 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
414
468
|
{
|
|
415
469
|
try {
|
|
416
470
|
coreBase.setAdditionalMeta(getMetaInfo());
|
|
471
|
+
if (!_isGlobal) {
|
|
472
|
+
_context.fallbackContext = __root
|
|
473
|
+
? coreBase.getFallbackContext()
|
|
474
|
+
: undefined;
|
|
475
|
+
}
|
|
417
476
|
ret = fn(_context);
|
|
418
477
|
}
|
|
419
478
|
finally {
|
|
420
479
|
coreBase.setAdditionalMeta(null);
|
|
480
|
+
if (!_isGlobal) {
|
|
481
|
+
_context.fallbackContext = undefined;
|
|
482
|
+
}
|
|
421
483
|
}
|
|
422
484
|
}
|
|
423
485
|
if (shared.isNumber(ret) && ret === coreBase.NOT_REOSLVED) {
|
|
@@ -480,7 +542,9 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
480
542
|
}
|
|
481
543
|
// for custom processor
|
|
482
544
|
function normalize(values) {
|
|
483
|
-
return values.map(val => shared.isString(val)
|
|
545
|
+
return values.map(val => shared.isString(val) || shared.isNumber(val) || shared.isBoolean(val)
|
|
546
|
+
? createTextNode(String(val))
|
|
547
|
+
: val);
|
|
484
548
|
}
|
|
485
549
|
const interpolate = (val) => val;
|
|
486
550
|
const processor = {
|
|
@@ -503,7 +567,7 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
503
567
|
return ret;
|
|
504
568
|
}, () => coreBase.parseTranslateArgs(...args), 'translate',
|
|
505
569
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
506
|
-
root => root[TransrateVNodeSymbol](...args), key => [
|
|
570
|
+
root => root[TransrateVNodeSymbol](...args), key => [createTextNode(key)], val => shared.isArray(val));
|
|
507
571
|
}
|
|
508
572
|
// numberParts, using for `i18n-n` component
|
|
509
573
|
function numberParts(...args) {
|
|
@@ -600,7 +664,7 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
600
664
|
// for debug
|
|
601
665
|
composerID++;
|
|
602
666
|
// watch root locale & fallbackLocale
|
|
603
|
-
if (__root) {
|
|
667
|
+
if (__root && shared.inBrowser) {
|
|
604
668
|
vue.watch(__root.locale, (val) => {
|
|
605
669
|
if (_inheritLocale) {
|
|
606
670
|
_locale.value = val;
|
|
@@ -710,11 +774,10 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
710
774
|
composer.getNumberFormat = getNumberFormat;
|
|
711
775
|
composer.setNumberFormat = setNumberFormat;
|
|
712
776
|
composer.mergeNumberFormat = mergeNumberFormat;
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
}
|
|
777
|
+
composer[InejctWithOption] = options.__injectWithOption;
|
|
778
|
+
composer[TransrateVNodeSymbol] = transrateVNode;
|
|
779
|
+
composer[DatetimePartsSymbol] = datetimeParts;
|
|
780
|
+
composer[NumberPartsSymbol] = numberParts;
|
|
718
781
|
}
|
|
719
782
|
// for vue-devtools timeline event
|
|
720
783
|
{
|
|
@@ -782,7 +845,7 @@ function convertComposerOptions(options) {
|
|
|
782
845
|
return messages;
|
|
783
846
|
}, (messages || {}));
|
|
784
847
|
}
|
|
785
|
-
const { __i18n, __root } = options;
|
|
848
|
+
const { __i18n, __root, __injectWithOption } = options;
|
|
786
849
|
const datetimeFormats = options.datetimeFormats;
|
|
787
850
|
const numberFormats = options.numberFormats;
|
|
788
851
|
const flatJson = options.flatJson;
|
|
@@ -806,7 +869,8 @@ function convertComposerOptions(options) {
|
|
|
806
869
|
messageResolver: options.messageResolver,
|
|
807
870
|
inheritLocale,
|
|
808
871
|
__i18n,
|
|
809
|
-
__root
|
|
872
|
+
__root,
|
|
873
|
+
__injectWithOption
|
|
810
874
|
};
|
|
811
875
|
}
|
|
812
876
|
/**
|
|
@@ -1116,6 +1180,37 @@ const baseFormatProps = {
|
|
|
1116
1180
|
}
|
|
1117
1181
|
};
|
|
1118
1182
|
|
|
1183
|
+
function getInterpolateArg(
|
|
1184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1185
|
+
{ slots }, // SetupContext,
|
|
1186
|
+
keys) {
|
|
1187
|
+
if (keys.length === 1 && keys[0] === 'default') {
|
|
1188
|
+
// default slot with list
|
|
1189
|
+
const ret = slots.default ? slots.default() : [];
|
|
1190
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1191
|
+
return ret.reduce((slot, current) => {
|
|
1192
|
+
return (slot = [
|
|
1193
|
+
...slot,
|
|
1194
|
+
...(shared.isArray(current.children) ? current.children : [current])
|
|
1195
|
+
]);
|
|
1196
|
+
}, []);
|
|
1197
|
+
}
|
|
1198
|
+
else {
|
|
1199
|
+
// named slots
|
|
1200
|
+
return keys.reduce((arg, key) => {
|
|
1201
|
+
const slot = slots[key];
|
|
1202
|
+
if (slot) {
|
|
1203
|
+
arg[key] = slot();
|
|
1204
|
+
}
|
|
1205
|
+
return arg;
|
|
1206
|
+
}, {});
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1210
|
+
function getFragmentableTag(tag) {
|
|
1211
|
+
return vue.Fragment ;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1119
1214
|
/**
|
|
1120
1215
|
* Translation Component
|
|
1121
1216
|
*
|
|
@@ -1165,7 +1260,7 @@ const baseFormatProps = {
|
|
|
1165
1260
|
*
|
|
1166
1261
|
* @VueI18nComponent
|
|
1167
1262
|
*/
|
|
1168
|
-
const Translation =
|
|
1263
|
+
const Translation = /* defineComponent */ {
|
|
1169
1264
|
/* eslint-disable */
|
|
1170
1265
|
name: 'i18n-t',
|
|
1171
1266
|
props: shared.assign({
|
|
@@ -1180,13 +1275,17 @@ const Translation = /* #__PURE__*/ vue.defineComponent({
|
|
|
1180
1275
|
}
|
|
1181
1276
|
}, baseFormatProps),
|
|
1182
1277
|
/* eslint-enable */
|
|
1278
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1183
1279
|
setup(props, context) {
|
|
1184
1280
|
const { slots, attrs } = context;
|
|
1185
1281
|
// NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
|
|
1186
1282
|
const i18n = props.i18n ||
|
|
1187
|
-
useI18n({
|
|
1188
|
-
|
|
1283
|
+
useI18n({
|
|
1284
|
+
useScope: props.scope,
|
|
1285
|
+
__useComponent: true
|
|
1286
|
+
});
|
|
1189
1287
|
return () => {
|
|
1288
|
+
const keys = Object.keys(slots).filter(key => key !== '_');
|
|
1190
1289
|
const options = {};
|
|
1191
1290
|
if (props.locale) {
|
|
1192
1291
|
options.locale = props.locale;
|
|
@@ -1198,28 +1297,17 @@ const Translation = /* #__PURE__*/ vue.defineComponent({
|
|
|
1198
1297
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1199
1298
|
const children = i18n[TransrateVNodeSymbol](props.keypath, arg, options);
|
|
1200
1299
|
const assignedAttrs = shared.assign({}, attrs);
|
|
1201
|
-
const tag = shared.isString(props.tag) || shared.isObject(props.tag)
|
|
1300
|
+
const tag = shared.isString(props.tag) || shared.isObject(props.tag)
|
|
1301
|
+
? props.tag
|
|
1302
|
+
: getFragmentableTag();
|
|
1202
1303
|
return vue.h(tag, assignedAttrs, children);
|
|
1203
1304
|
};
|
|
1204
1305
|
}
|
|
1205
|
-
}
|
|
1206
|
-
function getInterpolateArg({ slots }, keys) {
|
|
1207
|
-
if (keys.length === 1 && keys[0] === 'default') {
|
|
1208
|
-
// default slot only
|
|
1209
|
-
return slots.default ? slots.default() : [];
|
|
1210
|
-
}
|
|
1211
|
-
else {
|
|
1212
|
-
// named slots
|
|
1213
|
-
return keys.reduce((arg, key) => {
|
|
1214
|
-
const slot = slots[key];
|
|
1215
|
-
if (slot) {
|
|
1216
|
-
arg[key] = slot();
|
|
1217
|
-
}
|
|
1218
|
-
return arg;
|
|
1219
|
-
}, {});
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1306
|
+
};
|
|
1222
1307
|
|
|
1308
|
+
function isVNode(target) {
|
|
1309
|
+
return shared.isArray(target) && !shared.isString(target[0]);
|
|
1310
|
+
}
|
|
1223
1311
|
function renderFormatter(props, context, slotKeys, partFormatter) {
|
|
1224
1312
|
const { slots, attrs } = context;
|
|
1225
1313
|
return () => {
|
|
@@ -1249,37 +1337,26 @@ function renderFormatter(props, context, slotKeys, partFormatter) {
|
|
|
1249
1337
|
if (shared.isArray(parts)) {
|
|
1250
1338
|
children = parts.map((part, index) => {
|
|
1251
1339
|
const slot = slots[part.type];
|
|
1252
|
-
|
|
1340
|
+
const node = slot
|
|
1253
1341
|
? slot({ [part.type]: part.value, index, parts })
|
|
1254
1342
|
: [part.value];
|
|
1343
|
+
if (isVNode(node)) {
|
|
1344
|
+
node[0].key = `${part.type}-${index}`;
|
|
1345
|
+
}
|
|
1346
|
+
return node;
|
|
1255
1347
|
});
|
|
1256
1348
|
}
|
|
1257
1349
|
else if (shared.isString(parts)) {
|
|
1258
1350
|
children = [parts];
|
|
1259
1351
|
}
|
|
1260
1352
|
const assignedAttrs = shared.assign({}, attrs);
|
|
1261
|
-
const tag = shared.isString(props.tag) || shared.isObject(props.tag)
|
|
1353
|
+
const tag = shared.isString(props.tag) || shared.isObject(props.tag)
|
|
1354
|
+
? props.tag
|
|
1355
|
+
: getFragmentableTag();
|
|
1262
1356
|
return vue.h(tag, assignedAttrs, children);
|
|
1263
1357
|
};
|
|
1264
1358
|
}
|
|
1265
1359
|
|
|
1266
|
-
const NUMBER_FORMAT_KEYS = [
|
|
1267
|
-
'localeMatcher',
|
|
1268
|
-
'style',
|
|
1269
|
-
'unit',
|
|
1270
|
-
'unitDisplay',
|
|
1271
|
-
'currency',
|
|
1272
|
-
'currencyDisplay',
|
|
1273
|
-
'useGrouping',
|
|
1274
|
-
'numberingSystem',
|
|
1275
|
-
'minimumIntegerDigits',
|
|
1276
|
-
'minimumFractionDigits',
|
|
1277
|
-
'maximumFractionDigits',
|
|
1278
|
-
'minimumSignificantDigits',
|
|
1279
|
-
'maximumSignificantDigits',
|
|
1280
|
-
'notation',
|
|
1281
|
-
'formatMatcher'
|
|
1282
|
-
];
|
|
1283
1360
|
/**
|
|
1284
1361
|
* Number Format Component
|
|
1285
1362
|
*
|
|
@@ -1297,7 +1374,7 @@ const NUMBER_FORMAT_KEYS = [
|
|
|
1297
1374
|
*
|
|
1298
1375
|
* @VueI18nComponent
|
|
1299
1376
|
*/
|
|
1300
|
-
const NumberFormat =
|
|
1377
|
+
const NumberFormat = /* defineComponent */ {
|
|
1301
1378
|
/* eslint-disable */
|
|
1302
1379
|
name: 'i18n-n',
|
|
1303
1380
|
props: shared.assign({
|
|
@@ -1310,37 +1387,16 @@ const NumberFormat = /* #__PURE__*/ vue.defineComponent({
|
|
|
1310
1387
|
}
|
|
1311
1388
|
}, baseFormatProps),
|
|
1312
1389
|
/* eslint-enable */
|
|
1390
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1313
1391
|
setup(props, context) {
|
|
1314
1392
|
const i18n = props.i18n ||
|
|
1315
|
-
useI18n({ useScope: 'parent' });
|
|
1316
|
-
return renderFormatter(props, context,
|
|
1393
|
+
useI18n({ useScope: 'parent', __useComponent: true });
|
|
1394
|
+
return renderFormatter(props, context, coreBase.NUMBER_FORMAT_OPTIONS_KEYS, (...args) =>
|
|
1317
1395
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1318
1396
|
i18n[NumberPartsSymbol](...args));
|
|
1319
1397
|
}
|
|
1320
|
-
}
|
|
1398
|
+
};
|
|
1321
1399
|
|
|
1322
|
-
const DATETIME_FORMAT_KEYS = [
|
|
1323
|
-
'dateStyle',
|
|
1324
|
-
'timeStyle',
|
|
1325
|
-
'fractionalSecondDigits',
|
|
1326
|
-
'calendar',
|
|
1327
|
-
'dayPeriod',
|
|
1328
|
-
'numberingSystem',
|
|
1329
|
-
'localeMatcher',
|
|
1330
|
-
'timeZone',
|
|
1331
|
-
'hour12',
|
|
1332
|
-
'hourCycle',
|
|
1333
|
-
'formatMatcher',
|
|
1334
|
-
'weekday',
|
|
1335
|
-
'era',
|
|
1336
|
-
'year',
|
|
1337
|
-
'month',
|
|
1338
|
-
'day',
|
|
1339
|
-
'hour',
|
|
1340
|
-
'minute',
|
|
1341
|
-
'second',
|
|
1342
|
-
'timeZoneName'
|
|
1343
|
-
];
|
|
1344
1400
|
/**
|
|
1345
1401
|
* Datetime Format Component
|
|
1346
1402
|
*
|
|
@@ -1358,7 +1414,7 @@ const DATETIME_FORMAT_KEYS = [
|
|
|
1358
1414
|
*
|
|
1359
1415
|
* @VueI18nComponent
|
|
1360
1416
|
*/
|
|
1361
|
-
const DatetimeFormat =
|
|
1417
|
+
const DatetimeFormat = /*defineComponent */ {
|
|
1362
1418
|
/* eslint-disable */
|
|
1363
1419
|
name: 'i18n-d',
|
|
1364
1420
|
props: shared.assign({
|
|
@@ -1371,14 +1427,15 @@ const DatetimeFormat = /* #__PURE__*/ vue.defineComponent({
|
|
|
1371
1427
|
}
|
|
1372
1428
|
}, baseFormatProps),
|
|
1373
1429
|
/* eslint-enable */
|
|
1430
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1374
1431
|
setup(props, context) {
|
|
1375
1432
|
const i18n = props.i18n ||
|
|
1376
|
-
useI18n({ useScope: 'parent' });
|
|
1377
|
-
return renderFormatter(props, context,
|
|
1433
|
+
useI18n({ useScope: 'parent', __useComponent: true });
|
|
1434
|
+
return renderFormatter(props, context, coreBase.DATETIME_FORMAT_OPTIONS_KEYS, (...args) =>
|
|
1378
1435
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1379
1436
|
i18n[DatetimePartsSymbol](...args));
|
|
1380
1437
|
}
|
|
1381
|
-
}
|
|
1438
|
+
};
|
|
1382
1439
|
|
|
1383
1440
|
function getComposer$1(i18n, instance) {
|
|
1384
1441
|
const i18nInternal = i18n;
|
|
@@ -1393,7 +1450,8 @@ function getComposer$1(i18n, instance) {
|
|
|
1393
1450
|
}
|
|
1394
1451
|
}
|
|
1395
1452
|
function vTDirective(i18n) {
|
|
1396
|
-
|
|
1453
|
+
function process(binding) {
|
|
1454
|
+
const { instance, modifiers, value } = binding;
|
|
1397
1455
|
/* istanbul ignore if */
|
|
1398
1456
|
if (!instance || !instance.$) {
|
|
1399
1457
|
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
|
@@ -1403,14 +1461,50 @@ function vTDirective(i18n) {
|
|
|
1403
1461
|
shared.warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE));
|
|
1404
1462
|
}
|
|
1405
1463
|
const parsedValue = parseValue(value);
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
]
|
|
1464
|
+
return [
|
|
1465
|
+
Reflect.apply(composer.t, composer, [...makeParams(parsedValue)]),
|
|
1466
|
+
composer
|
|
1467
|
+
];
|
|
1468
|
+
}
|
|
1469
|
+
const register = (el, binding) => {
|
|
1470
|
+
const [textContent, composer] = process(binding);
|
|
1471
|
+
if (shared.inBrowser && i18n.global === composer) {
|
|
1472
|
+
// global scope only
|
|
1473
|
+
el.__i18nWatcher = vue.watch(composer.locale, () => {
|
|
1474
|
+
binding.instance && binding.instance.$forceUpdate();
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
el.__composer = composer;
|
|
1478
|
+
el.textContent = textContent;
|
|
1479
|
+
};
|
|
1480
|
+
const unregister = (el) => {
|
|
1481
|
+
if (shared.inBrowser && el.__i18nWatcher) {
|
|
1482
|
+
el.__i18nWatcher();
|
|
1483
|
+
el.__i18nWatcher = undefined;
|
|
1484
|
+
delete el.__i18nWatcher;
|
|
1485
|
+
}
|
|
1486
|
+
if (el.__composer) {
|
|
1487
|
+
el.__composer = undefined;
|
|
1488
|
+
delete el.__composer;
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
const update = (el, { value }) => {
|
|
1492
|
+
if (el.__composer) {
|
|
1493
|
+
const composer = el.__composer;
|
|
1494
|
+
const parsedValue = parseValue(value);
|
|
1495
|
+
el.textContent = Reflect.apply(composer.t, composer, [
|
|
1496
|
+
...makeParams(parsedValue)
|
|
1497
|
+
]);
|
|
1498
|
+
}
|
|
1410
1499
|
};
|
|
1411
1500
|
return {
|
|
1412
|
-
|
|
1413
|
-
|
|
1501
|
+
created: register,
|
|
1502
|
+
unmounted: unregister,
|
|
1503
|
+
beforeUpdate: update,
|
|
1504
|
+
getSSRProps: (binding) => {
|
|
1505
|
+
const [textContent] = process(binding);
|
|
1506
|
+
return { textContent };
|
|
1507
|
+
}
|
|
1414
1508
|
};
|
|
1415
1509
|
}
|
|
1416
1510
|
function parseValue(value) {
|
|
@@ -1491,6 +1585,7 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1491
1585
|
this.$i18n = mergeToRoot(vuei18n, optionsI18n);
|
|
1492
1586
|
}
|
|
1493
1587
|
else {
|
|
1588
|
+
optionsI18n.__injectWithOption = true;
|
|
1494
1589
|
this.$i18n = createVueI18n(optionsI18n);
|
|
1495
1590
|
}
|
|
1496
1591
|
}
|
|
@@ -1501,6 +1596,7 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1501
1596
|
else {
|
|
1502
1597
|
this.$i18n = createVueI18n({
|
|
1503
1598
|
__i18n: options.__i18n,
|
|
1599
|
+
__injectWithOption: true,
|
|
1504
1600
|
__root: composer
|
|
1505
1601
|
});
|
|
1506
1602
|
}
|
|
@@ -1509,6 +1605,9 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1509
1605
|
// set global
|
|
1510
1606
|
this.$i18n = vuei18n;
|
|
1511
1607
|
}
|
|
1608
|
+
if (options.__i18nGlobal) {
|
|
1609
|
+
adjustI18nResources(composer, options, options);
|
|
1610
|
+
}
|
|
1512
1611
|
vuei18n.__onComponentInstanceCreated(this.$i18n);
|
|
1513
1612
|
i18n.__setInstance(instance, this.$i18n);
|
|
1514
1613
|
// defines vue-i18n legacy APIs
|
|
@@ -1528,17 +1627,15 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1528
1627
|
if (!instance) {
|
|
1529
1628
|
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
|
1530
1629
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
delete this.$i18n;
|
|
1541
|
-
});
|
|
1630
|
+
delete this.$t;
|
|
1631
|
+
delete this.$rt;
|
|
1632
|
+
delete this.$tc;
|
|
1633
|
+
delete this.$te;
|
|
1634
|
+
delete this.$d;
|
|
1635
|
+
delete this.$n;
|
|
1636
|
+
delete this.$tm;
|
|
1637
|
+
i18n.__deleteInstance(instance);
|
|
1638
|
+
delete this.$i18n;
|
|
1542
1639
|
}
|
|
1543
1640
|
};
|
|
1544
1641
|
}
|
|
@@ -1589,9 +1686,16 @@ function createI18n(options = {}, VueI18nLegacy) {
|
|
|
1589
1686
|
const __legacyMode = shared.isBoolean(options.legacy)
|
|
1590
1687
|
? options.legacy
|
|
1591
1688
|
: true;
|
|
1592
|
-
|
|
1689
|
+
// prettier-ignore
|
|
1690
|
+
const __globalInjection = shared.isBoolean(options.globalInjection)
|
|
1691
|
+
? options.globalInjection
|
|
1692
|
+
: true;
|
|
1693
|
+
// prettier-ignore
|
|
1694
|
+
const __allowComposition = __legacyMode
|
|
1695
|
+
? !!options.allowComposition
|
|
1696
|
+
: true;
|
|
1593
1697
|
const __instances = new Map();
|
|
1594
|
-
const __global = createGlobal(options, __legacyMode);
|
|
1698
|
+
const [globalScope, __global] = createGlobal(options, __legacyMode);
|
|
1595
1699
|
const symbol = shared.makeSymbol('vue-i18n' );
|
|
1596
1700
|
function __getInstance(component) {
|
|
1597
1701
|
return __instances.get(component) || null;
|
|
@@ -1610,13 +1714,15 @@ function createI18n(options = {}, VueI18nLegacy) {
|
|
|
1610
1714
|
? 'legacy'
|
|
1611
1715
|
: 'composition';
|
|
1612
1716
|
},
|
|
1717
|
+
// allowComposition
|
|
1718
|
+
get allowComposition() {
|
|
1719
|
+
return __allowComposition;
|
|
1720
|
+
},
|
|
1613
1721
|
// install plugin
|
|
1614
1722
|
async install(app, ...options) {
|
|
1615
1723
|
// setup global provider
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
app.provide(app.__VUE_I18N_SYMBOL__, i18n);
|
|
1619
|
-
}
|
|
1724
|
+
app.__VUE_I18N_SYMBOL__ = symbol;
|
|
1725
|
+
app.provide(app.__VUE_I18N_SYMBOL__, i18n);
|
|
1620
1726
|
// global method and properties injection for Composition API
|
|
1621
1727
|
if (!__legacyMode && __globalInjection) {
|
|
1622
1728
|
injectGlobalFields(app, i18n.global);
|
|
@@ -1629,11 +1735,20 @@ function createI18n(options = {}, VueI18nLegacy) {
|
|
|
1629
1735
|
if (__legacyMode) {
|
|
1630
1736
|
app.mixin(defineMixin(__global, __global.__composer, i18n));
|
|
1631
1737
|
}
|
|
1738
|
+
// release global scope
|
|
1739
|
+
const unmountApp = app.unmount;
|
|
1740
|
+
app.unmount = () => {
|
|
1741
|
+
i18n.dispose();
|
|
1742
|
+
unmountApp();
|
|
1743
|
+
};
|
|
1632
1744
|
},
|
|
1633
1745
|
// global accessor
|
|
1634
1746
|
get global() {
|
|
1635
1747
|
return __global;
|
|
1636
1748
|
},
|
|
1749
|
+
dispose() {
|
|
1750
|
+
globalScope.stop();
|
|
1751
|
+
},
|
|
1637
1752
|
// @internal
|
|
1638
1753
|
__instances,
|
|
1639
1754
|
// @internal
|
|
@@ -1661,12 +1776,22 @@ function useI18n(options = {}) {
|
|
|
1661
1776
|
const global = getGlobalComposer(i18n);
|
|
1662
1777
|
const componentOptions = getComponentOptions(instance);
|
|
1663
1778
|
const scope = getScope(options, componentOptions);
|
|
1779
|
+
{
|
|
1780
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1781
|
+
if (i18n.mode === 'legacy' && !options.__useComponent) {
|
|
1782
|
+
if (!i18n.allowComposition) {
|
|
1783
|
+
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE);
|
|
1784
|
+
}
|
|
1785
|
+
return useI18nForLegacy(instance, scope, global, options);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1664
1788
|
if (scope === 'global') {
|
|
1665
1789
|
adjustI18nResources(global, options, componentOptions);
|
|
1666
1790
|
return global;
|
|
1667
1791
|
}
|
|
1668
1792
|
if (scope === 'parent') {
|
|
1669
|
-
|
|
1793
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1794
|
+
let composer = getComposer(i18n, instance, options.__useComponent);
|
|
1670
1795
|
if (composer == null) {
|
|
1671
1796
|
{
|
|
1672
1797
|
shared.warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
|
|
@@ -1675,10 +1800,6 @@ function useI18n(options = {}) {
|
|
|
1675
1800
|
}
|
|
1676
1801
|
return composer;
|
|
1677
1802
|
}
|
|
1678
|
-
// scope 'local' case
|
|
1679
|
-
if (i18n.mode === 'legacy') {
|
|
1680
|
-
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE);
|
|
1681
|
-
}
|
|
1682
1803
|
const i18nInternal = i18n;
|
|
1683
1804
|
let composer = i18nInternal.__getInstance(instance);
|
|
1684
1805
|
if (composer == null) {
|
|
@@ -1695,12 +1816,41 @@ function useI18n(options = {}) {
|
|
|
1695
1816
|
}
|
|
1696
1817
|
return composer;
|
|
1697
1818
|
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Cast to VueI18n legacy compatible type
|
|
1821
|
+
*
|
|
1822
|
+
* @remarks
|
|
1823
|
+
* This API is provided only with [vue-i18n-bridge](https://vue-i18n.intlify.dev/guide/migration/ways.html#what-is-vue-i18n-bridge).
|
|
1824
|
+
*
|
|
1825
|
+
* The purpose of this function is to convert an {@link I18n} instance created with {@link createI18n | createI18n(legacy: true)} into a `vue-i18n@v8.x` compatible instance of `new VueI18n` in a TypeScript environment.
|
|
1826
|
+
*
|
|
1827
|
+
* @param i18n - An instance of {@link I18n}
|
|
1828
|
+
* @returns A i18n instance which is casted to {@link VueI18n} type
|
|
1829
|
+
*
|
|
1830
|
+
* @VueI18nTip
|
|
1831
|
+
* :new: provided by **vue-i18n-bridge only**
|
|
1832
|
+
*
|
|
1833
|
+
* @VueI18nGeneral
|
|
1834
|
+
*/
|
|
1835
|
+
const castToVueI18n = (i18n
|
|
1836
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1837
|
+
) => {
|
|
1838
|
+
if (!(__VUE_I18N_BRIDGE__ in i18n)) {
|
|
1839
|
+
throw createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N);
|
|
1840
|
+
}
|
|
1841
|
+
return i18n;
|
|
1842
|
+
};
|
|
1698
1843
|
function createGlobal(options, legacyMode, VueI18nLegacy // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1699
1844
|
) {
|
|
1845
|
+
const scope = vue.effectScope();
|
|
1700
1846
|
{
|
|
1701
|
-
|
|
1702
|
-
? createVueI18n(options)
|
|
1703
|
-
: createComposer(options);
|
|
1847
|
+
const obj = legacyMode
|
|
1848
|
+
? scope.run(() => createVueI18n(options))
|
|
1849
|
+
: scope.run(() => createComposer(options));
|
|
1850
|
+
if (obj == null) {
|
|
1851
|
+
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
|
1852
|
+
}
|
|
1853
|
+
return [scope, obj];
|
|
1704
1854
|
}
|
|
1705
1855
|
}
|
|
1706
1856
|
function getI18nInstance(instance) {
|
|
@@ -1735,44 +1885,7 @@ function getGlobalComposer(i18n) {
|
|
|
1735
1885
|
: i18n.global.__composer
|
|
1736
1886
|
;
|
|
1737
1887
|
}
|
|
1738
|
-
function
|
|
1739
|
-
) {
|
|
1740
|
-
let messages = shared.isObject(options.messages) ? options.messages : {};
|
|
1741
|
-
if ('__i18nGlobal' in componentOptions) {
|
|
1742
|
-
messages = getLocaleMessages(global.locale.value, {
|
|
1743
|
-
messages,
|
|
1744
|
-
__i18n: componentOptions.__i18nGlobal
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
// merge locale messages
|
|
1748
|
-
const locales = Object.keys(messages);
|
|
1749
|
-
if (locales.length) {
|
|
1750
|
-
locales.forEach(locale => {
|
|
1751
|
-
global.mergeLocaleMessage(locale, messages[locale]);
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
|
-
{
|
|
1755
|
-
// merge datetime formats
|
|
1756
|
-
if (shared.isObject(options.datetimeFormats)) {
|
|
1757
|
-
const locales = Object.keys(options.datetimeFormats);
|
|
1758
|
-
if (locales.length) {
|
|
1759
|
-
locales.forEach(locale => {
|
|
1760
|
-
global.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
|
|
1761
|
-
});
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
// merge number formats
|
|
1765
|
-
if (shared.isObject(options.numberFormats)) {
|
|
1766
|
-
const locales = Object.keys(options.numberFormats);
|
|
1767
|
-
if (locales.length) {
|
|
1768
|
-
locales.forEach(locale => {
|
|
1769
|
-
global.mergeNumberFormat(locale, options.numberFormats[locale]);
|
|
1770
|
-
});
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
function getComposer(i18n, target) {
|
|
1888
|
+
function getComposer(i18n, target, useComponent = false) {
|
|
1776
1889
|
let composer = null;
|
|
1777
1890
|
const root = target.root;
|
|
1778
1891
|
let current = target.parent;
|
|
@@ -1787,6 +1900,12 @@ function getComposer(i18n, target) {
|
|
|
1787
1900
|
if (vueI18n != null) {
|
|
1788
1901
|
composer = vueI18n
|
|
1789
1902
|
.__composer;
|
|
1903
|
+
if (useComponent &&
|
|
1904
|
+
composer &&
|
|
1905
|
+
!composer[InejctWithOption] // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1906
|
+
) {
|
|
1907
|
+
composer = null;
|
|
1908
|
+
}
|
|
1790
1909
|
}
|
|
1791
1910
|
}
|
|
1792
1911
|
}
|
|
@@ -1809,6 +1928,366 @@ function setupLifeCycle(i18n, target, composer) {
|
|
|
1809
1928
|
}, target);
|
|
1810
1929
|
}
|
|
1811
1930
|
}
|
|
1931
|
+
function useI18nForLegacy(instance, scope, root, options = {} // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1932
|
+
) {
|
|
1933
|
+
const isLocale = scope === 'local';
|
|
1934
|
+
const _composer = vue.shallowRef(null);
|
|
1935
|
+
if (isLocale &&
|
|
1936
|
+
instance.proxy &&
|
|
1937
|
+
!(instance.proxy.$options.i18n || instance.proxy.$options.__i18n)) {
|
|
1938
|
+
throw createI18nError(I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION);
|
|
1939
|
+
}
|
|
1940
|
+
const _inheritLocale = shared.isBoolean(options.inheritLocale)
|
|
1941
|
+
? options.inheritLocale
|
|
1942
|
+
: true;
|
|
1943
|
+
const _locale = vue.ref(
|
|
1944
|
+
// prettier-ignore
|
|
1945
|
+
isLocale && _inheritLocale
|
|
1946
|
+
? root.locale.value
|
|
1947
|
+
: shared.isString(options.locale)
|
|
1948
|
+
? options.locale
|
|
1949
|
+
: coreBase.DEFAULT_LOCALE);
|
|
1950
|
+
const _fallbackLocale = vue.ref(
|
|
1951
|
+
// prettier-ignore
|
|
1952
|
+
isLocale && _inheritLocale
|
|
1953
|
+
? root.fallbackLocale.value
|
|
1954
|
+
: shared.isString(options.fallbackLocale) ||
|
|
1955
|
+
shared.isArray(options.fallbackLocale) ||
|
|
1956
|
+
shared.isPlainObject(options.fallbackLocale) ||
|
|
1957
|
+
options.fallbackLocale === false
|
|
1958
|
+
? options.fallbackLocale
|
|
1959
|
+
: _locale.value);
|
|
1960
|
+
const _messages = vue.ref(getLocaleMessages(_locale.value, options));
|
|
1961
|
+
// prettier-ignore
|
|
1962
|
+
const _datetimeFormats = vue.ref(shared.isPlainObject(options.datetimeFormats)
|
|
1963
|
+
? options.datetimeFormats
|
|
1964
|
+
: { [_locale.value]: {} });
|
|
1965
|
+
// prettier-ignore
|
|
1966
|
+
const _numberFormats = vue.ref(shared.isPlainObject(options.numberFormats)
|
|
1967
|
+
? options.numberFormats
|
|
1968
|
+
: { [_locale.value]: {} });
|
|
1969
|
+
// prettier-ignore
|
|
1970
|
+
const _missingWarn = isLocale
|
|
1971
|
+
? root.missingWarn
|
|
1972
|
+
: shared.isBoolean(options.missingWarn) || shared.isRegExp(options.missingWarn)
|
|
1973
|
+
? options.missingWarn
|
|
1974
|
+
: true;
|
|
1975
|
+
// prettier-ignore
|
|
1976
|
+
const _fallbackWarn = isLocale
|
|
1977
|
+
? root.fallbackWarn
|
|
1978
|
+
: shared.isBoolean(options.fallbackWarn) || shared.isRegExp(options.fallbackWarn)
|
|
1979
|
+
? options.fallbackWarn
|
|
1980
|
+
: true;
|
|
1981
|
+
// prettier-ignore
|
|
1982
|
+
const _fallbackRoot = isLocale
|
|
1983
|
+
? root.fallbackRoot
|
|
1984
|
+
: shared.isBoolean(options.fallbackRoot)
|
|
1985
|
+
? options.fallbackRoot
|
|
1986
|
+
: true;
|
|
1987
|
+
// configure fall back to root
|
|
1988
|
+
const _fallbackFormat = !!options.fallbackFormat;
|
|
1989
|
+
// runtime missing
|
|
1990
|
+
const _missing = shared.isFunction(options.missing) ? options.missing : null;
|
|
1991
|
+
// postTranslation handler
|
|
1992
|
+
const _postTranslation = shared.isFunction(options.postTranslation)
|
|
1993
|
+
? options.postTranslation
|
|
1994
|
+
: null;
|
|
1995
|
+
// prettier-ignore
|
|
1996
|
+
const _warnHtmlMessage = isLocale
|
|
1997
|
+
? root.warnHtmlMessage
|
|
1998
|
+
: shared.isBoolean(options.warnHtmlMessage)
|
|
1999
|
+
? options.warnHtmlMessage
|
|
2000
|
+
: true;
|
|
2001
|
+
const _escapeParameter = !!options.escapeParameter;
|
|
2002
|
+
// prettier-ignore
|
|
2003
|
+
const _modifiers = isLocale
|
|
2004
|
+
? root.modifiers
|
|
2005
|
+
: shared.isPlainObject(options.modifiers)
|
|
2006
|
+
? options.modifiers
|
|
2007
|
+
: {};
|
|
2008
|
+
// pluralRules
|
|
2009
|
+
const _pluralRules = options.pluralRules || (isLocale && root.pluralRules);
|
|
2010
|
+
// track reactivity
|
|
2011
|
+
function trackReactivityValues() {
|
|
2012
|
+
return [
|
|
2013
|
+
_locale.value,
|
|
2014
|
+
_fallbackLocale.value,
|
|
2015
|
+
_messages.value,
|
|
2016
|
+
_datetimeFormats.value,
|
|
2017
|
+
_numberFormats.value
|
|
2018
|
+
];
|
|
2019
|
+
}
|
|
2020
|
+
// locale
|
|
2021
|
+
const locale = vue.computed({
|
|
2022
|
+
get: () => {
|
|
2023
|
+
return _composer.value ? _composer.value.locale.value : _locale.value;
|
|
2024
|
+
},
|
|
2025
|
+
set: val => {
|
|
2026
|
+
if (_composer.value) {
|
|
2027
|
+
_composer.value.locale.value = val;
|
|
2028
|
+
}
|
|
2029
|
+
_locale.value = val;
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
// fallbackLocale
|
|
2033
|
+
const fallbackLocale = vue.computed({
|
|
2034
|
+
get: () => {
|
|
2035
|
+
return _composer.value
|
|
2036
|
+
? _composer.value.fallbackLocale.value
|
|
2037
|
+
: _fallbackLocale.value;
|
|
2038
|
+
},
|
|
2039
|
+
set: val => {
|
|
2040
|
+
if (_composer.value) {
|
|
2041
|
+
_composer.value.fallbackLocale.value = val;
|
|
2042
|
+
}
|
|
2043
|
+
_fallbackLocale.value = val;
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
// messages
|
|
2047
|
+
const messages = vue.computed(() => {
|
|
2048
|
+
if (_composer.value) {
|
|
2049
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2050
|
+
return _composer.value.messages.value;
|
|
2051
|
+
}
|
|
2052
|
+
else {
|
|
2053
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2054
|
+
return _messages.value;
|
|
2055
|
+
}
|
|
2056
|
+
});
|
|
2057
|
+
const datetimeFormats = vue.computed(() => _datetimeFormats.value);
|
|
2058
|
+
const numberFormats = vue.computed(() => _numberFormats.value);
|
|
2059
|
+
function getPostTranslationHandler() {
|
|
2060
|
+
return _composer.value
|
|
2061
|
+
? _composer.value.getPostTranslationHandler()
|
|
2062
|
+
: _postTranslation;
|
|
2063
|
+
}
|
|
2064
|
+
function setPostTranslationHandler(handler) {
|
|
2065
|
+
if (_composer.value) {
|
|
2066
|
+
_composer.value.setPostTranslationHandler(handler);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
function getMissingHandler() {
|
|
2070
|
+
return _composer.value ? _composer.value.getMissingHandler() : _missing;
|
|
2071
|
+
}
|
|
2072
|
+
function setMissingHandler(handler) {
|
|
2073
|
+
if (_composer.value) {
|
|
2074
|
+
_composer.value.setMissingHandler(handler);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
function warpWithDeps(fn) {
|
|
2078
|
+
trackReactivityValues();
|
|
2079
|
+
return fn();
|
|
2080
|
+
}
|
|
2081
|
+
function t(...args) {
|
|
2082
|
+
return _composer.value
|
|
2083
|
+
? warpWithDeps(() => Reflect.apply(_composer.value.t, null, [...args]))
|
|
2084
|
+
: warpWithDeps(() => '');
|
|
2085
|
+
}
|
|
2086
|
+
function rt(...args) {
|
|
2087
|
+
return _composer.value
|
|
2088
|
+
? Reflect.apply(_composer.value.rt, null, [...args])
|
|
2089
|
+
: '';
|
|
2090
|
+
}
|
|
2091
|
+
function d(...args) {
|
|
2092
|
+
return _composer.value
|
|
2093
|
+
? warpWithDeps(() => Reflect.apply(_composer.value.d, null, [...args]))
|
|
2094
|
+
: warpWithDeps(() => '');
|
|
2095
|
+
}
|
|
2096
|
+
function n(...args) {
|
|
2097
|
+
return _composer.value
|
|
2098
|
+
? warpWithDeps(() => Reflect.apply(_composer.value.n, null, [...args]))
|
|
2099
|
+
: warpWithDeps(() => '');
|
|
2100
|
+
}
|
|
2101
|
+
function tm(key) {
|
|
2102
|
+
return _composer.value ? _composer.value.tm(key) : {};
|
|
2103
|
+
}
|
|
2104
|
+
function te(key, locale) {
|
|
2105
|
+
return _composer.value ? _composer.value.te(key, locale) : false;
|
|
2106
|
+
}
|
|
2107
|
+
function getLocaleMessage(locale) {
|
|
2108
|
+
return _composer.value ? _composer.value.getLocaleMessage(locale) : {};
|
|
2109
|
+
}
|
|
2110
|
+
function setLocaleMessage(locale, message) {
|
|
2111
|
+
if (_composer.value) {
|
|
2112
|
+
_composer.value.setLocaleMessage(locale, message);
|
|
2113
|
+
_messages.value[locale] = message;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
function mergeLocaleMessage(locale, message) {
|
|
2117
|
+
if (_composer.value) {
|
|
2118
|
+
_composer.value.mergeLocaleMessage(locale, message);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
function getDateTimeFormat(locale) {
|
|
2122
|
+
return _composer.value ? _composer.value.getDateTimeFormat(locale) : {};
|
|
2123
|
+
}
|
|
2124
|
+
function setDateTimeFormat(locale, format) {
|
|
2125
|
+
if (_composer.value) {
|
|
2126
|
+
_composer.value.setDateTimeFormat(locale, format);
|
|
2127
|
+
_datetimeFormats.value[locale] = format;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
function mergeDateTimeFormat(locale, format) {
|
|
2131
|
+
if (_composer.value) {
|
|
2132
|
+
_composer.value.mergeDateTimeFormat(locale, format);
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
function getNumberFormat(locale) {
|
|
2136
|
+
return _composer.value ? _composer.value.getNumberFormat(locale) : {};
|
|
2137
|
+
}
|
|
2138
|
+
function setNumberFormat(locale, format) {
|
|
2139
|
+
if (_composer.value) {
|
|
2140
|
+
_composer.value.setNumberFormat(locale, format);
|
|
2141
|
+
_numberFormats.value[locale] = format;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
function mergeNumberFormat(locale, format) {
|
|
2145
|
+
if (_composer.value) {
|
|
2146
|
+
_composer.value.mergeNumberFormat(locale, format);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
const wrapper = {
|
|
2150
|
+
get id() {
|
|
2151
|
+
return _composer.value ? _composer.value.id : -1;
|
|
2152
|
+
},
|
|
2153
|
+
locale,
|
|
2154
|
+
fallbackLocale,
|
|
2155
|
+
messages,
|
|
2156
|
+
datetimeFormats,
|
|
2157
|
+
numberFormats,
|
|
2158
|
+
get inheritLocale() {
|
|
2159
|
+
return _composer.value ? _composer.value.inheritLocale : _inheritLocale;
|
|
2160
|
+
},
|
|
2161
|
+
set inheritLocale(val) {
|
|
2162
|
+
if (_composer.value) {
|
|
2163
|
+
_composer.value.inheritLocale = val;
|
|
2164
|
+
}
|
|
2165
|
+
},
|
|
2166
|
+
get availableLocales() {
|
|
2167
|
+
return _composer.value
|
|
2168
|
+
? _composer.value.availableLocales
|
|
2169
|
+
: Object.keys(_messages.value);
|
|
2170
|
+
},
|
|
2171
|
+
get modifiers() {
|
|
2172
|
+
return (_composer.value ? _composer.value.modifiers : _modifiers);
|
|
2173
|
+
},
|
|
2174
|
+
get pluralRules() {
|
|
2175
|
+
return (_composer.value ? _composer.value.pluralRules : _pluralRules);
|
|
2176
|
+
},
|
|
2177
|
+
get isGlobal() {
|
|
2178
|
+
return _composer.value ? _composer.value.isGlobal : false;
|
|
2179
|
+
},
|
|
2180
|
+
get missingWarn() {
|
|
2181
|
+
return _composer.value ? _composer.value.missingWarn : _missingWarn;
|
|
2182
|
+
},
|
|
2183
|
+
set missingWarn(val) {
|
|
2184
|
+
if (_composer.value) {
|
|
2185
|
+
_composer.value.missingWarn = val;
|
|
2186
|
+
}
|
|
2187
|
+
},
|
|
2188
|
+
get fallbackWarn() {
|
|
2189
|
+
return _composer.value ? _composer.value.fallbackWarn : _fallbackWarn;
|
|
2190
|
+
},
|
|
2191
|
+
set fallbackWarn(val) {
|
|
2192
|
+
if (_composer.value) {
|
|
2193
|
+
_composer.value.missingWarn = val;
|
|
2194
|
+
}
|
|
2195
|
+
},
|
|
2196
|
+
get fallbackRoot() {
|
|
2197
|
+
return _composer.value ? _composer.value.fallbackRoot : _fallbackRoot;
|
|
2198
|
+
},
|
|
2199
|
+
set fallbackRoot(val) {
|
|
2200
|
+
if (_composer.value) {
|
|
2201
|
+
_composer.value.fallbackRoot = val;
|
|
2202
|
+
}
|
|
2203
|
+
},
|
|
2204
|
+
get fallbackFormat() {
|
|
2205
|
+
return _composer.value ? _composer.value.fallbackFormat : _fallbackFormat;
|
|
2206
|
+
},
|
|
2207
|
+
set fallbackFormat(val) {
|
|
2208
|
+
if (_composer.value) {
|
|
2209
|
+
_composer.value.fallbackFormat = val;
|
|
2210
|
+
}
|
|
2211
|
+
},
|
|
2212
|
+
get warnHtmlMessage() {
|
|
2213
|
+
return _composer.value
|
|
2214
|
+
? _composer.value.warnHtmlMessage
|
|
2215
|
+
: _warnHtmlMessage;
|
|
2216
|
+
},
|
|
2217
|
+
set warnHtmlMessage(val) {
|
|
2218
|
+
if (_composer.value) {
|
|
2219
|
+
_composer.value.warnHtmlMessage = val;
|
|
2220
|
+
}
|
|
2221
|
+
},
|
|
2222
|
+
get escapeParameter() {
|
|
2223
|
+
return _composer.value
|
|
2224
|
+
? _composer.value.escapeParameter
|
|
2225
|
+
: _escapeParameter;
|
|
2226
|
+
},
|
|
2227
|
+
set escapeParameter(val) {
|
|
2228
|
+
if (_composer.value) {
|
|
2229
|
+
_composer.value.escapeParameter = val;
|
|
2230
|
+
}
|
|
2231
|
+
},
|
|
2232
|
+
t,
|
|
2233
|
+
getPostTranslationHandler,
|
|
2234
|
+
setPostTranslationHandler,
|
|
2235
|
+
getMissingHandler,
|
|
2236
|
+
setMissingHandler,
|
|
2237
|
+
rt,
|
|
2238
|
+
d,
|
|
2239
|
+
n,
|
|
2240
|
+
tm,
|
|
2241
|
+
te,
|
|
2242
|
+
getLocaleMessage,
|
|
2243
|
+
setLocaleMessage,
|
|
2244
|
+
mergeLocaleMessage,
|
|
2245
|
+
getDateTimeFormat,
|
|
2246
|
+
setDateTimeFormat,
|
|
2247
|
+
mergeDateTimeFormat,
|
|
2248
|
+
getNumberFormat,
|
|
2249
|
+
setNumberFormat,
|
|
2250
|
+
mergeNumberFormat
|
|
2251
|
+
};
|
|
2252
|
+
function sync(composer) {
|
|
2253
|
+
composer.locale.value = _locale.value;
|
|
2254
|
+
composer.fallbackLocale.value = _fallbackLocale.value;
|
|
2255
|
+
Object.keys(_messages.value).forEach(locale => {
|
|
2256
|
+
composer.mergeLocaleMessage(locale, _messages.value[locale]);
|
|
2257
|
+
});
|
|
2258
|
+
Object.keys(_datetimeFormats.value).forEach(locale => {
|
|
2259
|
+
composer.mergeDateTimeFormat(locale, _datetimeFormats.value[locale]);
|
|
2260
|
+
});
|
|
2261
|
+
Object.keys(_numberFormats.value).forEach(locale => {
|
|
2262
|
+
composer.mergeNumberFormat(locale, _numberFormats.value[locale]);
|
|
2263
|
+
});
|
|
2264
|
+
composer.escapeParameter = _escapeParameter;
|
|
2265
|
+
composer.fallbackFormat = _fallbackFormat;
|
|
2266
|
+
composer.fallbackRoot = _fallbackRoot;
|
|
2267
|
+
composer.fallbackWarn = _fallbackWarn;
|
|
2268
|
+
composer.missingWarn = _missingWarn;
|
|
2269
|
+
composer.warnHtmlMessage = _warnHtmlMessage;
|
|
2270
|
+
}
|
|
2271
|
+
vue.onBeforeMount(() => {
|
|
2272
|
+
if (instance.proxy == null || instance.proxy.$i18n == null) {
|
|
2273
|
+
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY);
|
|
2274
|
+
}
|
|
2275
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2276
|
+
const composer = (_composer.value = instance.proxy.$i18n
|
|
2277
|
+
.__composer);
|
|
2278
|
+
if (scope === 'global') {
|
|
2279
|
+
_locale.value = composer.locale.value;
|
|
2280
|
+
_fallbackLocale.value = composer.fallbackLocale.value;
|
|
2281
|
+
_messages.value = composer.messages.value;
|
|
2282
|
+
_datetimeFormats.value = composer.datetimeFormats.value;
|
|
2283
|
+
_numberFormats.value = composer.numberFormats.value;
|
|
2284
|
+
}
|
|
2285
|
+
else if (isLocale) {
|
|
2286
|
+
sync(composer);
|
|
2287
|
+
}
|
|
2288
|
+
});
|
|
2289
|
+
return wrapper;
|
|
2290
|
+
}
|
|
1812
2291
|
const globalExportProps = [
|
|
1813
2292
|
'locale',
|
|
1814
2293
|
'fallbackLocale',
|
|
@@ -1867,6 +2346,7 @@ exports.I18nInjectionKey = I18nInjectionKey;
|
|
|
1867
2346
|
exports.NumberFormat = NumberFormat;
|
|
1868
2347
|
exports.Translation = Translation;
|
|
1869
2348
|
exports.VERSION = VERSION;
|
|
2349
|
+
exports.castToVueI18n = castToVueI18n;
|
|
1870
2350
|
exports.createI18n = createI18n;
|
|
1871
2351
|
exports.useI18n = useI18n;
|
|
1872
2352
|
exports.vTDirective = vTDirective;
|