yc-design-vue 1.7.9 → 1.8.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/es/Calendar/Calendar.vue.js +15 -14
- package/es/Calendar/CalendarMonth.vue.js +11 -1
- package/es/Calendar/CalendarYear.vue.js +20 -16
- package/es/ColorPicker/ColorList.vue.js +4 -2
- package/es/ColorPicker/ColorPanel.vue.js +6 -4
- package/es/ConfigProvider/index.d.ts +3 -0
- package/es/ConfigProvider/index.vue.d.ts +1 -0
- package/es/ConfigProvider/index.vue.js +13 -2
- package/es/ConfigProvider/type.d.ts +1 -0
- package/es/Drawer/Drawer.vue.js +6 -4
- package/es/Drawer/DrawerService.vue.js +2 -2
- package/es/Empty/index.vue.js +11 -4
- package/es/Image/Image.vue.js +4 -2
- package/es/Image/ImagePreviewToolbar.vue.js +13 -29
- package/es/Layout/hooks/useTheme.js +0 -1
- package/es/Modal/Modal.vue.js +6 -4
- package/es/Modal/ModalService.vue.js +2 -2
- package/es/Pagination/Pagination.vue.js +5 -3
- package/es/Pagination/hooks/useContext.d.ts +5 -0
- package/es/Pagination/hooks/useContext.js +5 -2
- package/es/Popconfirm/index.vue.js +6 -4
- package/es/Transfer/TransferPanel.vue.js +2 -2
- package/es/Typography/TypographyBase.vue.js +7 -6
- package/es/_shared/icons/IconCopy.vue.js +1 -17
- package/es/_shared/icons/IconCopy.vue2.js +17 -1
- package/es/_shared/icons/IconDelete.vue.js +1 -17
- package/es/_shared/icons/IconDelete.vue2.js +17 -1
- package/es/_shared/icons/IconEdit.vue.js +1 -17
- package/es/_shared/icons/IconEdit.vue2.js +17 -1
- package/es/_shared/icons/IconSearch.vue.js +1 -17
- package/es/_shared/icons/IconSearch.vue2.js +17 -1
- package/es/_shared/locale/i18n.d.ts +256 -0
- package/es/_shared/locale/i18n.js +35 -0
- package/es/_shared/locale/lang/ar-eg.d.ts +205 -0
- package/es/_shared/locale/lang/ar-eg.js +153 -0
- package/es/_shared/locale/lang/de-de.d.ts +205 -0
- package/es/_shared/locale/lang/de-de.js +153 -0
- package/es/_shared/locale/lang/en-us.d.ts +253 -0
- package/es/_shared/locale/lang/en-us.js +158 -0
- package/es/_shared/locale/lang/es-es.d.ts +205 -0
- package/es/_shared/locale/lang/es-es.js +153 -0
- package/es/_shared/locale/lang/fr-fr.d.ts +205 -0
- package/es/_shared/locale/lang/fr-fr.js +153 -0
- package/es/_shared/locale/lang/id-id.d.ts +205 -0
- package/es/_shared/locale/lang/id-id.js +153 -0
- package/es/_shared/locale/lang/it-it.d.ts +205 -0
- package/es/_shared/locale/lang/it-it.js +153 -0
- package/es/_shared/locale/lang/ja-jp.d.ts +253 -0
- package/es/_shared/locale/lang/ja-jp.js +201 -0
- package/es/_shared/locale/lang/km-kh.d.ts +205 -0
- package/es/_shared/locale/lang/km-kh.js +153 -0
- package/es/_shared/locale/lang/ko-kr.d.ts +205 -0
- package/es/_shared/locale/lang/ko-kr.js +153 -0
- package/es/_shared/locale/lang/ms-my.d.ts +205 -0
- package/es/_shared/locale/lang/ms-my.js +153 -0
- package/es/_shared/locale/lang/nl-nl.d.ts +253 -0
- package/es/_shared/locale/lang/nl-nl.js +201 -0
- package/es/_shared/locale/lang/pt-pt.d.ts +205 -0
- package/es/_shared/locale/lang/pt-pt.js +153 -0
- package/es/_shared/locale/lang/ru-ru.d.ts +253 -0
- package/es/_shared/locale/lang/ru-ru.js +201 -0
- package/es/_shared/locale/lang/th-th.d.ts +205 -0
- package/es/_shared/locale/lang/th-th.js +153 -0
- package/es/_shared/locale/lang/vi-vn.d.ts +205 -0
- package/es/_shared/locale/lang/vi-vn.js +153 -0
- package/es/_shared/locale/lang/zh-cn.d.ts +253 -0
- package/es/_shared/locale/lang/zh-cn.js +201 -0
- package/es/_shared/locale/lang/zh-tw.d.ts +253 -0
- package/es/_shared/locale/lang/zh-tw.js +201 -0
- package/es/_shared/utils/time.js +1 -1
- package/es/_virtual/dynamic-import-helper.js +19 -0
- package/es/index.js +2 -0
- package/es/node_modules/@intlify/core-base/dist/core-base.js +1129 -0
- package/es/node_modules/@intlify/message-compiler/dist/message-compiler.js +65 -0
- package/es/node_modules/@intlify/shared/dist/shared.js +199 -0
- package/es/node_modules/@intlify/vue-i18n-core/dist/vue-i18n-core.js +1381 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/const.js +6 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/env.js +12 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/index.js +26 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/proxy.js +103 -0
- package/es/node_modules/@vue/devtools-api/lib/esm/time.js +25 -0
- package/es/node_modules/b-validate/es/is.js +27 -0
- package/es/node_modules/b-validate/es/locale/en-US.js +50 -0
- package/es/node_modules/b-validate/es/rules/base.js +86 -0
- package/es/node_modules/b-validate/es/util.js +25 -0
- package/lib/Calendar/Calendar.vue.js +1 -1
- package/lib/Calendar/CalendarMonth.vue.js +1 -1
- package/lib/Calendar/CalendarYear.vue.js +1 -1
- package/lib/ColorPicker/ColorList.vue.js +1 -1
- package/lib/ColorPicker/ColorPanel.vue.js +1 -1
- package/lib/ConfigProvider/index.d.ts +3 -0
- package/lib/ConfigProvider/index.vue.d.ts +1 -0
- package/lib/ConfigProvider/index.vue.js +1 -1
- package/lib/ConfigProvider/type.d.ts +1 -0
- package/lib/Drawer/Drawer.vue.js +1 -1
- package/lib/Drawer/DrawerService.vue.js +1 -1
- package/lib/Empty/index.vue.js +1 -1
- package/lib/Image/Image.vue.js +1 -1
- package/lib/Image/ImagePreviewToolbar.vue.js +1 -1
- package/lib/Modal/Modal.vue.js +1 -1
- package/lib/Modal/ModalService.vue.js +1 -1
- package/lib/Pagination/Pagination.vue.js +1 -1
- package/lib/Pagination/hooks/useContext.d.ts +5 -0
- package/lib/Pagination/hooks/useContext.js +1 -1
- package/lib/Popconfirm/index.vue.js +1 -1
- package/lib/Transfer/TransferPanel.vue.js +1 -1
- package/lib/Typography/TypographyBase.vue.js +1 -1
- package/lib/_shared/icons/IconCopy.vue.js +1 -1
- package/lib/_shared/icons/IconCopy.vue2.js +1 -1
- package/lib/_shared/icons/IconDelete.vue.js +1 -1
- package/lib/_shared/icons/IconDelete.vue2.js +1 -1
- package/lib/_shared/icons/IconEdit.vue.js +1 -1
- package/lib/_shared/icons/IconEdit.vue2.js +1 -1
- package/lib/_shared/icons/IconSearch.vue.js +1 -1
- package/lib/_shared/icons/IconSearch.vue2.js +1 -1
- package/lib/_shared/locale/i18n.d.ts +256 -0
- package/lib/_shared/locale/i18n.js +1 -0
- package/lib/_shared/locale/lang/ar-eg.d.ts +205 -0
- package/lib/_shared/locale/lang/ar-eg.js +1 -0
- package/lib/_shared/locale/lang/de-de.d.ts +205 -0
- package/lib/_shared/locale/lang/de-de.js +1 -0
- package/lib/_shared/locale/lang/en-us.d.ts +253 -0
- package/lib/_shared/locale/lang/en-us.js +1 -0
- package/lib/_shared/locale/lang/es-es.d.ts +205 -0
- package/lib/_shared/locale/lang/es-es.js +1 -0
- package/lib/_shared/locale/lang/fr-fr.d.ts +205 -0
- package/lib/_shared/locale/lang/fr-fr.js +1 -0
- package/lib/_shared/locale/lang/id-id.d.ts +205 -0
- package/lib/_shared/locale/lang/id-id.js +1 -0
- package/lib/_shared/locale/lang/it-it.d.ts +205 -0
- package/lib/_shared/locale/lang/it-it.js +1 -0
- package/lib/_shared/locale/lang/ja-jp.d.ts +253 -0
- package/lib/_shared/locale/lang/ja-jp.js +1 -0
- package/lib/_shared/locale/lang/km-kh.d.ts +205 -0
- package/lib/_shared/locale/lang/km-kh.js +1 -0
- package/lib/_shared/locale/lang/ko-kr.d.ts +205 -0
- package/lib/_shared/locale/lang/ko-kr.js +1 -0
- package/lib/_shared/locale/lang/ms-my.d.ts +205 -0
- package/lib/_shared/locale/lang/ms-my.js +1 -0
- package/lib/_shared/locale/lang/nl-nl.d.ts +253 -0
- package/lib/_shared/locale/lang/nl-nl.js +1 -0
- package/lib/_shared/locale/lang/pt-pt.d.ts +205 -0
- package/lib/_shared/locale/lang/pt-pt.js +1 -0
- package/lib/_shared/locale/lang/ru-ru.d.ts +253 -0
- package/lib/_shared/locale/lang/ru-ru.js +1 -0
- package/lib/_shared/locale/lang/th-th.d.ts +205 -0
- package/lib/_shared/locale/lang/th-th.js +1 -0
- package/lib/_shared/locale/lang/vi-vn.d.ts +205 -0
- package/lib/_shared/locale/lang/vi-vn.js +1 -0
- package/lib/_shared/locale/lang/zh-cn.d.ts +253 -0
- package/lib/_shared/locale/lang/zh-cn.js +1 -0
- package/lib/_shared/locale/lang/zh-tw.d.ts +253 -0
- package/lib/_shared/locale/lang/zh-tw.js +1 -0
- package/lib/_shared/utils/time.js +1 -1
- package/lib/_virtual/dynamic-import-helper.js +1 -0
- package/lib/index.js +1 -1
- package/lib/node_modules/@intlify/core-base/dist/core-base.js +1 -0
- package/lib/node_modules/@intlify/message-compiler/dist/message-compiler.js +6 -0
- package/lib/node_modules/@intlify/shared/dist/shared.js +7 -0
- package/lib/node_modules/@intlify/vue-i18n-core/dist/vue-i18n-core.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/const.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/env.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/index.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/proxy.js +1 -0
- package/lib/node_modules/@vue/devtools-api/lib/esm/time.js +1 -0
- package/lib/node_modules/b-validate/es/is.js +1 -0
- package/lib/node_modules/b-validate/es/locale/en-US.js +1 -0
- package/lib/node_modules/b-validate/es/rules/base.js +1 -0
- package/lib/node_modules/b-validate/es/util.js +1 -0
- package/package.json +3 -2
@@ -0,0 +1,1381 @@
|
|
1
|
+
import { DEFAULT_LOCALE, updateFallbackLocale, CORE_WARN_CODES_EXTEND_POINT, createCoreContext, clearDateTimeFormat, clearNumberFormat, isMessageAST, AST_NODE_PROPS_KEYS, setAdditionalMeta, getFallbackContext, NOT_RESOLVED, isTranslateFallbackWarn, isTranslateMissingWarn, CORE_ERROR_CODES_EXTEND_POINT, fallbackWithLocaleChain, setFallbackContext, parseTranslateArgs, translate, MISSING_RESOLVE_VALUE, parseDateTimeArgs, datetime, parseNumberArgs, number, isMessageFunction, DATETIME_FORMAT_OPTIONS_KEYS, NUMBER_FORMAT_OPTIONS_KEYS, setDevToolsHook } from "../../core-base/dist/core-base.js";
|
2
|
+
import { warn, assign, makeSymbol, isEmptyObject, isObject, create, format, isBoolean, isString, isArray, isPlainObject, isRegExp, isFunction, inBrowser, deepCopy, hasOwn, isNumber, createEmitter, getGlobalThis } from "../../shared/dist/shared.js";
|
3
|
+
import { getCurrentInstance, inject, ref, shallowRef, computed, watch, onMounted, onUnmounted, effectScope, isRef, defineComponent, h, Fragment, createVNode, Text } from "vue";
|
4
|
+
import { setupDevtoolsPlugin } from "../../../@vue/devtools-api/lib/esm/index.js";
|
5
|
+
import { createCompileError } from "../../message-compiler/dist/message-compiler.js";
|
6
|
+
/*!
|
7
|
+
* vue-i18n-core v12.0.0-alpha.3
|
8
|
+
* (c) 2016-present kazuya kawaguchi and contributors
|
9
|
+
* Released under the MIT License.
|
10
|
+
*/
|
11
|
+
const VERSION = "12.0.0-alpha.3";
|
12
|
+
function initFeatureFlags() {
|
13
|
+
if (typeof __VUE_I18N_FULL_INSTALL__ !== "boolean") {
|
14
|
+
getGlobalThis().__VUE_I18N_FULL_INSTALL__ = true;
|
15
|
+
}
|
16
|
+
if (typeof __INTLIFY_DROP_MESSAGE_COMPILER__ !== "boolean") {
|
17
|
+
getGlobalThis().__INTLIFY_DROP_MESSAGE_COMPILER__ = false;
|
18
|
+
}
|
19
|
+
if (typeof __INTLIFY_PROD_DEVTOOLS__ !== "boolean") {
|
20
|
+
getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
const I18nErrorCodes = {
|
24
|
+
// composer module errors
|
25
|
+
UNEXPECTED_RETURN_TYPE: CORE_ERROR_CODES_EXTEND_POINT,
|
26
|
+
// 24
|
27
|
+
// legacy module errors
|
28
|
+
INVALID_ARGUMENT: 25,
|
29
|
+
// i18n module errors
|
30
|
+
MUST_BE_CALL_SETUP_TOP: 26,
|
31
|
+
NOT_INSTALLED: 27,
|
32
|
+
// directive module errors
|
33
|
+
REQUIRED_VALUE: 28,
|
34
|
+
INVALID_VALUE: 29,
|
35
|
+
// vue-devtools errors
|
36
|
+
CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: 30,
|
37
|
+
NOT_INSTALLED_WITH_PROVIDE: 31,
|
38
|
+
// unexpected error
|
39
|
+
UNEXPECTED_ERROR: 32,
|
40
|
+
// duplicate `useI18n` calling
|
41
|
+
DUPLICATE_USE_I18N_CALLING: 33
|
42
|
+
};
|
43
|
+
function createI18nError(code, ...args) {
|
44
|
+
return createCompileError(code, null, process.env.NODE_ENV !== "production" ? { messages: errorMessages, args } : void 0);
|
45
|
+
}
|
46
|
+
const errorMessages = {
|
47
|
+
[I18nErrorCodes.UNEXPECTED_RETURN_TYPE]: "Unexpected return type in composer",
|
48
|
+
[I18nErrorCodes.INVALID_ARGUMENT]: "Invalid argument",
|
49
|
+
[I18nErrorCodes.MUST_BE_CALL_SETUP_TOP]: "Must be called at the top of a `setup` function",
|
50
|
+
[I18nErrorCodes.NOT_INSTALLED]: "Need to install with `app.use` function",
|
51
|
+
[I18nErrorCodes.UNEXPECTED_ERROR]: "Unexpected error",
|
52
|
+
[I18nErrorCodes.REQUIRED_VALUE]: `Required in value: {0}`,
|
53
|
+
[I18nErrorCodes.INVALID_VALUE]: `Invalid value`,
|
54
|
+
[I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`,
|
55
|
+
[I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE]: "Need to install with `provide` function",
|
56
|
+
[I18nErrorCodes.DUPLICATE_USE_I18N_CALLING]: "Duplicate local-scope `useI18n` call detected. Call `useI18n` only once per component."
|
57
|
+
};
|
58
|
+
const TranslateVNodeSymbol = /* @__PURE__ */ makeSymbol("__translateVNode");
|
59
|
+
const DatetimePartsSymbol = /* @__PURE__ */ makeSymbol("__datetimeParts");
|
60
|
+
const NumberPartsSymbol = /* @__PURE__ */ makeSymbol("__numberParts");
|
61
|
+
const EnableEmitter = /* @__PURE__ */ makeSymbol("__enableEmitter");
|
62
|
+
const DisableEmitter = /* @__PURE__ */ makeSymbol("__disableEmitter");
|
63
|
+
const SetPluralRulesSymbol = makeSymbol("__setPluralRules");
|
64
|
+
const InejctWithOptionSymbol = /* @__PURE__ */ makeSymbol("__injectWithOption");
|
65
|
+
const DisposeSymbol = /* @__PURE__ */ makeSymbol("__dispose");
|
66
|
+
const I18nWarnCodes = {
|
67
|
+
FALLBACK_TO_ROOT: CORE_WARN_CODES_EXTEND_POINT,
|
68
|
+
// 8
|
69
|
+
NOT_FOUND_PARENT_SCOPE: 9,
|
70
|
+
IGNORE_OBJ_FLATTEN: 10
|
71
|
+
};
|
72
|
+
const warnMessages = {
|
73
|
+
[I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
|
74
|
+
[I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
|
75
|
+
[I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`
|
76
|
+
};
|
77
|
+
function getWarnMessage(code, ...args) {
|
78
|
+
return format(warnMessages[code], ...args);
|
79
|
+
}
|
80
|
+
function handleFlatJson(obj) {
|
81
|
+
if (!isObject(obj)) {
|
82
|
+
return obj;
|
83
|
+
}
|
84
|
+
if (isMessageAST(obj)) {
|
85
|
+
return obj;
|
86
|
+
}
|
87
|
+
for (const key in obj) {
|
88
|
+
if (!hasOwn(obj, key)) {
|
89
|
+
continue;
|
90
|
+
}
|
91
|
+
if (!key.includes(".")) {
|
92
|
+
if (isObject(obj[key])) {
|
93
|
+
handleFlatJson(obj[key]);
|
94
|
+
}
|
95
|
+
} else {
|
96
|
+
const subKeys = key.split(".");
|
97
|
+
const lastIndex = subKeys.length - 1;
|
98
|
+
let currentObj = obj;
|
99
|
+
let hasStringValue = false;
|
100
|
+
for (let i = 0; i < lastIndex; i++) {
|
101
|
+
if (subKeys[i] === "__proto__") {
|
102
|
+
throw new Error(`unsafe key: ${subKeys[i]}`);
|
103
|
+
}
|
104
|
+
if (!(subKeys[i] in currentObj)) {
|
105
|
+
currentObj[subKeys[i]] = create();
|
106
|
+
}
|
107
|
+
if (!isObject(currentObj[subKeys[i]])) {
|
108
|
+
process.env.NODE_ENV !== "production" && warn(getWarnMessage(I18nWarnCodes.IGNORE_OBJ_FLATTEN, {
|
109
|
+
key: subKeys[i]
|
110
|
+
}));
|
111
|
+
hasStringValue = true;
|
112
|
+
break;
|
113
|
+
}
|
114
|
+
currentObj = currentObj[subKeys[i]];
|
115
|
+
}
|
116
|
+
if (!hasStringValue) {
|
117
|
+
if (!isMessageAST(currentObj)) {
|
118
|
+
currentObj[subKeys[lastIndex]] = obj[key];
|
119
|
+
delete obj[key];
|
120
|
+
} else {
|
121
|
+
if (!AST_NODE_PROPS_KEYS.includes(subKeys[lastIndex])) {
|
122
|
+
delete obj[key];
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
if (!isMessageAST(currentObj)) {
|
127
|
+
const target = currentObj[subKeys[lastIndex]];
|
128
|
+
if (isObject(target)) {
|
129
|
+
handleFlatJson(target);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
return obj;
|
135
|
+
}
|
136
|
+
function getLocaleMessages(locale, options) {
|
137
|
+
const { messages, __i18n, messageResolver, flatJson } = options;
|
138
|
+
const ret = isPlainObject(messages) ? messages : isArray(__i18n) ? create() : { [locale]: create() };
|
139
|
+
if (isArray(__i18n)) {
|
140
|
+
__i18n.forEach((custom) => {
|
141
|
+
if ("locale" in custom && "resource" in custom) {
|
142
|
+
const { locale: locale2, resource } = custom;
|
143
|
+
if (locale2) {
|
144
|
+
ret[locale2] = ret[locale2] || create();
|
145
|
+
deepCopy(resource, ret[locale2]);
|
146
|
+
} else {
|
147
|
+
deepCopy(resource, ret);
|
148
|
+
}
|
149
|
+
} else {
|
150
|
+
isString(custom) && deepCopy(JSON.parse(custom), ret);
|
151
|
+
}
|
152
|
+
});
|
153
|
+
}
|
154
|
+
if (messageResolver == null && flatJson) {
|
155
|
+
for (const key in ret) {
|
156
|
+
if (hasOwn(ret, key)) {
|
157
|
+
handleFlatJson(ret[key]);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
return ret;
|
162
|
+
}
|
163
|
+
function getComponentOptions(instance) {
|
164
|
+
return instance.type;
|
165
|
+
}
|
166
|
+
function adjustI18nResources(gl, options, componentOptions) {
|
167
|
+
let messages = isObject(options.messages) ? options.messages : create();
|
168
|
+
if ("__i18nGlobal" in componentOptions) {
|
169
|
+
messages = getLocaleMessages(gl.locale.value, {
|
170
|
+
messages,
|
171
|
+
__i18n: componentOptions.__i18nGlobal
|
172
|
+
});
|
173
|
+
}
|
174
|
+
const locales = Object.keys(messages);
|
175
|
+
if (locales.length) {
|
176
|
+
locales.forEach((locale) => {
|
177
|
+
gl.mergeLocaleMessage(locale, messages[locale]);
|
178
|
+
});
|
179
|
+
}
|
180
|
+
{
|
181
|
+
if (isObject(options.datetimeFormats)) {
|
182
|
+
const locales2 = Object.keys(options.datetimeFormats);
|
183
|
+
if (locales2.length) {
|
184
|
+
locales2.forEach((locale) => {
|
185
|
+
gl.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
|
186
|
+
});
|
187
|
+
}
|
188
|
+
}
|
189
|
+
if (isObject(options.numberFormats)) {
|
190
|
+
const locales2 = Object.keys(options.numberFormats);
|
191
|
+
if (locales2.length) {
|
192
|
+
locales2.forEach((locale) => {
|
193
|
+
gl.mergeNumberFormat(locale, options.numberFormats[locale]);
|
194
|
+
});
|
195
|
+
}
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
function createTextNode(key) {
|
200
|
+
return createVNode(Text, null, key, 0);
|
201
|
+
}
|
202
|
+
const DEVTOOLS_META = "__INTLIFY_META__";
|
203
|
+
const NOOP_RETURN_ARRAY = () => [];
|
204
|
+
const NOOP_RETURN_FALSE = () => false;
|
205
|
+
let composerID = 0;
|
206
|
+
function defineCoreMissingHandler(missing) {
|
207
|
+
return (ctx, locale, key, type) => {
|
208
|
+
return missing(locale, key, getCurrentInstance() || void 0, type);
|
209
|
+
};
|
210
|
+
}
|
211
|
+
const getMetaInfo = /* @__NO_SIDE_EFFECTS__ */ () => {
|
212
|
+
const instance = getCurrentInstance();
|
213
|
+
let meta = null;
|
214
|
+
return instance && (meta = getComponentOptions(instance)[DEVTOOLS_META]) ? { [DEVTOOLS_META]: meta } : null;
|
215
|
+
};
|
216
|
+
function createComposer(options = {}) {
|
217
|
+
const { __root, __injectWithOption } = options;
|
218
|
+
const _isGlobal = __root === void 0;
|
219
|
+
const flatJson = options.flatJson;
|
220
|
+
const _ref = inBrowser ? ref : shallowRef;
|
221
|
+
let _inheritLocale = isBoolean(options.inheritLocale) ? options.inheritLocale : true;
|
222
|
+
const _locale = _ref(
|
223
|
+
// prettier-ignore
|
224
|
+
__root && _inheritLocale ? __root.locale.value : isString(options.locale) ? options.locale : DEFAULT_LOCALE
|
225
|
+
);
|
226
|
+
const _fallbackLocale = _ref(
|
227
|
+
// prettier-ignore
|
228
|
+
__root && _inheritLocale ? __root.fallbackLocale.value : isString(options.fallbackLocale) || isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale.value
|
229
|
+
);
|
230
|
+
const _messages = _ref(getLocaleMessages(_locale.value, options));
|
231
|
+
const _datetimeFormats = _ref(isPlainObject(options.datetimeFormats) ? options.datetimeFormats : { [_locale.value]: {} });
|
232
|
+
const _numberFormats = _ref(isPlainObject(options.numberFormats) ? options.numberFormats : { [_locale.value]: {} });
|
233
|
+
let _missingWarn = __root ? __root.missingWarn : isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true;
|
234
|
+
let _fallbackWarn = __root ? __root.fallbackWarn : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true;
|
235
|
+
let _fallbackRoot = __root ? __root.fallbackRoot : isBoolean(options.fallbackRoot) ? options.fallbackRoot : true;
|
236
|
+
let _fallbackFormat = !!options.fallbackFormat;
|
237
|
+
let _missing = isFunction(options.missing) ? options.missing : null;
|
238
|
+
let _runtimeMissing = isFunction(options.missing) ? defineCoreMissingHandler(options.missing) : null;
|
239
|
+
let _postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null;
|
240
|
+
let _warnHtmlMessage = __root ? __root.warnHtmlMessage : isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true;
|
241
|
+
let _escapeParameter = !!options.escapeParameter;
|
242
|
+
const _modifiers = __root ? __root.modifiers : isPlainObject(options.modifiers) ? options.modifiers : {};
|
243
|
+
let _pluralRules = options.pluralRules || __root && __root.pluralRules;
|
244
|
+
let _context;
|
245
|
+
const getCoreContext = () => {
|
246
|
+
_isGlobal && setFallbackContext(null);
|
247
|
+
const ctxOptions = {
|
248
|
+
version: VERSION,
|
249
|
+
locale: _locale.value,
|
250
|
+
fallbackLocale: _fallbackLocale.value,
|
251
|
+
messages: _messages.value,
|
252
|
+
modifiers: _modifiers,
|
253
|
+
pluralRules: _pluralRules,
|
254
|
+
missing: _runtimeMissing === null ? void 0 : _runtimeMissing,
|
255
|
+
missingWarn: _missingWarn,
|
256
|
+
fallbackWarn: _fallbackWarn,
|
257
|
+
fallbackFormat: _fallbackFormat,
|
258
|
+
unresolving: true,
|
259
|
+
postTranslation: _postTranslation === null ? void 0 : _postTranslation,
|
260
|
+
warnHtmlMessage: _warnHtmlMessage,
|
261
|
+
escapeParameter: _escapeParameter,
|
262
|
+
messageResolver: options.messageResolver,
|
263
|
+
messageCompiler: options.messageCompiler,
|
264
|
+
__meta: { framework: "vue" }
|
265
|
+
};
|
266
|
+
{
|
267
|
+
ctxOptions.datetimeFormats = _datetimeFormats.value;
|
268
|
+
ctxOptions.numberFormats = _numberFormats.value;
|
269
|
+
ctxOptions.__datetimeFormatters = isPlainObject(_context) ? _context.__datetimeFormatters : void 0;
|
270
|
+
ctxOptions.__numberFormatters = isPlainObject(_context) ? _context.__numberFormatters : void 0;
|
271
|
+
}
|
272
|
+
if (process.env.NODE_ENV !== "production") {
|
273
|
+
ctxOptions.__v_emitter = isPlainObject(_context) ? _context.__v_emitter : void 0;
|
274
|
+
}
|
275
|
+
const ctx = createCoreContext(ctxOptions);
|
276
|
+
_isGlobal && setFallbackContext(ctx);
|
277
|
+
return ctx;
|
278
|
+
};
|
279
|
+
_context = getCoreContext();
|
280
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
281
|
+
function trackReactivityValues() {
|
282
|
+
return [
|
283
|
+
_locale.value,
|
284
|
+
_fallbackLocale.value,
|
285
|
+
_messages.value,
|
286
|
+
_datetimeFormats.value,
|
287
|
+
_numberFormats.value
|
288
|
+
];
|
289
|
+
}
|
290
|
+
const locale = computed({
|
291
|
+
get: () => _locale.value,
|
292
|
+
set: (val) => {
|
293
|
+
_context.locale = val;
|
294
|
+
_locale.value = val;
|
295
|
+
}
|
296
|
+
});
|
297
|
+
const fallbackLocale = computed({
|
298
|
+
get: () => _fallbackLocale.value,
|
299
|
+
set: (val) => {
|
300
|
+
_context.fallbackLocale = val;
|
301
|
+
_fallbackLocale.value = val;
|
302
|
+
updateFallbackLocale(_context, _locale.value, val);
|
303
|
+
}
|
304
|
+
});
|
305
|
+
const messages = computed(() => _messages.value);
|
306
|
+
const availableLocales = computed(() => Object.keys(_messages.value).sort());
|
307
|
+
const datetimeFormats = /* @__PURE__ */ computed(() => _datetimeFormats.value);
|
308
|
+
const numberFormats = /* @__PURE__ */ computed(() => _numberFormats.value);
|
309
|
+
function getPostTranslationHandler() {
|
310
|
+
return isFunction(_postTranslation) ? _postTranslation : null;
|
311
|
+
}
|
312
|
+
function setPostTranslationHandler(handler) {
|
313
|
+
_postTranslation = handler;
|
314
|
+
_context.postTranslation = handler;
|
315
|
+
}
|
316
|
+
function getMissingHandler() {
|
317
|
+
return _missing;
|
318
|
+
}
|
319
|
+
function setMissingHandler(handler) {
|
320
|
+
if (handler !== null) {
|
321
|
+
_runtimeMissing = defineCoreMissingHandler(handler);
|
322
|
+
}
|
323
|
+
_missing = handler;
|
324
|
+
_context.missing = _runtimeMissing;
|
325
|
+
}
|
326
|
+
function isResolvedTranslateMessage(type, arg) {
|
327
|
+
return type !== "translate" || !arg.resolvedMessage;
|
328
|
+
}
|
329
|
+
const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => {
|
330
|
+
trackReactivityValues();
|
331
|
+
let ret;
|
332
|
+
try {
|
333
|
+
if (process.env.NODE_ENV !== "production" || __INTLIFY_PROD_DEVTOOLS__) {
|
334
|
+
setAdditionalMeta(/* @__PURE__ */ getMetaInfo());
|
335
|
+
}
|
336
|
+
if (!_isGlobal) {
|
337
|
+
_context.fallbackContext = __root ? getFallbackContext() : void 0;
|
338
|
+
}
|
339
|
+
ret = fn(_context);
|
340
|
+
} finally {
|
341
|
+
if (process.env.NODE_ENV !== "production" || __INTLIFY_PROD_DEVTOOLS__) ;
|
342
|
+
if (!_isGlobal) {
|
343
|
+
_context.fallbackContext = void 0;
|
344
|
+
}
|
345
|
+
}
|
346
|
+
if (warnType !== "translate exists" && // for not `te` (e.g `t`)
|
347
|
+
isNumber(ret) && ret === NOT_RESOLVED || warnType === "translate exists" && !ret) {
|
348
|
+
const [key, arg2] = argumentParser();
|
349
|
+
if (process.env.NODE_ENV !== "production" && __root && isString(key) && isResolvedTranslateMessage(warnType, arg2)) {
|
350
|
+
if (_fallbackRoot && (isTranslateFallbackWarn(_fallbackWarn, key) || isTranslateMissingWarn(_missingWarn, key))) {
|
351
|
+
warn(getWarnMessage(I18nWarnCodes.FALLBACK_TO_ROOT, {
|
352
|
+
key,
|
353
|
+
type: warnType
|
354
|
+
}));
|
355
|
+
}
|
356
|
+
if (process.env.NODE_ENV !== "production") {
|
357
|
+
const { __v_emitter: emitter } = _context;
|
358
|
+
if (emitter && _fallbackRoot) {
|
359
|
+
emitter.emit("fallback", {
|
360
|
+
type: warnType,
|
361
|
+
key,
|
362
|
+
to: "global",
|
363
|
+
groupId: `${warnType}:${key}`
|
364
|
+
});
|
365
|
+
}
|
366
|
+
}
|
367
|
+
}
|
368
|
+
return __root && _fallbackRoot ? fallbackSuccess(__root) : fallbackFail(key);
|
369
|
+
} else if (successCondition(ret)) {
|
370
|
+
return ret;
|
371
|
+
} else {
|
372
|
+
throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
|
373
|
+
}
|
374
|
+
};
|
375
|
+
function t(...args) {
|
376
|
+
return wrapWithDeps((context) => Reflect.apply(translate, null, [context, ...args]), () => parseTranslateArgs(...args), "translate", (root) => Reflect.apply(root.t, root, [...args]), (key) => key, (val) => isString(val));
|
377
|
+
}
|
378
|
+
function rt(...args) {
|
379
|
+
const [arg1, arg2, arg3] = args;
|
380
|
+
if (arg3 && !isObject(arg3)) {
|
381
|
+
throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
|
382
|
+
}
|
383
|
+
return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]);
|
384
|
+
}
|
385
|
+
function d(...args) {
|
386
|
+
return wrapWithDeps((context) => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), "datetime format", (root) => Reflect.apply(root.d, root, [...args]), () => MISSING_RESOLVE_VALUE, (val) => isString(val) || isArray(val));
|
387
|
+
}
|
388
|
+
function n(...args) {
|
389
|
+
return wrapWithDeps((context) => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), "number format", (root) => Reflect.apply(root.n, root, [...args]), () => MISSING_RESOLVE_VALUE, (val) => isString(val) || isArray(val));
|
390
|
+
}
|
391
|
+
function normalize(values) {
|
392
|
+
return values.map((val) => isString(val) || isNumber(val) || isBoolean(val) ? createTextNode(String(val)) : val);
|
393
|
+
}
|
394
|
+
const interpolate = (val) => val;
|
395
|
+
const processor = {
|
396
|
+
normalize,
|
397
|
+
interpolate,
|
398
|
+
type: "vnode"
|
399
|
+
};
|
400
|
+
function translateVNode(...args) {
|
401
|
+
return wrapWithDeps((context) => {
|
402
|
+
let ret;
|
403
|
+
const _context2 = context;
|
404
|
+
try {
|
405
|
+
_context2.processor = processor;
|
406
|
+
ret = Reflect.apply(translate, null, [_context2, ...args]);
|
407
|
+
} finally {
|
408
|
+
_context2.processor = null;
|
409
|
+
}
|
410
|
+
return ret;
|
411
|
+
}, () => parseTranslateArgs(...args), "translate", (root) => root[TranslateVNodeSymbol](...args), (key) => [createTextNode(key)], (val) => isArray(val));
|
412
|
+
}
|
413
|
+
function numberParts(...args) {
|
414
|
+
return wrapWithDeps((context) => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), "number format", (root) => root[NumberPartsSymbol](...args), NOOP_RETURN_ARRAY, (val) => isString(val) || isArray(val));
|
415
|
+
}
|
416
|
+
function datetimeParts(...args) {
|
417
|
+
return wrapWithDeps((context) => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), "datetime format", (root) => root[DatetimePartsSymbol](...args), NOOP_RETURN_ARRAY, (val) => isString(val) || isArray(val));
|
418
|
+
}
|
419
|
+
function setPluralRules(rules) {
|
420
|
+
_pluralRules = rules;
|
421
|
+
_context.pluralRules = _pluralRules;
|
422
|
+
}
|
423
|
+
function te(key, locale2) {
|
424
|
+
return wrapWithDeps(() => {
|
425
|
+
if (!key) {
|
426
|
+
return false;
|
427
|
+
}
|
428
|
+
const targetLocale = isString(locale2) ? locale2 : _locale.value;
|
429
|
+
const message = getLocaleMessage(targetLocale);
|
430
|
+
const resolved = _context.messageResolver(message, key);
|
431
|
+
return isMessageAST(resolved) || isMessageFunction(resolved) || isString(resolved);
|
432
|
+
}, () => [key], "translate exists", (root) => {
|
433
|
+
return Reflect.apply(root.te, root, [key, locale2]);
|
434
|
+
}, NOOP_RETURN_FALSE, (val) => isBoolean(val));
|
435
|
+
}
|
436
|
+
function resolveMessages(key) {
|
437
|
+
let messages2 = null;
|
438
|
+
const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
|
439
|
+
for (let i = 0; i < locales.length; i++) {
|
440
|
+
const targetLocaleMessages = _messages.value[locales[i]] || {};
|
441
|
+
const messageValue = _context.messageResolver(targetLocaleMessages, key);
|
442
|
+
if (messageValue != null) {
|
443
|
+
messages2 = messageValue;
|
444
|
+
break;
|
445
|
+
}
|
446
|
+
}
|
447
|
+
return messages2;
|
448
|
+
}
|
449
|
+
function tm(key) {
|
450
|
+
const messages2 = resolveMessages(key);
|
451
|
+
return messages2 != null ? messages2 : __root ? __root.tm(key) || {} : {};
|
452
|
+
}
|
453
|
+
function getLocaleMessage(locale2) {
|
454
|
+
return _messages.value[locale2] || {};
|
455
|
+
}
|
456
|
+
function setLocaleMessage(locale2, message) {
|
457
|
+
if (flatJson) {
|
458
|
+
const _message = { [locale2]: message };
|
459
|
+
for (const key in _message) {
|
460
|
+
if (hasOwn(_message, key)) {
|
461
|
+
handleFlatJson(_message[key]);
|
462
|
+
}
|
463
|
+
}
|
464
|
+
message = _message[locale2];
|
465
|
+
}
|
466
|
+
_messages.value[locale2] = message;
|
467
|
+
_context.messages = _messages.value;
|
468
|
+
}
|
469
|
+
function mergeLocaleMessage(locale2, message) {
|
470
|
+
_messages.value[locale2] = _messages.value[locale2] || {};
|
471
|
+
const _message = { [locale2]: message };
|
472
|
+
if (flatJson) {
|
473
|
+
for (const key in _message) {
|
474
|
+
if (hasOwn(_message, key)) {
|
475
|
+
handleFlatJson(_message[key]);
|
476
|
+
}
|
477
|
+
}
|
478
|
+
}
|
479
|
+
message = _message[locale2];
|
480
|
+
deepCopy(message, _messages.value[locale2]);
|
481
|
+
_context.messages = _messages.value;
|
482
|
+
}
|
483
|
+
function getDateTimeFormat(locale2) {
|
484
|
+
return _datetimeFormats.value[locale2] || {};
|
485
|
+
}
|
486
|
+
function setDateTimeFormat(locale2, format2) {
|
487
|
+
_datetimeFormats.value[locale2] = format2;
|
488
|
+
_context.datetimeFormats = _datetimeFormats.value;
|
489
|
+
clearDateTimeFormat(_context, locale2, format2);
|
490
|
+
}
|
491
|
+
function mergeDateTimeFormat(locale2, format2) {
|
492
|
+
_datetimeFormats.value[locale2] = assign(_datetimeFormats.value[locale2] || {}, format2);
|
493
|
+
_context.datetimeFormats = _datetimeFormats.value;
|
494
|
+
clearDateTimeFormat(_context, locale2, format2);
|
495
|
+
}
|
496
|
+
function getNumberFormat(locale2) {
|
497
|
+
return _numberFormats.value[locale2] || {};
|
498
|
+
}
|
499
|
+
function setNumberFormat(locale2, format2) {
|
500
|
+
_numberFormats.value[locale2] = format2;
|
501
|
+
_context.numberFormats = _numberFormats.value;
|
502
|
+
clearNumberFormat(_context, locale2, format2);
|
503
|
+
}
|
504
|
+
function mergeNumberFormat(locale2, format2) {
|
505
|
+
_numberFormats.value[locale2] = assign(_numberFormats.value[locale2] || {}, format2);
|
506
|
+
_context.numberFormats = _numberFormats.value;
|
507
|
+
clearNumberFormat(_context, locale2, format2);
|
508
|
+
}
|
509
|
+
composerID++;
|
510
|
+
if (__root && inBrowser) {
|
511
|
+
watch(__root.locale, (val) => {
|
512
|
+
if (_inheritLocale) {
|
513
|
+
_locale.value = val;
|
514
|
+
_context.locale = val;
|
515
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
516
|
+
}
|
517
|
+
});
|
518
|
+
watch(__root.fallbackLocale, (val) => {
|
519
|
+
if (_inheritLocale) {
|
520
|
+
_fallbackLocale.value = val;
|
521
|
+
_context.fallbackLocale = val;
|
522
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
523
|
+
}
|
524
|
+
});
|
525
|
+
}
|
526
|
+
const composer = {
|
527
|
+
id: composerID,
|
528
|
+
locale,
|
529
|
+
fallbackLocale,
|
530
|
+
get inheritLocale() {
|
531
|
+
return _inheritLocale;
|
532
|
+
},
|
533
|
+
set inheritLocale(val) {
|
534
|
+
_inheritLocale = val;
|
535
|
+
if (val && __root) {
|
536
|
+
_locale.value = __root.locale.value;
|
537
|
+
_fallbackLocale.value = __root.fallbackLocale.value;
|
538
|
+
updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
|
539
|
+
}
|
540
|
+
},
|
541
|
+
availableLocales,
|
542
|
+
messages,
|
543
|
+
get modifiers() {
|
544
|
+
return _modifiers;
|
545
|
+
},
|
546
|
+
get pluralRules() {
|
547
|
+
return _pluralRules || {};
|
548
|
+
},
|
549
|
+
get isGlobal() {
|
550
|
+
return _isGlobal;
|
551
|
+
},
|
552
|
+
get missingWarn() {
|
553
|
+
return _missingWarn;
|
554
|
+
},
|
555
|
+
set missingWarn(val) {
|
556
|
+
_missingWarn = val;
|
557
|
+
_context.missingWarn = _missingWarn;
|
558
|
+
},
|
559
|
+
get fallbackWarn() {
|
560
|
+
return _fallbackWarn;
|
561
|
+
},
|
562
|
+
set fallbackWarn(val) {
|
563
|
+
_fallbackWarn = val;
|
564
|
+
_context.fallbackWarn = _fallbackWarn;
|
565
|
+
},
|
566
|
+
get fallbackRoot() {
|
567
|
+
return _fallbackRoot;
|
568
|
+
},
|
569
|
+
set fallbackRoot(val) {
|
570
|
+
_fallbackRoot = val;
|
571
|
+
},
|
572
|
+
get fallbackFormat() {
|
573
|
+
return _fallbackFormat;
|
574
|
+
},
|
575
|
+
set fallbackFormat(val) {
|
576
|
+
_fallbackFormat = val;
|
577
|
+
_context.fallbackFormat = _fallbackFormat;
|
578
|
+
},
|
579
|
+
get warnHtmlMessage() {
|
580
|
+
return _warnHtmlMessage;
|
581
|
+
},
|
582
|
+
set warnHtmlMessage(val) {
|
583
|
+
_warnHtmlMessage = val;
|
584
|
+
_context.warnHtmlMessage = val;
|
585
|
+
},
|
586
|
+
get escapeParameter() {
|
587
|
+
return _escapeParameter;
|
588
|
+
},
|
589
|
+
set escapeParameter(val) {
|
590
|
+
_escapeParameter = val;
|
591
|
+
_context.escapeParameter = val;
|
592
|
+
},
|
593
|
+
t,
|
594
|
+
getLocaleMessage,
|
595
|
+
setLocaleMessage,
|
596
|
+
mergeLocaleMessage,
|
597
|
+
getPostTranslationHandler,
|
598
|
+
setPostTranslationHandler,
|
599
|
+
getMissingHandler,
|
600
|
+
setMissingHandler,
|
601
|
+
[SetPluralRulesSymbol]: setPluralRules
|
602
|
+
};
|
603
|
+
{
|
604
|
+
composer.datetimeFormats = datetimeFormats;
|
605
|
+
composer.numberFormats = numberFormats;
|
606
|
+
composer.rt = rt;
|
607
|
+
composer.te = te;
|
608
|
+
composer.tm = tm;
|
609
|
+
composer.d = d;
|
610
|
+
composer.n = n;
|
611
|
+
composer.getDateTimeFormat = getDateTimeFormat;
|
612
|
+
composer.setDateTimeFormat = setDateTimeFormat;
|
613
|
+
composer.mergeDateTimeFormat = mergeDateTimeFormat;
|
614
|
+
composer.getNumberFormat = getNumberFormat;
|
615
|
+
composer.setNumberFormat = setNumberFormat;
|
616
|
+
composer.mergeNumberFormat = mergeNumberFormat;
|
617
|
+
composer[InejctWithOptionSymbol] = __injectWithOption;
|
618
|
+
composer[TranslateVNodeSymbol] = translateVNode;
|
619
|
+
composer[DatetimePartsSymbol] = datetimeParts;
|
620
|
+
composer[NumberPartsSymbol] = numberParts;
|
621
|
+
}
|
622
|
+
if (process.env.NODE_ENV !== "production") {
|
623
|
+
composer[EnableEmitter] = (emitter) => {
|
624
|
+
_context.__v_emitter = emitter;
|
625
|
+
};
|
626
|
+
composer[DisableEmitter] = () => {
|
627
|
+
_context.__v_emitter = void 0;
|
628
|
+
};
|
629
|
+
}
|
630
|
+
return composer;
|
631
|
+
}
|
632
|
+
const VUE_I18N_COMPONENT_TYPES = "vue-i18n: composer properties";
|
633
|
+
const VueDevToolsLabels = {
|
634
|
+
"vue-devtools-plugin-vue-i18n": "Vue I18n DevTools",
|
635
|
+
"vue-i18n-resource-inspector": "Vue I18n DevTools",
|
636
|
+
"vue-i18n-timeline": "Vue I18n"
|
637
|
+
};
|
638
|
+
const VueDevToolsPlaceholders = {
|
639
|
+
"vue-i18n-resource-inspector": "Search for scopes ..."
|
640
|
+
};
|
641
|
+
const VueDevToolsTimelineColors = {
|
642
|
+
"vue-i18n-timeline": 16764185
|
643
|
+
};
|
644
|
+
let devtoolsApi;
|
645
|
+
async function enableDevTools(app, i18n) {
|
646
|
+
return new Promise((resolve, reject) => {
|
647
|
+
try {
|
648
|
+
setupDevtoolsPlugin({
|
649
|
+
id: "vue-devtools-plugin-vue-i18n",
|
650
|
+
label: VueDevToolsLabels["vue-devtools-plugin-vue-i18n"],
|
651
|
+
packageName: "vue-i18n",
|
652
|
+
homepage: "https://vue-i18n.intlify.dev",
|
653
|
+
logo: "https://vue-i18n.intlify.dev/vue-i18n-devtools-logo.png",
|
654
|
+
componentStateTypes: [VUE_I18N_COMPONENT_TYPES],
|
655
|
+
app
|
656
|
+
// eslint-disable-line @typescript-eslint/no-explicit-any
|
657
|
+
}, (api) => {
|
658
|
+
devtoolsApi = api;
|
659
|
+
api.on.visitComponentTree(({ componentInstance, treeNode }) => {
|
660
|
+
updateComponentTreeTags(componentInstance, treeNode, i18n);
|
661
|
+
});
|
662
|
+
api.on.inspectComponent(({ componentInstance, instanceData }) => {
|
663
|
+
if (componentInstance.vnode.el && componentInstance.vnode.el.__VUE_I18N__ && instanceData) {
|
664
|
+
inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__);
|
665
|
+
}
|
666
|
+
});
|
667
|
+
api.addInspector({
|
668
|
+
id: "vue-i18n-resource-inspector",
|
669
|
+
label: VueDevToolsLabels["vue-i18n-resource-inspector"],
|
670
|
+
icon: "language",
|
671
|
+
treeFilterPlaceholder: VueDevToolsPlaceholders["vue-i18n-resource-inspector"]
|
672
|
+
});
|
673
|
+
api.on.getInspectorTree((payload) => {
|
674
|
+
if (payload.app === app && payload.inspectorId === "vue-i18n-resource-inspector") {
|
675
|
+
registerScope(payload, i18n);
|
676
|
+
}
|
677
|
+
});
|
678
|
+
const roots = /* @__PURE__ */ new Map();
|
679
|
+
api.on.getInspectorState(async (payload) => {
|
680
|
+
if (payload.app === app && payload.inspectorId === "vue-i18n-resource-inspector") {
|
681
|
+
api.unhighlightElement();
|
682
|
+
inspectScope(payload, i18n);
|
683
|
+
if (payload.nodeId === "global") {
|
684
|
+
if (!roots.has(payload.app)) {
|
685
|
+
const [root] = await api.getComponentInstances(payload.app);
|
686
|
+
roots.set(payload.app, root);
|
687
|
+
}
|
688
|
+
api.highlightElement(roots.get(payload.app));
|
689
|
+
} else {
|
690
|
+
const instance = getComponentInstance(payload.nodeId, i18n);
|
691
|
+
instance && api.highlightElement(instance);
|
692
|
+
}
|
693
|
+
}
|
694
|
+
});
|
695
|
+
api.on.editInspectorState((payload) => {
|
696
|
+
if (payload.app === app && payload.inspectorId === "vue-i18n-resource-inspector") {
|
697
|
+
editScope(payload, i18n);
|
698
|
+
}
|
699
|
+
});
|
700
|
+
api.addTimelineLayer({
|
701
|
+
id: "vue-i18n-timeline",
|
702
|
+
label: VueDevToolsLabels["vue-i18n-timeline"],
|
703
|
+
color: VueDevToolsTimelineColors["vue-i18n-timeline"]
|
704
|
+
});
|
705
|
+
resolve(true);
|
706
|
+
});
|
707
|
+
} catch (e) {
|
708
|
+
console.error(e);
|
709
|
+
reject(false);
|
710
|
+
}
|
711
|
+
});
|
712
|
+
}
|
713
|
+
function getI18nScopeLable(instance) {
|
714
|
+
return instance.type.name || instance.type.displayName || instance.type.__file || "Anonymous";
|
715
|
+
}
|
716
|
+
function updateComponentTreeTags(instance, treeNode, i18n) {
|
717
|
+
const global = i18n.global;
|
718
|
+
if (instance && instance.vnode.el && instance.vnode.el.__VUE_I18N__) {
|
719
|
+
if (instance.vnode.el.__VUE_I18N__ !== global) {
|
720
|
+
const tag = {
|
721
|
+
label: `i18n (${getI18nScopeLable(instance)} Scope)`,
|
722
|
+
textColor: 0,
|
723
|
+
backgroundColor: 16764185
|
724
|
+
};
|
725
|
+
treeNode.tags.push(tag);
|
726
|
+
}
|
727
|
+
}
|
728
|
+
}
|
729
|
+
function inspectComposer(instanceData, composer) {
|
730
|
+
const type = VUE_I18N_COMPONENT_TYPES;
|
731
|
+
instanceData.state.push({
|
732
|
+
type,
|
733
|
+
key: "locale",
|
734
|
+
editable: true,
|
735
|
+
value: composer.locale.value
|
736
|
+
});
|
737
|
+
instanceData.state.push({
|
738
|
+
type,
|
739
|
+
key: "availableLocales",
|
740
|
+
editable: false,
|
741
|
+
value: composer.availableLocales
|
742
|
+
});
|
743
|
+
instanceData.state.push({
|
744
|
+
type,
|
745
|
+
key: "fallbackLocale",
|
746
|
+
editable: true,
|
747
|
+
value: composer.fallbackLocale.value
|
748
|
+
});
|
749
|
+
instanceData.state.push({
|
750
|
+
type,
|
751
|
+
key: "inheritLocale",
|
752
|
+
editable: true,
|
753
|
+
value: composer.inheritLocale
|
754
|
+
});
|
755
|
+
instanceData.state.push({
|
756
|
+
type,
|
757
|
+
key: "messages",
|
758
|
+
editable: false,
|
759
|
+
value: getLocaleMessageValue(composer.messages.value)
|
760
|
+
});
|
761
|
+
{
|
762
|
+
instanceData.state.push({
|
763
|
+
type,
|
764
|
+
key: "datetimeFormats",
|
765
|
+
editable: false,
|
766
|
+
value: composer.datetimeFormats.value
|
767
|
+
});
|
768
|
+
instanceData.state.push({
|
769
|
+
type,
|
770
|
+
key: "numberFormats",
|
771
|
+
editable: false,
|
772
|
+
value: composer.numberFormats.value
|
773
|
+
});
|
774
|
+
}
|
775
|
+
}
|
776
|
+
function getLocaleMessageValue(messages) {
|
777
|
+
const value = {};
|
778
|
+
Object.keys(messages).forEach((key) => {
|
779
|
+
const v = messages[key];
|
780
|
+
if (isFunction(v) && "source" in v) {
|
781
|
+
value[key] = getMessageFunctionDetails(v);
|
782
|
+
} else if (isMessageAST(v) && v.loc && v.loc.source) {
|
783
|
+
value[key] = v.loc.source;
|
784
|
+
} else if (isObject(v)) {
|
785
|
+
value[key] = getLocaleMessageValue(v);
|
786
|
+
} else {
|
787
|
+
value[key] = v;
|
788
|
+
}
|
789
|
+
});
|
790
|
+
return value;
|
791
|
+
}
|
792
|
+
const ESC = {
|
793
|
+
"<": "<",
|
794
|
+
">": ">",
|
795
|
+
'"': """,
|
796
|
+
"&": "&"
|
797
|
+
};
|
798
|
+
function escape(s) {
|
799
|
+
return s.replace(/[<>"&]/g, escapeChar);
|
800
|
+
}
|
801
|
+
function escapeChar(a) {
|
802
|
+
return ESC[a] || a;
|
803
|
+
}
|
804
|
+
function getMessageFunctionDetails(func) {
|
805
|
+
const argString = func.source ? `("${escape(func.source)}")` : `(?)`;
|
806
|
+
return {
|
807
|
+
_custom: {
|
808
|
+
type: "function",
|
809
|
+
display: `<span>ƒ</span> ${argString}`
|
810
|
+
}
|
811
|
+
};
|
812
|
+
}
|
813
|
+
function registerScope(payload, i18n) {
|
814
|
+
payload.rootNodes.push({
|
815
|
+
id: "global",
|
816
|
+
label: "Global Scope"
|
817
|
+
});
|
818
|
+
const global = i18n.global;
|
819
|
+
for (const [keyInstance, instance] of i18n.__instances) {
|
820
|
+
const composer = instance;
|
821
|
+
if (global === composer) {
|
822
|
+
continue;
|
823
|
+
}
|
824
|
+
payload.rootNodes.push({
|
825
|
+
id: composer.id.toString(),
|
826
|
+
label: `${getI18nScopeLable(keyInstance)} Scope`
|
827
|
+
});
|
828
|
+
}
|
829
|
+
}
|
830
|
+
function getComponentInstance(nodeId, i18n) {
|
831
|
+
let instance = null;
|
832
|
+
if (nodeId !== "global") {
|
833
|
+
for (const [component, composer] of i18n.__instances.entries()) {
|
834
|
+
if (composer.id.toString() === nodeId) {
|
835
|
+
instance = component;
|
836
|
+
break;
|
837
|
+
}
|
838
|
+
}
|
839
|
+
}
|
840
|
+
return instance;
|
841
|
+
}
|
842
|
+
function getComposer$1(nodeId, i18n) {
|
843
|
+
if (nodeId === "global") {
|
844
|
+
return i18n.global;
|
845
|
+
} else {
|
846
|
+
const instance = Array.from(i18n.__instances.values()).find((item) => item.id.toString() === nodeId);
|
847
|
+
if (instance) {
|
848
|
+
return instance;
|
849
|
+
} else {
|
850
|
+
return null;
|
851
|
+
}
|
852
|
+
}
|
853
|
+
}
|
854
|
+
function inspectScope(payload, i18n) {
|
855
|
+
const composer = getComposer$1(payload.nodeId, i18n);
|
856
|
+
if (composer) {
|
857
|
+
payload.state = makeScopeInspectState(composer);
|
858
|
+
}
|
859
|
+
return null;
|
860
|
+
}
|
861
|
+
function makeScopeInspectState(composer) {
|
862
|
+
const state = {};
|
863
|
+
const localeType = "Locale related info";
|
864
|
+
const localeStates = [
|
865
|
+
{
|
866
|
+
type: localeType,
|
867
|
+
key: "locale",
|
868
|
+
editable: true,
|
869
|
+
value: composer.locale.value
|
870
|
+
},
|
871
|
+
{
|
872
|
+
type: localeType,
|
873
|
+
key: "fallbackLocale",
|
874
|
+
editable: true,
|
875
|
+
value: composer.fallbackLocale.value
|
876
|
+
},
|
877
|
+
{
|
878
|
+
type: localeType,
|
879
|
+
key: "availableLocales",
|
880
|
+
editable: false,
|
881
|
+
value: composer.availableLocales
|
882
|
+
},
|
883
|
+
{
|
884
|
+
type: localeType,
|
885
|
+
key: "inheritLocale",
|
886
|
+
editable: true,
|
887
|
+
value: composer.inheritLocale
|
888
|
+
}
|
889
|
+
];
|
890
|
+
state[localeType] = localeStates;
|
891
|
+
const localeMessagesType = "Locale messages info";
|
892
|
+
const localeMessagesStates = [
|
893
|
+
{
|
894
|
+
type: localeMessagesType,
|
895
|
+
key: "messages",
|
896
|
+
editable: false,
|
897
|
+
value: getLocaleMessageValue(composer.messages.value)
|
898
|
+
}
|
899
|
+
];
|
900
|
+
state[localeMessagesType] = localeMessagesStates;
|
901
|
+
{
|
902
|
+
const datetimeFormatsType = "Datetime formats info";
|
903
|
+
const datetimeFormatsStates = [
|
904
|
+
{
|
905
|
+
type: datetimeFormatsType,
|
906
|
+
key: "datetimeFormats",
|
907
|
+
editable: false,
|
908
|
+
value: composer.datetimeFormats.value
|
909
|
+
}
|
910
|
+
];
|
911
|
+
state[datetimeFormatsType] = datetimeFormatsStates;
|
912
|
+
const numberFormatsType = "Datetime formats info";
|
913
|
+
const numberFormatsStates = [
|
914
|
+
{
|
915
|
+
type: numberFormatsType,
|
916
|
+
key: "numberFormats",
|
917
|
+
editable: false,
|
918
|
+
value: composer.numberFormats.value
|
919
|
+
}
|
920
|
+
];
|
921
|
+
state[numberFormatsType] = numberFormatsStates;
|
922
|
+
}
|
923
|
+
return state;
|
924
|
+
}
|
925
|
+
function addTimelineEvent(event, payload) {
|
926
|
+
if (devtoolsApi) {
|
927
|
+
let groupId;
|
928
|
+
if (payload && "groupId" in payload) {
|
929
|
+
groupId = payload.groupId;
|
930
|
+
delete payload.groupId;
|
931
|
+
}
|
932
|
+
devtoolsApi.addTimelineEvent({
|
933
|
+
layerId: "vue-i18n-timeline",
|
934
|
+
event: {
|
935
|
+
title: event,
|
936
|
+
groupId,
|
937
|
+
time: Date.now(),
|
938
|
+
meta: {},
|
939
|
+
data: payload || {},
|
940
|
+
logType: event === "compile-error" ? "error" : event === "fallback" || event === "missing" ? "warning" : "default"
|
941
|
+
}
|
942
|
+
});
|
943
|
+
}
|
944
|
+
}
|
945
|
+
function editScope(payload, i18n) {
|
946
|
+
const composer = getComposer$1(payload.nodeId, i18n);
|
947
|
+
if (composer) {
|
948
|
+
const [field] = payload.path;
|
949
|
+
if (field === "locale" && isString(payload.state.value)) {
|
950
|
+
composer.locale.value = payload.state.value;
|
951
|
+
} else if (field === "fallbackLocale" && (isString(payload.state.value) || isArray(payload.state.value) || isObject(payload.state.value))) {
|
952
|
+
composer.fallbackLocale.value = payload.state.value;
|
953
|
+
} else if (field === "inheritLocale" && isBoolean(payload.state.value)) {
|
954
|
+
composer.inheritLocale = payload.state.value;
|
955
|
+
}
|
956
|
+
}
|
957
|
+
}
|
958
|
+
const BaseFormatPropsValidators = {
|
959
|
+
tag: {
|
960
|
+
type: [String, Object]
|
961
|
+
},
|
962
|
+
locale: {
|
963
|
+
type: String
|
964
|
+
},
|
965
|
+
scope: {
|
966
|
+
type: String,
|
967
|
+
// NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
|
968
|
+
validator: (val) => val === "parent" || val === "global",
|
969
|
+
default: "parent"
|
970
|
+
/* ComponentI18nScope */
|
971
|
+
},
|
972
|
+
i18n: {
|
973
|
+
type: Object
|
974
|
+
}
|
975
|
+
};
|
976
|
+
function getInterpolateArg({ slots }, keys) {
|
977
|
+
if (keys.length === 1 && keys[0] === "default") {
|
978
|
+
const ret = slots.default ? slots.default() : [];
|
979
|
+
return ret.reduce((slot, current) => {
|
980
|
+
return [
|
981
|
+
...slot,
|
982
|
+
// prettier-ignore
|
983
|
+
...current.type === Fragment ? current.children : [current]
|
984
|
+
];
|
985
|
+
}, []);
|
986
|
+
} else {
|
987
|
+
return keys.reduce((arg, key) => {
|
988
|
+
const slot = slots[key];
|
989
|
+
if (slot) {
|
990
|
+
arg[key] = slot();
|
991
|
+
}
|
992
|
+
return arg;
|
993
|
+
}, create());
|
994
|
+
}
|
995
|
+
}
|
996
|
+
function getFragmentableTag() {
|
997
|
+
return Fragment;
|
998
|
+
}
|
999
|
+
function isVNode(target) {
|
1000
|
+
return isArray(target) && !isString(target[0]);
|
1001
|
+
}
|
1002
|
+
function renderFormatter(props, context, slotKeys, partFormatter) {
|
1003
|
+
const { slots, attrs } = context;
|
1004
|
+
return () => {
|
1005
|
+
const options = { part: true };
|
1006
|
+
let overrides = create();
|
1007
|
+
if (props.locale) {
|
1008
|
+
options.locale = props.locale;
|
1009
|
+
}
|
1010
|
+
if (isString(props.format)) {
|
1011
|
+
options.key = props.format;
|
1012
|
+
} else if (isObject(props.format)) {
|
1013
|
+
if (isString(props.format.key)) {
|
1014
|
+
options.key = props.format.key;
|
1015
|
+
}
|
1016
|
+
overrides = Object.keys(props.format).reduce((options2, prop) => {
|
1017
|
+
return slotKeys.includes(prop) ? assign(create(), options2, { [prop]: props.format[prop] }) : options2;
|
1018
|
+
}, create());
|
1019
|
+
}
|
1020
|
+
const parts = partFormatter(...[props.value, options, overrides]);
|
1021
|
+
let children = [options.key];
|
1022
|
+
if (isArray(parts)) {
|
1023
|
+
children = parts.map((part, index) => {
|
1024
|
+
const slot = slots[part.type];
|
1025
|
+
const node = slot ? slot({ [part.type]: part.value, index, parts }) : [part.value];
|
1026
|
+
if (isVNode(node)) {
|
1027
|
+
node[0].key = `${part.type}-${index}`;
|
1028
|
+
}
|
1029
|
+
return node;
|
1030
|
+
});
|
1031
|
+
} else if (isString(parts)) {
|
1032
|
+
children = [parts];
|
1033
|
+
}
|
1034
|
+
const assignedAttrs = assign(create(), attrs);
|
1035
|
+
const tag = isString(props.tag) || isObject(props.tag) ? props.tag : getFragmentableTag();
|
1036
|
+
return h(tag, assignedAttrs, children);
|
1037
|
+
};
|
1038
|
+
}
|
1039
|
+
const DatetimeFormatImpl = /* @__PURE__ */ defineComponent({
|
1040
|
+
name: "i18n-d",
|
1041
|
+
// eslint-disable-line vue/component-definition-name-casing
|
1042
|
+
props: /* @__PURE__ */ assign({
|
1043
|
+
value: {
|
1044
|
+
type: [Number, Date],
|
1045
|
+
required: true
|
1046
|
+
},
|
1047
|
+
format: {
|
1048
|
+
type: [String, Object]
|
1049
|
+
}
|
1050
|
+
}, BaseFormatPropsValidators),
|
1051
|
+
setup(props, context) {
|
1052
|
+
const i18n = props.i18n || useI18n({
|
1053
|
+
useScope: props.scope,
|
1054
|
+
__useComponent: true
|
1055
|
+
});
|
1056
|
+
return renderFormatter(props, context, DATETIME_FORMAT_OPTIONS_KEYS, (...args) => (
|
1057
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1058
|
+
i18n[DatetimePartsSymbol](...args)
|
1059
|
+
));
|
1060
|
+
}
|
1061
|
+
});
|
1062
|
+
const DatetimeFormat = DatetimeFormatImpl;
|
1063
|
+
const NumberFormatImpl = /* @__PURE__ */ defineComponent({
|
1064
|
+
name: "i18n-n",
|
1065
|
+
// eslint-disable-line vue/component-definition-name-casing
|
1066
|
+
props: /* @__PURE__ */ assign({
|
1067
|
+
value: {
|
1068
|
+
type: Number,
|
1069
|
+
required: true
|
1070
|
+
},
|
1071
|
+
format: {
|
1072
|
+
type: [String, Object]
|
1073
|
+
}
|
1074
|
+
}, BaseFormatPropsValidators),
|
1075
|
+
setup(props, context) {
|
1076
|
+
const i18n = props.i18n || useI18n({
|
1077
|
+
useScope: props.scope,
|
1078
|
+
__useComponent: true
|
1079
|
+
});
|
1080
|
+
return renderFormatter(props, context, NUMBER_FORMAT_OPTIONS_KEYS, (...args) => (
|
1081
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1082
|
+
i18n[NumberPartsSymbol](...args)
|
1083
|
+
));
|
1084
|
+
}
|
1085
|
+
});
|
1086
|
+
const NumberFormat = NumberFormatImpl;
|
1087
|
+
const TranslationImpl = /* @__PURE__ */ defineComponent({
|
1088
|
+
name: "i18n-t",
|
1089
|
+
// eslint-disable-line vue/component-definition-name-casing
|
1090
|
+
props: /* @__PURE__ */ assign({}, {
|
1091
|
+
keypath: {
|
1092
|
+
type: String,
|
1093
|
+
required: true
|
1094
|
+
},
|
1095
|
+
plural: {
|
1096
|
+
type: [Number, String],
|
1097
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1098
|
+
validator: (val) => isNumber(val) || !isNaN(val)
|
1099
|
+
}
|
1100
|
+
}, BaseFormatPropsValidators),
|
1101
|
+
setup(props, context) {
|
1102
|
+
const { slots, attrs } = context;
|
1103
|
+
const i18n = props.i18n || useI18n({
|
1104
|
+
useScope: props.scope,
|
1105
|
+
__useComponent: true
|
1106
|
+
});
|
1107
|
+
return () => {
|
1108
|
+
const keys = Object.keys(slots).filter((key) => key[0] !== "_");
|
1109
|
+
const options = create();
|
1110
|
+
if (props.locale) {
|
1111
|
+
options.locale = props.locale;
|
1112
|
+
}
|
1113
|
+
if (props.plural !== void 0) {
|
1114
|
+
options.plural = isString(props.plural) ? +props.plural : props.plural;
|
1115
|
+
}
|
1116
|
+
const arg = getInterpolateArg(context, keys);
|
1117
|
+
const children = i18n[TranslateVNodeSymbol](props.keypath, arg, options);
|
1118
|
+
const assignedAttrs = assign(create(), attrs);
|
1119
|
+
const tag = isString(props.tag) || isObject(props.tag) ? props.tag : getFragmentableTag();
|
1120
|
+
return h(tag, assignedAttrs, children);
|
1121
|
+
};
|
1122
|
+
}
|
1123
|
+
});
|
1124
|
+
const Translation = TranslationImpl;
|
1125
|
+
function apply(app, ...options) {
|
1126
|
+
const pluginOptions = isPlainObject(options[0]) ? options[0] : {};
|
1127
|
+
const globalInstall = isBoolean(pluginOptions.globalInstall) ? pluginOptions.globalInstall : true;
|
1128
|
+
if (globalInstall) {
|
1129
|
+
[Translation.name, "I18nT"].forEach((name) => app.component(name, Translation));
|
1130
|
+
[NumberFormat.name, "I18nN"].forEach((name) => app.component(name, NumberFormat));
|
1131
|
+
[DatetimeFormat.name, "I18nD"].forEach((name) => app.component(name, DatetimeFormat));
|
1132
|
+
}
|
1133
|
+
}
|
1134
|
+
const I18nInjectionKey = /* @__PURE__ */ makeSymbol("global-vue-i18n");
|
1135
|
+
function createI18n(options = {}) {
|
1136
|
+
const __globalInjection = isBoolean(options.globalInjection) ? options.globalInjection : true;
|
1137
|
+
const __instances = /* @__PURE__ */ new Map();
|
1138
|
+
const [globalScope, __global] = createGlobal(options);
|
1139
|
+
const symbol = /* @__PURE__ */ makeSymbol(process.env.NODE_ENV !== "production" ? "vue-i18n" : "");
|
1140
|
+
function __getInstance(component) {
|
1141
|
+
return __instances.get(component) || null;
|
1142
|
+
}
|
1143
|
+
function __setInstance(component, instance) {
|
1144
|
+
__instances.set(component, instance);
|
1145
|
+
}
|
1146
|
+
function __deleteInstance(component) {
|
1147
|
+
__instances.delete(component);
|
1148
|
+
}
|
1149
|
+
const i18n = {
|
1150
|
+
// install plugin
|
1151
|
+
async install(app, ...options2) {
|
1152
|
+
if ((process.env.NODE_ENV !== "production" || false) && true) {
|
1153
|
+
app.__VUE_I18N__ = i18n;
|
1154
|
+
}
|
1155
|
+
app.__VUE_I18N_SYMBOL__ = symbol;
|
1156
|
+
app.provide(app.__VUE_I18N_SYMBOL__, i18n);
|
1157
|
+
if (isPlainObject(options2[0])) {
|
1158
|
+
const opts = options2[0];
|
1159
|
+
i18n.__composerExtend = opts.__composerExtend;
|
1160
|
+
}
|
1161
|
+
let globalReleaseHandler = null;
|
1162
|
+
if (__globalInjection) {
|
1163
|
+
globalReleaseHandler = injectGlobalFields(app, i18n.global);
|
1164
|
+
}
|
1165
|
+
if (__VUE_I18N_FULL_INSTALL__) {
|
1166
|
+
apply(app, ...options2);
|
1167
|
+
}
|
1168
|
+
const unmountApp = app.unmount;
|
1169
|
+
app.unmount = () => {
|
1170
|
+
globalReleaseHandler && globalReleaseHandler();
|
1171
|
+
i18n.dispose();
|
1172
|
+
unmountApp();
|
1173
|
+
};
|
1174
|
+
if ((process.env.NODE_ENV !== "production" || false) && true) {
|
1175
|
+
const ret = await enableDevTools(app, i18n);
|
1176
|
+
if (!ret) {
|
1177
|
+
throw createI18nError(I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN);
|
1178
|
+
}
|
1179
|
+
const emitter = createEmitter();
|
1180
|
+
const _composer = __global;
|
1181
|
+
_composer[EnableEmitter] && _composer[EnableEmitter](emitter);
|
1182
|
+
emitter.on("*", addTimelineEvent);
|
1183
|
+
}
|
1184
|
+
},
|
1185
|
+
// global accessor
|
1186
|
+
get global() {
|
1187
|
+
return __global;
|
1188
|
+
},
|
1189
|
+
dispose() {
|
1190
|
+
globalScope.stop();
|
1191
|
+
},
|
1192
|
+
// @internal
|
1193
|
+
__instances,
|
1194
|
+
// @internal
|
1195
|
+
__getInstance,
|
1196
|
+
// @internal
|
1197
|
+
__setInstance,
|
1198
|
+
// @internal
|
1199
|
+
__deleteInstance
|
1200
|
+
};
|
1201
|
+
return i18n;
|
1202
|
+
}
|
1203
|
+
function useI18n(options = {}) {
|
1204
|
+
const instance = getCurrentInstance();
|
1205
|
+
if (instance == null) {
|
1206
|
+
throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP);
|
1207
|
+
}
|
1208
|
+
if (!instance.isCE && instance.appContext.app != null && !instance.appContext.app.__VUE_I18N_SYMBOL__) {
|
1209
|
+
throw createI18nError(I18nErrorCodes.NOT_INSTALLED);
|
1210
|
+
}
|
1211
|
+
const i18n = getI18nInstance(instance);
|
1212
|
+
const gl = getGlobalComposer(i18n);
|
1213
|
+
const componentOptions = getComponentOptions(instance);
|
1214
|
+
const scope = getScope(options, componentOptions);
|
1215
|
+
if (scope === "global") {
|
1216
|
+
adjustI18nResources(gl, options, componentOptions);
|
1217
|
+
return gl;
|
1218
|
+
}
|
1219
|
+
if (scope === "parent") {
|
1220
|
+
let composer2 = getComposer(i18n, instance, options.__useComponent);
|
1221
|
+
if (composer2 == null) {
|
1222
|
+
if (process.env.NODE_ENV !== "production") {
|
1223
|
+
warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
|
1224
|
+
}
|
1225
|
+
composer2 = gl;
|
1226
|
+
}
|
1227
|
+
return composer2;
|
1228
|
+
}
|
1229
|
+
const i18nInternal = i18n;
|
1230
|
+
let composer = i18nInternal.__getInstance(instance);
|
1231
|
+
if (composer == null) {
|
1232
|
+
const composerOptions = assign({}, options);
|
1233
|
+
if ("__i18n" in componentOptions) {
|
1234
|
+
composerOptions.__i18n = componentOptions.__i18n;
|
1235
|
+
}
|
1236
|
+
if (gl) {
|
1237
|
+
composerOptions.__root = gl;
|
1238
|
+
}
|
1239
|
+
composer = createComposer(composerOptions);
|
1240
|
+
if (i18nInternal.__composerExtend) {
|
1241
|
+
composer[DisposeSymbol] = i18nInternal.__composerExtend(composer);
|
1242
|
+
}
|
1243
|
+
setupLifeCycle(i18nInternal, instance, composer);
|
1244
|
+
i18nInternal.__setInstance(instance, composer);
|
1245
|
+
} else {
|
1246
|
+
if (process.env.NODE_ENV !== "production" && scope === "local") {
|
1247
|
+
throw createI18nError(I18nErrorCodes.DUPLICATE_USE_I18N_CALLING);
|
1248
|
+
}
|
1249
|
+
}
|
1250
|
+
return composer;
|
1251
|
+
}
|
1252
|
+
function createGlobal(options) {
|
1253
|
+
const scope = effectScope();
|
1254
|
+
const obj = scope.run(() => createComposer(options));
|
1255
|
+
if (obj == null) {
|
1256
|
+
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
1257
|
+
}
|
1258
|
+
return [scope, obj];
|
1259
|
+
}
|
1260
|
+
function getI18nInstance(instance) {
|
1261
|
+
const i18n = inject(!instance.isCE ? instance.appContext.app.__VUE_I18N_SYMBOL__ : I18nInjectionKey);
|
1262
|
+
if (!i18n) {
|
1263
|
+
throw createI18nError(!instance.isCE ? I18nErrorCodes.UNEXPECTED_ERROR : I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE);
|
1264
|
+
}
|
1265
|
+
return i18n;
|
1266
|
+
}
|
1267
|
+
function getScope(options, componentOptions) {
|
1268
|
+
return isEmptyObject(options) ? "__i18n" in componentOptions ? "local" : "global" : !options.useScope ? "local" : options.useScope;
|
1269
|
+
}
|
1270
|
+
function getGlobalComposer(i18n) {
|
1271
|
+
return i18n.global;
|
1272
|
+
}
|
1273
|
+
function getComposer(i18n, target, useComponent = false) {
|
1274
|
+
let composer = null;
|
1275
|
+
const root = target.root;
|
1276
|
+
let current = getParentComponentInstance(target, useComponent);
|
1277
|
+
while (current != null) {
|
1278
|
+
const i18nInternal = i18n;
|
1279
|
+
composer = i18nInternal.__getInstance(current);
|
1280
|
+
if (composer != null) {
|
1281
|
+
break;
|
1282
|
+
}
|
1283
|
+
if (root === current) {
|
1284
|
+
break;
|
1285
|
+
}
|
1286
|
+
current = current.parent;
|
1287
|
+
}
|
1288
|
+
return composer;
|
1289
|
+
}
|
1290
|
+
function getParentComponentInstance(target, useComponent = false) {
|
1291
|
+
if (target == null) {
|
1292
|
+
return null;
|
1293
|
+
}
|
1294
|
+
return !useComponent ? target.parent : target.vnode.ctx || target.parent;
|
1295
|
+
}
|
1296
|
+
function setupLifeCycle(i18n, target, composer) {
|
1297
|
+
let emitter = null;
|
1298
|
+
onMounted(() => {
|
1299
|
+
if ((process.env.NODE_ENV !== "production" || false) && true && target.vnode.el) {
|
1300
|
+
target.vnode.el.__VUE_I18N__ = composer;
|
1301
|
+
emitter = createEmitter();
|
1302
|
+
const _composer = composer;
|
1303
|
+
_composer[EnableEmitter] && _composer[EnableEmitter](emitter);
|
1304
|
+
emitter.on("*", addTimelineEvent);
|
1305
|
+
}
|
1306
|
+
}, target);
|
1307
|
+
onUnmounted(() => {
|
1308
|
+
const _composer = composer;
|
1309
|
+
if ((process.env.NODE_ENV !== "production" || false) && true && target.vnode.el && target.vnode.el.__VUE_I18N__) {
|
1310
|
+
emitter && emitter.off("*", addTimelineEvent);
|
1311
|
+
_composer[DisableEmitter] && _composer[DisableEmitter]();
|
1312
|
+
delete target.vnode.el.__VUE_I18N__;
|
1313
|
+
}
|
1314
|
+
i18n.__deleteInstance(target);
|
1315
|
+
const dispose = _composer[DisposeSymbol];
|
1316
|
+
if (dispose) {
|
1317
|
+
dispose();
|
1318
|
+
delete _composer[DisposeSymbol];
|
1319
|
+
}
|
1320
|
+
}, target);
|
1321
|
+
}
|
1322
|
+
const globalExportProps = [
|
1323
|
+
"locale",
|
1324
|
+
"fallbackLocale",
|
1325
|
+
"availableLocales"
|
1326
|
+
];
|
1327
|
+
const globalExportMethods = ["t", "rt", "d", "n", "tm", "te"];
|
1328
|
+
function injectGlobalFields(app, composer) {
|
1329
|
+
const i18n = /* @__PURE__ */ Object.create(null);
|
1330
|
+
globalExportProps.forEach((prop) => {
|
1331
|
+
const desc = Object.getOwnPropertyDescriptor(composer, prop);
|
1332
|
+
if (!desc) {
|
1333
|
+
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
1334
|
+
}
|
1335
|
+
const wrap = isRef(desc.value) ? {
|
1336
|
+
get() {
|
1337
|
+
return desc.value.value;
|
1338
|
+
},
|
1339
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1340
|
+
set(val) {
|
1341
|
+
desc.value.value = val;
|
1342
|
+
}
|
1343
|
+
} : {
|
1344
|
+
get() {
|
1345
|
+
return desc.get && desc.get();
|
1346
|
+
}
|
1347
|
+
};
|
1348
|
+
Object.defineProperty(i18n, prop, wrap);
|
1349
|
+
});
|
1350
|
+
app.config.globalProperties.$i18n = i18n;
|
1351
|
+
globalExportMethods.forEach((method) => {
|
1352
|
+
const desc = Object.getOwnPropertyDescriptor(composer, method);
|
1353
|
+
if (!desc || !desc.value) {
|
1354
|
+
throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
|
1355
|
+
}
|
1356
|
+
Object.defineProperty(app.config.globalProperties, `$${method}`, desc);
|
1357
|
+
});
|
1358
|
+
const dispose = () => {
|
1359
|
+
delete app.config.globalProperties.$i18n;
|
1360
|
+
globalExportMethods.forEach((method) => {
|
1361
|
+
delete app.config.globalProperties[`$${method}`];
|
1362
|
+
});
|
1363
|
+
};
|
1364
|
+
return dispose;
|
1365
|
+
}
|
1366
|
+
{
|
1367
|
+
initFeatureFlags();
|
1368
|
+
}
|
1369
|
+
if (process.env.NODE_ENV !== "production" || __INTLIFY_PROD_DEVTOOLS__) {
|
1370
|
+
const target = getGlobalThis();
|
1371
|
+
target.__INTLIFY__ = true;
|
1372
|
+
setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
|
1373
|
+
}
|
1374
|
+
if (process.env.NODE_ENV !== "production") ;
|
1375
|
+
export {
|
1376
|
+
I18nInjectionKey,
|
1377
|
+
VERSION,
|
1378
|
+
createI18n,
|
1379
|
+
initFeatureFlags,
|
1380
|
+
useI18n
|
1381
|
+
};
|