vue-i18n 9.2.0-beta.9 → 9.2.2
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 +651 -170
- package/dist/vue-i18n.cjs.prod.js +636 -164
- package/dist/vue-i18n.d.ts +266 -316
- package/dist/vue-i18n.esm-browser.js +1005 -230
- package/dist/vue-i18n.esm-browser.prod.js +3 -3
- package/dist/vue-i18n.esm-bundler.js +672 -186
- package/dist/vue-i18n.global.js +1005 -229
- package/dist/vue-i18n.global.prod.js +3 -3
- package/dist/vue-i18n.runtime.esm-browser.js +967 -213
- package/dist/vue-i18n.runtime.esm-browser.prod.js +3 -3
- package/dist/vue-i18n.runtime.esm-bundler.js +672 -186
- package/dist/vue-i18n.runtime.global.js +967 -212
- 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.
|
|
3
|
-
* (c)
|
|
2
|
+
* vue-i18n v9.2.2
|
|
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.
|
|
22
|
+
const VERSION = '9.2.2';
|
|
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
|
|
@@ -310,7 +361,8 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
310
361
|
// runtime context
|
|
311
362
|
// eslint-disable-next-line prefer-const
|
|
312
363
|
let _context;
|
|
313
|
-
|
|
364
|
+
const getCoreContext = () => {
|
|
365
|
+
_isGlobal && coreBase.setFallbackContext(null);
|
|
314
366
|
const ctxOptions = {
|
|
315
367
|
version: VERSION,
|
|
316
368
|
locale: _locale.value,
|
|
@@ -344,8 +396,10 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
344
396
|
? _context.__v_emitter
|
|
345
397
|
: undefined;
|
|
346
398
|
}
|
|
347
|
-
|
|
348
|
-
|
|
399
|
+
const ctx = coreBase.createCoreContext(ctxOptions);
|
|
400
|
+
_isGlobal && coreBase.setFallbackContext(ctx);
|
|
401
|
+
return ctx;
|
|
402
|
+
};
|
|
349
403
|
_context = getCoreContext();
|
|
350
404
|
coreBase.updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
|
351
405
|
// track reactivity
|
|
@@ -407,17 +461,25 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
407
461
|
) {
|
|
408
462
|
return type !== 'translate' || !arg.resolvedMessage;
|
|
409
463
|
}
|
|
410
|
-
|
|
464
|
+
const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => {
|
|
411
465
|
trackReactivityValues(); // track reactive dependency
|
|
412
466
|
// NOTE: experimental !!
|
|
413
467
|
let ret;
|
|
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) {
|
|
@@ -457,7 +519,7 @@ function createComposer(options = {}, VueI18nLegacy) {
|
|
|
457
519
|
/* istanbul ignore next */
|
|
458
520
|
throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
|
|
459
521
|
}
|
|
460
|
-
}
|
|
522
|
+
};
|
|
461
523
|
// t
|
|
462
524
|
function t(...args) {
|
|
463
525
|
return wrapWithDeps(context => Reflect.apply(coreBase.translate, null, [context, ...args]), () => coreBase.parseTranslateArgs(...args), 'translate', root => Reflect.apply(root.t, root, [...args]), key => key, val => shared.isString(val));
|
|
@@ -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
|
-
const
|
|
1453
|
+
const _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,51 @@ 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
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
const getSSRProps = (binding) => {
|
|
1501
|
+
const [textContent] = _process(binding);
|
|
1502
|
+
return { textContent };
|
|
1410
1503
|
};
|
|
1411
1504
|
return {
|
|
1412
|
-
|
|
1413
|
-
|
|
1505
|
+
created: register,
|
|
1506
|
+
unmounted: unregister,
|
|
1507
|
+
beforeUpdate: update,
|
|
1508
|
+
getSSRProps
|
|
1414
1509
|
};
|
|
1415
1510
|
}
|
|
1416
1511
|
function parseValue(value) {
|
|
@@ -1491,6 +1586,7 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1491
1586
|
this.$i18n = mergeToRoot(vuei18n, optionsI18n);
|
|
1492
1587
|
}
|
|
1493
1588
|
else {
|
|
1589
|
+
optionsI18n.__injectWithOption = true;
|
|
1494
1590
|
this.$i18n = createVueI18n(optionsI18n);
|
|
1495
1591
|
}
|
|
1496
1592
|
}
|
|
@@ -1501,6 +1597,7 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1501
1597
|
else {
|
|
1502
1598
|
this.$i18n = createVueI18n({
|
|
1503
1599
|
__i18n: options.__i18n,
|
|
1600
|
+
__injectWithOption: true,
|
|
1504
1601
|
__root: composer
|
|
1505
1602
|
});
|
|
1506
1603
|
}
|
|
@@ -1509,6 +1606,9 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1509
1606
|
// set global
|
|
1510
1607
|
this.$i18n = vuei18n;
|
|
1511
1608
|
}
|
|
1609
|
+
if (options.__i18nGlobal) {
|
|
1610
|
+
adjustI18nResources(composer, options, options);
|
|
1611
|
+
}
|
|
1512
1612
|
vuei18n.__onComponentInstanceCreated(this.$i18n);
|
|
1513
1613
|
i18n.__setInstance(instance, this.$i18n);
|
|
1514
1614
|
// defines vue-i18n legacy APIs
|
|
@@ -1528,17 +1628,15 @@ function defineMixin(vuei18n, composer, i18n) {
|
|
|
1528
1628
|
if (!instance) {
|
|
1529
1629
|
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
|
1530
1630
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
delete this.$i18n;
|
|
1541
|
-
});
|
|
1631
|
+
delete this.$t;
|
|
1632
|
+
delete this.$rt;
|
|
1633
|
+
delete this.$tc;
|
|
1634
|
+
delete this.$te;
|
|
1635
|
+
delete this.$d;
|
|
1636
|
+
delete this.$n;
|
|
1637
|
+
delete this.$tm;
|
|
1638
|
+
i18n.__deleteInstance(instance);
|
|
1639
|
+
delete this.$i18n;
|
|
1542
1640
|
}
|
|
1543
1641
|
};
|
|
1544
1642
|
}
|
|
@@ -1589,9 +1687,16 @@ function createI18n(options = {}, VueI18nLegacy) {
|
|
|
1589
1687
|
const __legacyMode = shared.isBoolean(options.legacy)
|
|
1590
1688
|
? options.legacy
|
|
1591
1689
|
: true;
|
|
1592
|
-
|
|
1690
|
+
// prettier-ignore
|
|
1691
|
+
const __globalInjection = shared.isBoolean(options.globalInjection)
|
|
1692
|
+
? options.globalInjection
|
|
1693
|
+
: true;
|
|
1694
|
+
// prettier-ignore
|
|
1695
|
+
const __allowComposition = __legacyMode
|
|
1696
|
+
? !!options.allowComposition
|
|
1697
|
+
: true;
|
|
1593
1698
|
const __instances = new Map();
|
|
1594
|
-
const __global = createGlobal(options, __legacyMode);
|
|
1699
|
+
const [globalScope, __global] = createGlobal(options, __legacyMode);
|
|
1595
1700
|
const symbol = shared.makeSymbol('vue-i18n' );
|
|
1596
1701
|
function __getInstance(component) {
|
|
1597
1702
|
return __instances.get(component) || null;
|
|
@@ -1610,13 +1715,15 @@ function createI18n(options = {}, VueI18nLegacy) {
|
|
|
1610
1715
|
? 'legacy'
|
|
1611
1716
|
: 'composition';
|
|
1612
1717
|
},
|
|
1718
|
+
// allowComposition
|
|
1719
|
+
get allowComposition() {
|
|
1720
|
+
return __allowComposition;
|
|
1721
|
+
},
|
|
1613
1722
|
// install plugin
|
|
1614
1723
|
async install(app, ...options) {
|
|
1615
1724
|
// setup global provider
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
app.provide(app.__VUE_I18N_SYMBOL__, i18n);
|
|
1619
|
-
}
|
|
1725
|
+
app.__VUE_I18N_SYMBOL__ = symbol;
|
|
1726
|
+
app.provide(app.__VUE_I18N_SYMBOL__, i18n);
|
|
1620
1727
|
// global method and properties injection for Composition API
|
|
1621
1728
|
if (!__legacyMode && __globalInjection) {
|
|
1622
1729
|
injectGlobalFields(app, i18n.global);
|
|
@@ -1629,11 +1736,20 @@ function createI18n(options = {}, VueI18nLegacy) {
|
|
|
1629
1736
|
if (__legacyMode) {
|
|
1630
1737
|
app.mixin(defineMixin(__global, __global.__composer, i18n));
|
|
1631
1738
|
}
|
|
1739
|
+
// release global scope
|
|
1740
|
+
const unmountApp = app.unmount;
|
|
1741
|
+
app.unmount = () => {
|
|
1742
|
+
i18n.dispose();
|
|
1743
|
+
unmountApp();
|
|
1744
|
+
};
|
|
1632
1745
|
},
|
|
1633
1746
|
// global accessor
|
|
1634
1747
|
get global() {
|
|
1635
1748
|
return __global;
|
|
1636
1749
|
},
|
|
1750
|
+
dispose() {
|
|
1751
|
+
globalScope.stop();
|
|
1752
|
+
},
|
|
1637
1753
|
// @internal
|
|
1638
1754
|
__instances,
|
|
1639
1755
|
// @internal
|
|
@@ -1661,12 +1777,22 @@ function useI18n(options = {}) {
|
|
|
1661
1777
|
const global = getGlobalComposer(i18n);
|
|
1662
1778
|
const componentOptions = getComponentOptions(instance);
|
|
1663
1779
|
const scope = getScope(options, componentOptions);
|
|
1780
|
+
{
|
|
1781
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1782
|
+
if (i18n.mode === 'legacy' && !options.__useComponent) {
|
|
1783
|
+
if (!i18n.allowComposition) {
|
|
1784
|
+
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE);
|
|
1785
|
+
}
|
|
1786
|
+
return useI18nForLegacy(instance, scope, global, options);
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1664
1789
|
if (scope === 'global') {
|
|
1665
1790
|
adjustI18nResources(global, options, componentOptions);
|
|
1666
1791
|
return global;
|
|
1667
1792
|
}
|
|
1668
1793
|
if (scope === 'parent') {
|
|
1669
|
-
|
|
1794
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1795
|
+
let composer = getComposer(i18n, instance, options.__useComponent);
|
|
1670
1796
|
if (composer == null) {
|
|
1671
1797
|
{
|
|
1672
1798
|
shared.warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
|
|
@@ -1675,10 +1801,6 @@ function useI18n(options = {}) {
|
|
|
1675
1801
|
}
|
|
1676
1802
|
return composer;
|
|
1677
1803
|
}
|
|
1678
|
-
// scope 'local' case
|
|
1679
|
-
if (i18n.mode === 'legacy') {
|
|
1680
|
-
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE);
|
|
1681
|
-
}
|
|
1682
1804
|
const i18nInternal = i18n;
|
|
1683
1805
|
let composer = i18nInternal.__getInstance(instance);
|
|
1684
1806
|
if (composer == null) {
|
|
@@ -1695,12 +1817,41 @@ function useI18n(options = {}) {
|
|
|
1695
1817
|
}
|
|
1696
1818
|
return composer;
|
|
1697
1819
|
}
|
|
1820
|
+
/**
|
|
1821
|
+
* Cast to VueI18n legacy compatible type
|
|
1822
|
+
*
|
|
1823
|
+
* @remarks
|
|
1824
|
+
* This API is provided only with [vue-i18n-bridge](https://vue-i18n.intlify.dev/guide/migration/ways.html#what-is-vue-i18n-bridge).
|
|
1825
|
+
*
|
|
1826
|
+
* 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.
|
|
1827
|
+
*
|
|
1828
|
+
* @param i18n - An instance of {@link I18n}
|
|
1829
|
+
* @returns A i18n instance which is casted to {@link VueI18n} type
|
|
1830
|
+
*
|
|
1831
|
+
* @VueI18nTip
|
|
1832
|
+
* :new: provided by **vue-i18n-bridge only**
|
|
1833
|
+
*
|
|
1834
|
+
* @VueI18nGeneral
|
|
1835
|
+
*/
|
|
1836
|
+
const castToVueI18n = (i18n
|
|
1837
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1838
|
+
) => {
|
|
1839
|
+
if (!(__VUE_I18N_BRIDGE__ in i18n)) {
|
|
1840
|
+
throw createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N);
|
|
1841
|
+
}
|
|
1842
|
+
return i18n;
|
|
1843
|
+
};
|
|
1698
1844
|
function createGlobal(options, legacyMode, VueI18nLegacy // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1699
1845
|
) {
|
|
1846
|
+
const scope = vue.effectScope();
|
|
1700
1847
|
{
|
|
1701
|
-
|
|
1702
|
-
? createVueI18n(options)
|
|
1703
|
-
: createComposer(options);
|
|
1848
|
+
const obj = legacyMode
|
|
1849
|
+
? scope.run(() => createVueI18n(options))
|
|
1850
|
+
: scope.run(() => createComposer(options));
|
|
1851
|
+
if (obj == null) {
|
|
1852
|
+
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
|
1853
|
+
}
|
|
1854
|
+
return [scope, obj];
|
|
1704
1855
|
}
|
|
1705
1856
|
}
|
|
1706
1857
|
function getI18nInstance(instance) {
|
|
@@ -1735,44 +1886,7 @@ function getGlobalComposer(i18n) {
|
|
|
1735
1886
|
: i18n.global.__composer
|
|
1736
1887
|
;
|
|
1737
1888
|
}
|
|
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) {
|
|
1889
|
+
function getComposer(i18n, target, useComponent = false) {
|
|
1776
1890
|
let composer = null;
|
|
1777
1891
|
const root = target.root;
|
|
1778
1892
|
let current = target.parent;
|
|
@@ -1787,6 +1901,12 @@ function getComposer(i18n, target) {
|
|
|
1787
1901
|
if (vueI18n != null) {
|
|
1788
1902
|
composer = vueI18n
|
|
1789
1903
|
.__composer;
|
|
1904
|
+
if (useComponent &&
|
|
1905
|
+
composer &&
|
|
1906
|
+
!composer[InejctWithOption] // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1907
|
+
) {
|
|
1908
|
+
composer = null;
|
|
1909
|
+
}
|
|
1790
1910
|
}
|
|
1791
1911
|
}
|
|
1792
1912
|
}
|
|
@@ -1809,6 +1929,366 @@ function setupLifeCycle(i18n, target, composer) {
|
|
|
1809
1929
|
}, target);
|
|
1810
1930
|
}
|
|
1811
1931
|
}
|
|
1932
|
+
function useI18nForLegacy(instance, scope, root, options = {} // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1933
|
+
) {
|
|
1934
|
+
const isLocale = scope === 'local';
|
|
1935
|
+
const _composer = vue.shallowRef(null);
|
|
1936
|
+
if (isLocale &&
|
|
1937
|
+
instance.proxy &&
|
|
1938
|
+
!(instance.proxy.$options.i18n || instance.proxy.$options.__i18n)) {
|
|
1939
|
+
throw createI18nError(I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION);
|
|
1940
|
+
}
|
|
1941
|
+
const _inheritLocale = shared.isBoolean(options.inheritLocale)
|
|
1942
|
+
? options.inheritLocale
|
|
1943
|
+
: true;
|
|
1944
|
+
const _locale = vue.ref(
|
|
1945
|
+
// prettier-ignore
|
|
1946
|
+
isLocale && _inheritLocale
|
|
1947
|
+
? root.locale.value
|
|
1948
|
+
: shared.isString(options.locale)
|
|
1949
|
+
? options.locale
|
|
1950
|
+
: coreBase.DEFAULT_LOCALE);
|
|
1951
|
+
const _fallbackLocale = vue.ref(
|
|
1952
|
+
// prettier-ignore
|
|
1953
|
+
isLocale && _inheritLocale
|
|
1954
|
+
? root.fallbackLocale.value
|
|
1955
|
+
: shared.isString(options.fallbackLocale) ||
|
|
1956
|
+
shared.isArray(options.fallbackLocale) ||
|
|
1957
|
+
shared.isPlainObject(options.fallbackLocale) ||
|
|
1958
|
+
options.fallbackLocale === false
|
|
1959
|
+
? options.fallbackLocale
|
|
1960
|
+
: _locale.value);
|
|
1961
|
+
const _messages = vue.ref(getLocaleMessages(_locale.value, options));
|
|
1962
|
+
// prettier-ignore
|
|
1963
|
+
const _datetimeFormats = vue.ref(shared.isPlainObject(options.datetimeFormats)
|
|
1964
|
+
? options.datetimeFormats
|
|
1965
|
+
: { [_locale.value]: {} });
|
|
1966
|
+
// prettier-ignore
|
|
1967
|
+
const _numberFormats = vue.ref(shared.isPlainObject(options.numberFormats)
|
|
1968
|
+
? options.numberFormats
|
|
1969
|
+
: { [_locale.value]: {} });
|
|
1970
|
+
// prettier-ignore
|
|
1971
|
+
const _missingWarn = isLocale
|
|
1972
|
+
? root.missingWarn
|
|
1973
|
+
: shared.isBoolean(options.missingWarn) || shared.isRegExp(options.missingWarn)
|
|
1974
|
+
? options.missingWarn
|
|
1975
|
+
: true;
|
|
1976
|
+
// prettier-ignore
|
|
1977
|
+
const _fallbackWarn = isLocale
|
|
1978
|
+
? root.fallbackWarn
|
|
1979
|
+
: shared.isBoolean(options.fallbackWarn) || shared.isRegExp(options.fallbackWarn)
|
|
1980
|
+
? options.fallbackWarn
|
|
1981
|
+
: true;
|
|
1982
|
+
// prettier-ignore
|
|
1983
|
+
const _fallbackRoot = isLocale
|
|
1984
|
+
? root.fallbackRoot
|
|
1985
|
+
: shared.isBoolean(options.fallbackRoot)
|
|
1986
|
+
? options.fallbackRoot
|
|
1987
|
+
: true;
|
|
1988
|
+
// configure fall back to root
|
|
1989
|
+
const _fallbackFormat = !!options.fallbackFormat;
|
|
1990
|
+
// runtime missing
|
|
1991
|
+
const _missing = shared.isFunction(options.missing) ? options.missing : null;
|
|
1992
|
+
// postTranslation handler
|
|
1993
|
+
const _postTranslation = shared.isFunction(options.postTranslation)
|
|
1994
|
+
? options.postTranslation
|
|
1995
|
+
: null;
|
|
1996
|
+
// prettier-ignore
|
|
1997
|
+
const _warnHtmlMessage = isLocale
|
|
1998
|
+
? root.warnHtmlMessage
|
|
1999
|
+
: shared.isBoolean(options.warnHtmlMessage)
|
|
2000
|
+
? options.warnHtmlMessage
|
|
2001
|
+
: true;
|
|
2002
|
+
const _escapeParameter = !!options.escapeParameter;
|
|
2003
|
+
// prettier-ignore
|
|
2004
|
+
const _modifiers = isLocale
|
|
2005
|
+
? root.modifiers
|
|
2006
|
+
: shared.isPlainObject(options.modifiers)
|
|
2007
|
+
? options.modifiers
|
|
2008
|
+
: {};
|
|
2009
|
+
// pluralRules
|
|
2010
|
+
const _pluralRules = options.pluralRules || (isLocale && root.pluralRules);
|
|
2011
|
+
// track reactivity
|
|
2012
|
+
function trackReactivityValues() {
|
|
2013
|
+
return [
|
|
2014
|
+
_locale.value,
|
|
2015
|
+
_fallbackLocale.value,
|
|
2016
|
+
_messages.value,
|
|
2017
|
+
_datetimeFormats.value,
|
|
2018
|
+
_numberFormats.value
|
|
2019
|
+
];
|
|
2020
|
+
}
|
|
2021
|
+
// locale
|
|
2022
|
+
const locale = vue.computed({
|
|
2023
|
+
get: () => {
|
|
2024
|
+
return _composer.value ? _composer.value.locale.value : _locale.value;
|
|
2025
|
+
},
|
|
2026
|
+
set: val => {
|
|
2027
|
+
if (_composer.value) {
|
|
2028
|
+
_composer.value.locale.value = val;
|
|
2029
|
+
}
|
|
2030
|
+
_locale.value = val;
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
// fallbackLocale
|
|
2034
|
+
const fallbackLocale = vue.computed({
|
|
2035
|
+
get: () => {
|
|
2036
|
+
return _composer.value
|
|
2037
|
+
? _composer.value.fallbackLocale.value
|
|
2038
|
+
: _fallbackLocale.value;
|
|
2039
|
+
},
|
|
2040
|
+
set: val => {
|
|
2041
|
+
if (_composer.value) {
|
|
2042
|
+
_composer.value.fallbackLocale.value = val;
|
|
2043
|
+
}
|
|
2044
|
+
_fallbackLocale.value = val;
|
|
2045
|
+
}
|
|
2046
|
+
});
|
|
2047
|
+
// messages
|
|
2048
|
+
const messages = vue.computed(() => {
|
|
2049
|
+
if (_composer.value) {
|
|
2050
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2051
|
+
return _composer.value.messages.value;
|
|
2052
|
+
}
|
|
2053
|
+
else {
|
|
2054
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2055
|
+
return _messages.value;
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2058
|
+
const datetimeFormats = vue.computed(() => _datetimeFormats.value);
|
|
2059
|
+
const numberFormats = vue.computed(() => _numberFormats.value);
|
|
2060
|
+
function getPostTranslationHandler() {
|
|
2061
|
+
return _composer.value
|
|
2062
|
+
? _composer.value.getPostTranslationHandler()
|
|
2063
|
+
: _postTranslation;
|
|
2064
|
+
}
|
|
2065
|
+
function setPostTranslationHandler(handler) {
|
|
2066
|
+
if (_composer.value) {
|
|
2067
|
+
_composer.value.setPostTranslationHandler(handler);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
function getMissingHandler() {
|
|
2071
|
+
return _composer.value ? _composer.value.getMissingHandler() : _missing;
|
|
2072
|
+
}
|
|
2073
|
+
function setMissingHandler(handler) {
|
|
2074
|
+
if (_composer.value) {
|
|
2075
|
+
_composer.value.setMissingHandler(handler);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
function warpWithDeps(fn) {
|
|
2079
|
+
trackReactivityValues();
|
|
2080
|
+
return fn();
|
|
2081
|
+
}
|
|
2082
|
+
function t(...args) {
|
|
2083
|
+
return _composer.value
|
|
2084
|
+
? warpWithDeps(() => Reflect.apply(_composer.value.t, null, [...args]))
|
|
2085
|
+
: warpWithDeps(() => '');
|
|
2086
|
+
}
|
|
2087
|
+
function rt(...args) {
|
|
2088
|
+
return _composer.value
|
|
2089
|
+
? Reflect.apply(_composer.value.rt, null, [...args])
|
|
2090
|
+
: '';
|
|
2091
|
+
}
|
|
2092
|
+
function d(...args) {
|
|
2093
|
+
return _composer.value
|
|
2094
|
+
? warpWithDeps(() => Reflect.apply(_composer.value.d, null, [...args]))
|
|
2095
|
+
: warpWithDeps(() => '');
|
|
2096
|
+
}
|
|
2097
|
+
function n(...args) {
|
|
2098
|
+
return _composer.value
|
|
2099
|
+
? warpWithDeps(() => Reflect.apply(_composer.value.n, null, [...args]))
|
|
2100
|
+
: warpWithDeps(() => '');
|
|
2101
|
+
}
|
|
2102
|
+
function tm(key) {
|
|
2103
|
+
return _composer.value ? _composer.value.tm(key) : {};
|
|
2104
|
+
}
|
|
2105
|
+
function te(key, locale) {
|
|
2106
|
+
return _composer.value ? _composer.value.te(key, locale) : false;
|
|
2107
|
+
}
|
|
2108
|
+
function getLocaleMessage(locale) {
|
|
2109
|
+
return _composer.value ? _composer.value.getLocaleMessage(locale) : {};
|
|
2110
|
+
}
|
|
2111
|
+
function setLocaleMessage(locale, message) {
|
|
2112
|
+
if (_composer.value) {
|
|
2113
|
+
_composer.value.setLocaleMessage(locale, message);
|
|
2114
|
+
_messages.value[locale] = message;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
function mergeLocaleMessage(locale, message) {
|
|
2118
|
+
if (_composer.value) {
|
|
2119
|
+
_composer.value.mergeLocaleMessage(locale, message);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
function getDateTimeFormat(locale) {
|
|
2123
|
+
return _composer.value ? _composer.value.getDateTimeFormat(locale) : {};
|
|
2124
|
+
}
|
|
2125
|
+
function setDateTimeFormat(locale, format) {
|
|
2126
|
+
if (_composer.value) {
|
|
2127
|
+
_composer.value.setDateTimeFormat(locale, format);
|
|
2128
|
+
_datetimeFormats.value[locale] = format;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
function mergeDateTimeFormat(locale, format) {
|
|
2132
|
+
if (_composer.value) {
|
|
2133
|
+
_composer.value.mergeDateTimeFormat(locale, format);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
function getNumberFormat(locale) {
|
|
2137
|
+
return _composer.value ? _composer.value.getNumberFormat(locale) : {};
|
|
2138
|
+
}
|
|
2139
|
+
function setNumberFormat(locale, format) {
|
|
2140
|
+
if (_composer.value) {
|
|
2141
|
+
_composer.value.setNumberFormat(locale, format);
|
|
2142
|
+
_numberFormats.value[locale] = format;
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
function mergeNumberFormat(locale, format) {
|
|
2146
|
+
if (_composer.value) {
|
|
2147
|
+
_composer.value.mergeNumberFormat(locale, format);
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
const wrapper = {
|
|
2151
|
+
get id() {
|
|
2152
|
+
return _composer.value ? _composer.value.id : -1;
|
|
2153
|
+
},
|
|
2154
|
+
locale,
|
|
2155
|
+
fallbackLocale,
|
|
2156
|
+
messages,
|
|
2157
|
+
datetimeFormats,
|
|
2158
|
+
numberFormats,
|
|
2159
|
+
get inheritLocale() {
|
|
2160
|
+
return _composer.value ? _composer.value.inheritLocale : _inheritLocale;
|
|
2161
|
+
},
|
|
2162
|
+
set inheritLocale(val) {
|
|
2163
|
+
if (_composer.value) {
|
|
2164
|
+
_composer.value.inheritLocale = val;
|
|
2165
|
+
}
|
|
2166
|
+
},
|
|
2167
|
+
get availableLocales() {
|
|
2168
|
+
return _composer.value
|
|
2169
|
+
? _composer.value.availableLocales
|
|
2170
|
+
: Object.keys(_messages.value);
|
|
2171
|
+
},
|
|
2172
|
+
get modifiers() {
|
|
2173
|
+
return (_composer.value ? _composer.value.modifiers : _modifiers);
|
|
2174
|
+
},
|
|
2175
|
+
get pluralRules() {
|
|
2176
|
+
return (_composer.value ? _composer.value.pluralRules : _pluralRules);
|
|
2177
|
+
},
|
|
2178
|
+
get isGlobal() {
|
|
2179
|
+
return _composer.value ? _composer.value.isGlobal : false;
|
|
2180
|
+
},
|
|
2181
|
+
get missingWarn() {
|
|
2182
|
+
return _composer.value ? _composer.value.missingWarn : _missingWarn;
|
|
2183
|
+
},
|
|
2184
|
+
set missingWarn(val) {
|
|
2185
|
+
if (_composer.value) {
|
|
2186
|
+
_composer.value.missingWarn = val;
|
|
2187
|
+
}
|
|
2188
|
+
},
|
|
2189
|
+
get fallbackWarn() {
|
|
2190
|
+
return _composer.value ? _composer.value.fallbackWarn : _fallbackWarn;
|
|
2191
|
+
},
|
|
2192
|
+
set fallbackWarn(val) {
|
|
2193
|
+
if (_composer.value) {
|
|
2194
|
+
_composer.value.missingWarn = val;
|
|
2195
|
+
}
|
|
2196
|
+
},
|
|
2197
|
+
get fallbackRoot() {
|
|
2198
|
+
return _composer.value ? _composer.value.fallbackRoot : _fallbackRoot;
|
|
2199
|
+
},
|
|
2200
|
+
set fallbackRoot(val) {
|
|
2201
|
+
if (_composer.value) {
|
|
2202
|
+
_composer.value.fallbackRoot = val;
|
|
2203
|
+
}
|
|
2204
|
+
},
|
|
2205
|
+
get fallbackFormat() {
|
|
2206
|
+
return _composer.value ? _composer.value.fallbackFormat : _fallbackFormat;
|
|
2207
|
+
},
|
|
2208
|
+
set fallbackFormat(val) {
|
|
2209
|
+
if (_composer.value) {
|
|
2210
|
+
_composer.value.fallbackFormat = val;
|
|
2211
|
+
}
|
|
2212
|
+
},
|
|
2213
|
+
get warnHtmlMessage() {
|
|
2214
|
+
return _composer.value
|
|
2215
|
+
? _composer.value.warnHtmlMessage
|
|
2216
|
+
: _warnHtmlMessage;
|
|
2217
|
+
},
|
|
2218
|
+
set warnHtmlMessage(val) {
|
|
2219
|
+
if (_composer.value) {
|
|
2220
|
+
_composer.value.warnHtmlMessage = val;
|
|
2221
|
+
}
|
|
2222
|
+
},
|
|
2223
|
+
get escapeParameter() {
|
|
2224
|
+
return _composer.value
|
|
2225
|
+
? _composer.value.escapeParameter
|
|
2226
|
+
: _escapeParameter;
|
|
2227
|
+
},
|
|
2228
|
+
set escapeParameter(val) {
|
|
2229
|
+
if (_composer.value) {
|
|
2230
|
+
_composer.value.escapeParameter = val;
|
|
2231
|
+
}
|
|
2232
|
+
},
|
|
2233
|
+
t,
|
|
2234
|
+
getPostTranslationHandler,
|
|
2235
|
+
setPostTranslationHandler,
|
|
2236
|
+
getMissingHandler,
|
|
2237
|
+
setMissingHandler,
|
|
2238
|
+
rt,
|
|
2239
|
+
d,
|
|
2240
|
+
n,
|
|
2241
|
+
tm,
|
|
2242
|
+
te,
|
|
2243
|
+
getLocaleMessage,
|
|
2244
|
+
setLocaleMessage,
|
|
2245
|
+
mergeLocaleMessage,
|
|
2246
|
+
getDateTimeFormat,
|
|
2247
|
+
setDateTimeFormat,
|
|
2248
|
+
mergeDateTimeFormat,
|
|
2249
|
+
getNumberFormat,
|
|
2250
|
+
setNumberFormat,
|
|
2251
|
+
mergeNumberFormat
|
|
2252
|
+
};
|
|
2253
|
+
function sync(composer) {
|
|
2254
|
+
composer.locale.value = _locale.value;
|
|
2255
|
+
composer.fallbackLocale.value = _fallbackLocale.value;
|
|
2256
|
+
Object.keys(_messages.value).forEach(locale => {
|
|
2257
|
+
composer.mergeLocaleMessage(locale, _messages.value[locale]);
|
|
2258
|
+
});
|
|
2259
|
+
Object.keys(_datetimeFormats.value).forEach(locale => {
|
|
2260
|
+
composer.mergeDateTimeFormat(locale, _datetimeFormats.value[locale]);
|
|
2261
|
+
});
|
|
2262
|
+
Object.keys(_numberFormats.value).forEach(locale => {
|
|
2263
|
+
composer.mergeNumberFormat(locale, _numberFormats.value[locale]);
|
|
2264
|
+
});
|
|
2265
|
+
composer.escapeParameter = _escapeParameter;
|
|
2266
|
+
composer.fallbackFormat = _fallbackFormat;
|
|
2267
|
+
composer.fallbackRoot = _fallbackRoot;
|
|
2268
|
+
composer.fallbackWarn = _fallbackWarn;
|
|
2269
|
+
composer.missingWarn = _missingWarn;
|
|
2270
|
+
composer.warnHtmlMessage = _warnHtmlMessage;
|
|
2271
|
+
}
|
|
2272
|
+
vue.onBeforeMount(() => {
|
|
2273
|
+
if (instance.proxy == null || instance.proxy.$i18n == null) {
|
|
2274
|
+
throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY);
|
|
2275
|
+
}
|
|
2276
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2277
|
+
const composer = (_composer.value = instance.proxy.$i18n
|
|
2278
|
+
.__composer);
|
|
2279
|
+
if (scope === 'global') {
|
|
2280
|
+
_locale.value = composer.locale.value;
|
|
2281
|
+
_fallbackLocale.value = composer.fallbackLocale.value;
|
|
2282
|
+
_messages.value = composer.messages.value;
|
|
2283
|
+
_datetimeFormats.value = composer.datetimeFormats.value;
|
|
2284
|
+
_numberFormats.value = composer.numberFormats.value;
|
|
2285
|
+
}
|
|
2286
|
+
else if (isLocale) {
|
|
2287
|
+
sync(composer);
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
return wrapper;
|
|
2291
|
+
}
|
|
1812
2292
|
const globalExportProps = [
|
|
1813
2293
|
'locale',
|
|
1814
2294
|
'fallbackLocale',
|
|
@@ -1867,6 +2347,7 @@ exports.I18nInjectionKey = I18nInjectionKey;
|
|
|
1867
2347
|
exports.NumberFormat = NumberFormat;
|
|
1868
2348
|
exports.Translation = Translation;
|
|
1869
2349
|
exports.VERSION = VERSION;
|
|
2350
|
+
exports.castToVueI18n = castToVueI18n;
|
|
1870
2351
|
exports.createI18n = createI18n;
|
|
1871
2352
|
exports.useI18n = useI18n;
|
|
1872
2353
|
exports.vTDirective = vTDirective;
|