@intlify/core 9.3.0-beta.17 → 9.3.0-beta.18

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.
Files changed (59) hide show
  1. package/dist/core.cjs +6 -6
  2. package/dist/core.esm-browser.js +3005 -3000
  3. package/dist/core.esm-browser.prod.js +2 -2
  4. package/dist/core.global.js +3005 -3000
  5. package/dist/core.global.prod.js +2 -2
  6. package/dist/core.mjs +6 -6
  7. package/dist/core.prod.cjs +6 -6
  8. package/dist/core.runtime.esm-browser.js +1677 -1672
  9. package/dist/core.runtime.esm-browser.prod.js +2 -2
  10. package/dist/core.runtime.global.js +1677 -1672
  11. package/dist/core.runtime.global.prod.js +2 -2
  12. package/dist/core.runtime.mjs +4 -4
  13. package/dist/e2e/bridge/basic.spec.d.ts +1 -1
  14. package/dist/e2e/bridge/component.spec.d.ts +1 -1
  15. package/dist/e2e/bridge/components/datetime-format.spec.d.ts +1 -1
  16. package/dist/e2e/bridge/components/number-format.spec.d.ts +1 -1
  17. package/dist/e2e/bridge/components/translation.spec.d.ts +1 -1
  18. package/dist/e2e/bridge/plural.spec.d.ts +1 -1
  19. package/dist/e2e/bridge/scope/global.spec.d.ts +1 -1
  20. package/dist/e2e/bridge/scope/inherit-locale.spec.d.ts +1 -1
  21. package/dist/e2e/bridge/scope/local.spec.d.ts +1 -1
  22. package/dist/e2e/components/datetime-format.spec.d.ts +1 -1
  23. package/dist/e2e/components/number-format.spec.d.ts +1 -1
  24. package/dist/e2e/components/translation.spec.d.ts +1 -1
  25. package/dist/e2e/composition.spec.d.ts +1 -1
  26. package/dist/e2e/datetime.spec.d.ts +1 -1
  27. package/dist/e2e/directive/basic.spec.d.ts +1 -1
  28. package/dist/e2e/directive/object.spec.d.ts +1 -1
  29. package/dist/e2e/directive/plural.spec.d.ts +1 -1
  30. package/dist/e2e/directive/preserve.spec.d.ts +1 -1
  31. package/dist/e2e/fallback/basic.spec.d.ts +1 -1
  32. package/dist/e2e/fallback/component.spec.d.ts +1 -1
  33. package/dist/e2e/fallback/default-format.spec.d.ts +1 -1
  34. package/dist/e2e/fallback/format.spec.d.ts +1 -1
  35. package/dist/e2e/fallback/option.spec.d.ts +1 -1
  36. package/dist/e2e/fallback/suppress.spec.d.ts +1 -1
  37. package/dist/e2e/formatting/linked.spec.d.ts +1 -1
  38. package/dist/e2e/formatting/list.spec.d.ts +1 -1
  39. package/dist/e2e/formatting/literal.spec.d.ts +1 -1
  40. package/dist/e2e/formatting/named.spec.d.ts +1 -1
  41. package/dist/e2e/formatting/ruby.spec.d.ts +1 -1
  42. package/dist/e2e/functions/linked.spec.d.ts +1 -1
  43. package/dist/e2e/functions/list.spec.d.ts +1 -1
  44. package/dist/e2e/functions/named.spec.d.ts +1 -1
  45. package/dist/e2e/functions/plural.spec.d.ts +1 -1
  46. package/dist/e2e/helper.d.ts +8 -8
  47. package/dist/e2e/missing/handler.spec.d.ts +1 -1
  48. package/dist/e2e/missing/option.spec.d.ts +1 -1
  49. package/dist/e2e/missing/suppress.spec.d.ts +1 -1
  50. package/dist/e2e/number.spec.d.ts +1 -1
  51. package/dist/e2e/plural/basic.spec.d.ts +1 -1
  52. package/dist/e2e/plural/custom.spec.d.ts +1 -1
  53. package/dist/e2e/scope/global.spec.d.ts +1 -1
  54. package/dist/e2e/scope/inherit-locale.spec.d.ts +1 -1
  55. package/dist/e2e/scope/local.spec.d.ts +1 -1
  56. package/dist/e2e/started.spec.d.ts +1 -1
  57. package/dist/scripts/vitest.globalSetup.d.ts +1 -1
  58. package/dist/scripts/vitest.setup.d.ts +1 -1
  59. package/package.json +3 -3
@@ -1,1709 +1,1714 @@
1
1
  /*!
2
- * core v9.3.0-beta.17
2
+ * core v9.3.0-beta.18
3
3
  * (c) 2023 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
6
- /**
7
- * Original Utilities
8
- * written by kazuya kawaguchi
9
- */
10
- const inBrowser = typeof window !== 'undefined';
11
- let mark;
12
- let measure;
13
- {
14
- const perf = inBrowser && window.performance;
15
- if (perf &&
16
- perf.mark &&
17
- perf.measure &&
18
- perf.clearMarks &&
19
- // @ts-ignore browser compat
20
- perf.clearMeasures) {
21
- mark = (tag) => {
22
- perf.mark(tag);
23
- };
24
- measure = (name, startTag, endTag) => {
25
- perf.measure(name, startTag, endTag);
26
- perf.clearMarks(startTag);
27
- perf.clearMarks(endTag);
28
- };
29
- }
30
- }
31
- const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
32
- /* eslint-disable */
33
- function format(message, ...args) {
34
- if (args.length === 1 && isObject(args[0])) {
35
- args = args[0];
36
- }
37
- if (!args || !args.hasOwnProperty) {
38
- args = {};
39
- }
40
- return message.replace(RE_ARGS, (match, identifier) => {
41
- return args.hasOwnProperty(identifier) ? args[identifier] : '';
42
- });
43
- }
44
- const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
45
- const friendlyJSONstringify = (json) => JSON.stringify(json)
46
- .replace(/\u2028/g, '\\u2028')
47
- .replace(/\u2029/g, '\\u2029')
48
- .replace(/\u0027/g, '\\u0027');
49
- const isNumber = (val) => typeof val === 'number' && isFinite(val);
50
- const isDate = (val) => toTypeString(val) === '[object Date]';
51
- const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
52
- const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
53
- function warn(msg, err) {
54
- if (typeof console !== 'undefined') {
55
- console.warn(`[intlify] ` + msg);
56
- /* istanbul ignore if */
57
- if (err) {
58
- console.warn(err.stack);
59
- }
60
- }
61
- }
62
- const assign = Object.assign;
63
- function escapeHtml(rawText) {
64
- return rawText
65
- .replace(/</g, '&lt;')
66
- .replace(/>/g, '&gt;')
67
- .replace(/"/g, '&quot;')
68
- .replace(/'/g, '&apos;');
69
- }
70
- /* eslint-enable */
71
- /**
72
- * Useful Utilities By Evan you
73
- * Modified by kazuya kawaguchi
74
- * MIT License
75
- * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
76
- * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
77
- */
78
- const isArray = Array.isArray;
79
- const isFunction = (val) => typeof val === 'function';
80
- const isString = (val) => typeof val === 'string';
81
- const isBoolean = (val) => typeof val === 'boolean';
82
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
- const isObject = (val) => val !== null && typeof val === 'object';
84
- const objectToString = Object.prototype.toString;
85
- const toTypeString = (value) => objectToString.call(value);
86
- const isPlainObject = (val) => toTypeString(val) === '[object Object]';
87
- // for converting list and named values to displayed strings.
88
- const toDisplayString = (val) => {
89
- return val == null
90
- ? ''
91
- : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
92
- ? JSON.stringify(val, null, 2)
93
- : String(val);
94
- };
95
- const RANGE = 2;
96
- function generateCodeFrame(source, start = 0, end = source.length) {
97
- const lines = source.split(/\r?\n/);
98
- let count = 0;
99
- const res = [];
100
- for (let i = 0; i < lines.length; i++) {
101
- count += lines[i].length + 1;
102
- if (count >= start) {
103
- for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
104
- if (j < 0 || j >= lines.length)
105
- continue;
106
- const line = j + 1;
107
- res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
108
- const lineLength = lines[j].length;
109
- if (j === i) {
110
- // push underline
111
- const pad = start - (count - lineLength) + 1;
112
- const length = Math.max(1, end > count ? lineLength - pad : end - start);
113
- res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
114
- }
115
- else if (j > i) {
116
- if (end > count) {
117
- const length = Math.max(Math.min(end - count, lineLength), 1);
118
- res.push(` | ` + '^'.repeat(length));
119
- }
120
- count += lineLength + 1;
121
- }
122
- }
123
- break;
124
- }
125
- }
126
- return res.join('\n');
6
+ /**
7
+ * Original Utilities
8
+ * written by kazuya kawaguchi
9
+ */
10
+ const inBrowser = typeof window !== 'undefined';
11
+ let mark;
12
+ let measure;
13
+ {
14
+ const perf = inBrowser && window.performance;
15
+ if (perf &&
16
+ perf.mark &&
17
+ perf.measure &&
18
+ perf.clearMarks &&
19
+ // @ts-ignore browser compat
20
+ perf.clearMeasures) {
21
+ mark = (tag) => {
22
+ perf.mark(tag);
23
+ };
24
+ measure = (name, startTag, endTag) => {
25
+ perf.measure(name, startTag, endTag);
26
+ perf.clearMarks(startTag);
27
+ perf.clearMarks(endTag);
28
+ };
29
+ }
30
+ }
31
+ const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
32
+ /* eslint-disable */
33
+ function format(message, ...args) {
34
+ if (args.length === 1 && isObject(args[0])) {
35
+ args = args[0];
36
+ }
37
+ if (!args || !args.hasOwnProperty) {
38
+ args = {};
39
+ }
40
+ return message.replace(RE_ARGS, (match, identifier) => {
41
+ return args.hasOwnProperty(identifier) ? args[identifier] : '';
42
+ });
43
+ }
44
+ const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
45
+ const friendlyJSONstringify = (json) => JSON.stringify(json)
46
+ .replace(/\u2028/g, '\\u2028')
47
+ .replace(/\u2029/g, '\\u2029')
48
+ .replace(/\u0027/g, '\\u0027');
49
+ const isNumber = (val) => typeof val === 'number' && isFinite(val);
50
+ const isDate = (val) => toTypeString(val) === '[object Date]';
51
+ const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
52
+ const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
53
+ function warn(msg, err) {
54
+ if (typeof console !== 'undefined') {
55
+ console.warn(`[intlify] ` + msg);
56
+ /* istanbul ignore if */
57
+ if (err) {
58
+ console.warn(err.stack);
59
+ }
60
+ }
61
+ }
62
+ const assign = Object.assign;
63
+ function escapeHtml(rawText) {
64
+ return rawText
65
+ .replace(/</g, '&lt;')
66
+ .replace(/>/g, '&gt;')
67
+ .replace(/"/g, '&quot;')
68
+ .replace(/'/g, '&apos;');
69
+ }
70
+ /* eslint-enable */
71
+ /**
72
+ * Useful Utilities By Evan you
73
+ * Modified by kazuya kawaguchi
74
+ * MIT License
75
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
76
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
77
+ */
78
+ const isArray = Array.isArray;
79
+ const isFunction = (val) => typeof val === 'function';
80
+ const isString = (val) => typeof val === 'string';
81
+ const isBoolean = (val) => typeof val === 'boolean';
82
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
+ const isObject = (val) => val !== null && typeof val === 'object';
84
+ const objectToString = Object.prototype.toString;
85
+ const toTypeString = (value) => objectToString.call(value);
86
+ const isPlainObject = (val) => {
87
+ if (!isObject(val))
88
+ return false;
89
+ const proto = Object.getPrototypeOf(val);
90
+ return proto === null || proto.constructor === Object;
91
+ };
92
+ // for converting list and named values to displayed strings.
93
+ const toDisplayString = (val) => {
94
+ return val == null
95
+ ? ''
96
+ : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
97
+ ? JSON.stringify(val, null, 2)
98
+ : String(val);
99
+ };
100
+ const RANGE = 2;
101
+ function generateCodeFrame(source, start = 0, end = source.length) {
102
+ const lines = source.split(/\r?\n/);
103
+ let count = 0;
104
+ const res = [];
105
+ for (let i = 0; i < lines.length; i++) {
106
+ count += lines[i].length + 1;
107
+ if (count >= start) {
108
+ for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
109
+ if (j < 0 || j >= lines.length)
110
+ continue;
111
+ const line = j + 1;
112
+ res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
113
+ const lineLength = lines[j].length;
114
+ if (j === i) {
115
+ // push underline
116
+ const pad = start - (count - lineLength) + 1;
117
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
118
+ res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
119
+ }
120
+ else if (j > i) {
121
+ if (end > count) {
122
+ const length = Math.max(Math.min(end - count, lineLength), 1);
123
+ res.push(` | ` + '^'.repeat(length));
124
+ }
125
+ count += lineLength + 1;
126
+ }
127
+ }
128
+ break;
129
+ }
130
+ }
131
+ return res.join('\n');
127
132
  }
128
133
 
129
- const CompileErrorCodes = {
130
- // tokenizer error codes
131
- EXPECTED_TOKEN: 1,
132
- INVALID_TOKEN_IN_PLACEHOLDER: 2,
133
- UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
134
- UNKNOWN_ESCAPE_SEQUENCE: 4,
135
- INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
136
- UNBALANCED_CLOSING_BRACE: 6,
137
- UNTERMINATED_CLOSING_BRACE: 7,
138
- EMPTY_PLACEHOLDER: 8,
139
- NOT_ALLOW_NEST_PLACEHOLDER: 9,
140
- INVALID_LINKED_FORMAT: 10,
141
- // parser error codes
142
- MUST_HAVE_MESSAGES_IN_PLURAL: 11,
143
- UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
144
- UNEXPECTED_EMPTY_LINKED_KEY: 13,
145
- UNEXPECTED_LEXICAL_ANALYSIS: 14,
146
- // Special value for higher-order compilers to pick up the last code
147
- // to avoid collision of error codes. This should always be kept as the last
148
- // item.
149
- __EXTEND_POINT__: 15
150
- };
151
- /** @internal */
152
- const errorMessages$1 = {
153
- // tokenizer error messages
154
- [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
155
- [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
156
- [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
157
- [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
158
- [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
159
- [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
160
- [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
161
- [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
162
- [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
163
- [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
164
- // parser error messages
165
- [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
166
- [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
167
- [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
168
- [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`
169
- };
170
- function createCompileError(code, loc, options = {}) {
171
- const { domain, messages, args } = options;
172
- const msg = format((messages || errorMessages$1)[code] || '', ...(args || []))
173
- ;
174
- const error = new SyntaxError(String(msg));
175
- error.code = code;
176
- if (loc) {
177
- error.location = loc;
178
- }
179
- error.domain = domain;
180
- return error;
134
+ const CompileErrorCodes = {
135
+ // tokenizer error codes
136
+ EXPECTED_TOKEN: 1,
137
+ INVALID_TOKEN_IN_PLACEHOLDER: 2,
138
+ UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
139
+ UNKNOWN_ESCAPE_SEQUENCE: 4,
140
+ INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
141
+ UNBALANCED_CLOSING_BRACE: 6,
142
+ UNTERMINATED_CLOSING_BRACE: 7,
143
+ EMPTY_PLACEHOLDER: 8,
144
+ NOT_ALLOW_NEST_PLACEHOLDER: 9,
145
+ INVALID_LINKED_FORMAT: 10,
146
+ // parser error codes
147
+ MUST_HAVE_MESSAGES_IN_PLURAL: 11,
148
+ UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
149
+ UNEXPECTED_EMPTY_LINKED_KEY: 13,
150
+ UNEXPECTED_LEXICAL_ANALYSIS: 14,
151
+ // Special value for higher-order compilers to pick up the last code
152
+ // to avoid collision of error codes. This should always be kept as the last
153
+ // item.
154
+ __EXTEND_POINT__: 15
155
+ };
156
+ /** @internal */
157
+ const errorMessages$1 = {
158
+ // tokenizer error messages
159
+ [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
160
+ [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
161
+ [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
162
+ [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
163
+ [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
164
+ [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
165
+ [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
166
+ [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
167
+ [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
168
+ [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
169
+ // parser error messages
170
+ [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
171
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
172
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
173
+ [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`
174
+ };
175
+ function createCompileError(code, loc, options = {}) {
176
+ const { domain, messages, args } = options;
177
+ const msg = format((messages || errorMessages$1)[code] || '', ...(args || []))
178
+ ;
179
+ const error = new SyntaxError(String(msg));
180
+ error.code = code;
181
+ if (loc) {
182
+ error.location = loc;
183
+ }
184
+ error.domain = domain;
185
+ return error;
181
186
  }
182
187
 
183
- const pathStateMachine = [];
184
- pathStateMachine[0 /* States.BEFORE_PATH */] = {
185
- ["w" /* PathCharTypes.WORKSPACE */]: [0 /* States.BEFORE_PATH */],
186
- ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
187
- ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
188
- ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
189
- };
190
- pathStateMachine[1 /* States.IN_PATH */] = {
191
- ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */],
192
- ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */],
193
- ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
194
- ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
195
- };
196
- pathStateMachine[2 /* States.BEFORE_IDENT */] = {
197
- ["w" /* PathCharTypes.WORKSPACE */]: [2 /* States.BEFORE_IDENT */],
198
- ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
199
- ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */]
200
- };
201
- pathStateMachine[3 /* States.IN_IDENT */] = {
202
- ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
203
- ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
204
- ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */, 1 /* Actions.PUSH */],
205
- ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */, 1 /* Actions.PUSH */],
206
- ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */, 1 /* Actions.PUSH */],
207
- ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */, 1 /* Actions.PUSH */]
208
- };
209
- pathStateMachine[4 /* States.IN_SUB_PATH */] = {
210
- ["'" /* PathCharTypes.SINGLE_QUOTE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */],
211
- ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */],
212
- ["[" /* PathCharTypes.LEFT_BRACKET */]: [
213
- 4 /* States.IN_SUB_PATH */,
214
- 2 /* Actions.INC_SUB_PATH_DEPTH */
215
- ],
216
- ["]" /* PathCharTypes.RIGHT_BRACKET */]: [1 /* States.IN_PATH */, 3 /* Actions.PUSH_SUB_PATH */],
217
- ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
218
- ["l" /* PathCharTypes.ELSE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */]
219
- };
220
- pathStateMachine[5 /* States.IN_SINGLE_QUOTE */] = {
221
- ["'" /* PathCharTypes.SINGLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
222
- ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
223
- ["l" /* PathCharTypes.ELSE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */]
224
- };
225
- pathStateMachine[6 /* States.IN_DOUBLE_QUOTE */] = {
226
- ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
227
- ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
228
- ["l" /* PathCharTypes.ELSE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */]
229
- };
230
- /**
231
- * Check if an expression is a literal value.
232
- */
233
- const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
234
- function isLiteral(exp) {
235
- return literalValueRE.test(exp);
236
- }
237
- /**
238
- * Strip quotes from a string
239
- */
240
- function stripQuotes(str) {
241
- const a = str.charCodeAt(0);
242
- const b = str.charCodeAt(str.length - 1);
243
- return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
244
- }
245
- /**
246
- * Determine the type of a character in a keypath.
247
- */
248
- function getPathCharType(ch) {
249
- if (ch === undefined || ch === null) {
250
- return "o" /* PathCharTypes.END_OF_FAIL */;
251
- }
252
- const code = ch.charCodeAt(0);
253
- switch (code) {
254
- case 0x5b: // [
255
- case 0x5d: // ]
256
- case 0x2e: // .
257
- case 0x22: // "
258
- case 0x27: // '
259
- return ch;
260
- case 0x5f: // _
261
- case 0x24: // $
262
- case 0x2d: // -
263
- return "i" /* PathCharTypes.IDENT */;
264
- case 0x09: // Tab (HT)
265
- case 0x0a: // Newline (LF)
266
- case 0x0d: // Return (CR)
267
- case 0xa0: // No-break space (NBSP)
268
- case 0xfeff: // Byte Order Mark (BOM)
269
- case 0x2028: // Line Separator (LS)
270
- case 0x2029: // Paragraph Separator (PS)
271
- return "w" /* PathCharTypes.WORKSPACE */;
272
- }
273
- return "i" /* PathCharTypes.IDENT */;
274
- }
275
- /**
276
- * Format a subPath, return its plain form if it is
277
- * a literal string or number. Otherwise prepend the
278
- * dynamic indicator (*).
279
- */
280
- function formatSubPath(path) {
281
- const trimmed = path.trim();
282
- // invalid leading 0
283
- if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
284
- return false;
285
- }
286
- return isLiteral(trimmed)
287
- ? stripQuotes(trimmed)
288
- : "*" /* PathCharTypes.ASTARISK */ + trimmed;
289
- }
290
- /**
291
- * Parse a string path into an array of segments
292
- */
293
- function parse(path) {
294
- const keys = [];
295
- let index = -1;
296
- let mode = 0 /* States.BEFORE_PATH */;
297
- let subPathDepth = 0;
298
- let c;
299
- let key; // eslint-disable-line
300
- let newChar;
301
- let type;
302
- let transition;
303
- let action;
304
- let typeMap;
305
- const actions = [];
306
- actions[0 /* Actions.APPEND */] = () => {
307
- if (key === undefined) {
308
- key = newChar;
309
- }
310
- else {
311
- key += newChar;
312
- }
313
- };
314
- actions[1 /* Actions.PUSH */] = () => {
315
- if (key !== undefined) {
316
- keys.push(key);
317
- key = undefined;
318
- }
319
- };
320
- actions[2 /* Actions.INC_SUB_PATH_DEPTH */] = () => {
321
- actions[0 /* Actions.APPEND */]();
322
- subPathDepth++;
323
- };
324
- actions[3 /* Actions.PUSH_SUB_PATH */] = () => {
325
- if (subPathDepth > 0) {
326
- subPathDepth--;
327
- mode = 4 /* States.IN_SUB_PATH */;
328
- actions[0 /* Actions.APPEND */]();
329
- }
330
- else {
331
- subPathDepth = 0;
332
- if (key === undefined) {
333
- return false;
334
- }
335
- key = formatSubPath(key);
336
- if (key === false) {
337
- return false;
338
- }
339
- else {
340
- actions[1 /* Actions.PUSH */]();
341
- }
342
- }
343
- };
344
- function maybeUnescapeQuote() {
345
- const nextChar = path[index + 1];
346
- if ((mode === 5 /* States.IN_SINGLE_QUOTE */ &&
347
- nextChar === "'" /* PathCharTypes.SINGLE_QUOTE */) ||
348
- (mode === 6 /* States.IN_DOUBLE_QUOTE */ &&
349
- nextChar === "\"" /* PathCharTypes.DOUBLE_QUOTE */)) {
350
- index++;
351
- newChar = '\\' + nextChar;
352
- actions[0 /* Actions.APPEND */]();
353
- return true;
354
- }
355
- }
356
- while (mode !== null) {
357
- index++;
358
- c = path[index];
359
- if (c === '\\' && maybeUnescapeQuote()) {
360
- continue;
361
- }
362
- type = getPathCharType(c);
363
- typeMap = pathStateMachine[mode];
364
- transition = typeMap[type] || typeMap["l" /* PathCharTypes.ELSE */] || 8 /* States.ERROR */;
365
- // check parse error
366
- if (transition === 8 /* States.ERROR */) {
367
- return;
368
- }
369
- mode = transition[0];
370
- if (transition[1] !== undefined) {
371
- action = actions[transition[1]];
372
- if (action) {
373
- newChar = c;
374
- if (action() === false) {
375
- return;
376
- }
377
- }
378
- }
379
- // check parse finish
380
- if (mode === 7 /* States.AFTER_PATH */) {
381
- return keys;
382
- }
383
- }
384
- }
385
- // path token cache
386
- const cache = new Map();
387
- /**
388
- * key-value message resolver
389
- *
390
- * @remarks
391
- * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
392
- *
393
- * @param obj - A target object to be resolved with path
394
- * @param path - A {@link Path | path} to resolve the value of message
395
- *
396
- * @returns A resolved {@link PathValue | path value}
397
- *
398
- * @VueI18nGeneral
399
- */
400
- function resolveWithKeyValue(obj, path) {
401
- return isObject(obj) ? obj[path] : null;
402
- }
403
- /**
404
- * message resolver
405
- *
406
- * @remarks
407
- * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
408
- *
409
- * @param obj - A target object to be resolved with path
410
- * @param path - A {@link Path | path} to resolve the value of message
411
- *
412
- * @returns A resolved {@link PathValue | path value}
413
- *
414
- * @VueI18nGeneral
415
- */
416
- function resolveValue(obj, path) {
417
- // check object
418
- if (!isObject(obj)) {
419
- return null;
420
- }
421
- // parse path
422
- let hit = cache.get(path);
423
- if (!hit) {
424
- hit = parse(path);
425
- if (hit) {
426
- cache.set(path, hit);
427
- }
428
- }
429
- // check hit
430
- if (!hit) {
431
- return null;
432
- }
433
- // resolve path value
434
- const len = hit.length;
435
- let last = obj;
436
- let i = 0;
437
- while (i < len) {
438
- const val = last[hit[i]];
439
- if (val === undefined) {
440
- return null;
441
- }
442
- last = val;
443
- i++;
444
- }
445
- return last;
188
+ const pathStateMachine = [];
189
+ pathStateMachine[0 /* States.BEFORE_PATH */] = {
190
+ ["w" /* PathCharTypes.WORKSPACE */]: [0 /* States.BEFORE_PATH */],
191
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
192
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
193
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
194
+ };
195
+ pathStateMachine[1 /* States.IN_PATH */] = {
196
+ ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */],
197
+ ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */],
198
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
199
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
200
+ };
201
+ pathStateMachine[2 /* States.BEFORE_IDENT */] = {
202
+ ["w" /* PathCharTypes.WORKSPACE */]: [2 /* States.BEFORE_IDENT */],
203
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
204
+ ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */]
205
+ };
206
+ pathStateMachine[3 /* States.IN_IDENT */] = {
207
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
208
+ ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
209
+ ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */, 1 /* Actions.PUSH */],
210
+ ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */, 1 /* Actions.PUSH */],
211
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */, 1 /* Actions.PUSH */],
212
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */, 1 /* Actions.PUSH */]
213
+ };
214
+ pathStateMachine[4 /* States.IN_SUB_PATH */] = {
215
+ ["'" /* PathCharTypes.SINGLE_QUOTE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */],
216
+ ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */],
217
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [
218
+ 4 /* States.IN_SUB_PATH */,
219
+ 2 /* Actions.INC_SUB_PATH_DEPTH */
220
+ ],
221
+ ["]" /* PathCharTypes.RIGHT_BRACKET */]: [1 /* States.IN_PATH */, 3 /* Actions.PUSH_SUB_PATH */],
222
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
223
+ ["l" /* PathCharTypes.ELSE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */]
224
+ };
225
+ pathStateMachine[5 /* States.IN_SINGLE_QUOTE */] = {
226
+ ["'" /* PathCharTypes.SINGLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
227
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
228
+ ["l" /* PathCharTypes.ELSE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */]
229
+ };
230
+ pathStateMachine[6 /* States.IN_DOUBLE_QUOTE */] = {
231
+ ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
232
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
233
+ ["l" /* PathCharTypes.ELSE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */]
234
+ };
235
+ /**
236
+ * Check if an expression is a literal value.
237
+ */
238
+ const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
239
+ function isLiteral(exp) {
240
+ return literalValueRE.test(exp);
241
+ }
242
+ /**
243
+ * Strip quotes from a string
244
+ */
245
+ function stripQuotes(str) {
246
+ const a = str.charCodeAt(0);
247
+ const b = str.charCodeAt(str.length - 1);
248
+ return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
249
+ }
250
+ /**
251
+ * Determine the type of a character in a keypath.
252
+ */
253
+ function getPathCharType(ch) {
254
+ if (ch === undefined || ch === null) {
255
+ return "o" /* PathCharTypes.END_OF_FAIL */;
256
+ }
257
+ const code = ch.charCodeAt(0);
258
+ switch (code) {
259
+ case 0x5b: // [
260
+ case 0x5d: // ]
261
+ case 0x2e: // .
262
+ case 0x22: // "
263
+ case 0x27: // '
264
+ return ch;
265
+ case 0x5f: // _
266
+ case 0x24: // $
267
+ case 0x2d: // -
268
+ return "i" /* PathCharTypes.IDENT */;
269
+ case 0x09: // Tab (HT)
270
+ case 0x0a: // Newline (LF)
271
+ case 0x0d: // Return (CR)
272
+ case 0xa0: // No-break space (NBSP)
273
+ case 0xfeff: // Byte Order Mark (BOM)
274
+ case 0x2028: // Line Separator (LS)
275
+ case 0x2029: // Paragraph Separator (PS)
276
+ return "w" /* PathCharTypes.WORKSPACE */;
277
+ }
278
+ return "i" /* PathCharTypes.IDENT */;
279
+ }
280
+ /**
281
+ * Format a subPath, return its plain form if it is
282
+ * a literal string or number. Otherwise prepend the
283
+ * dynamic indicator (*).
284
+ */
285
+ function formatSubPath(path) {
286
+ const trimmed = path.trim();
287
+ // invalid leading 0
288
+ if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
289
+ return false;
290
+ }
291
+ return isLiteral(trimmed)
292
+ ? stripQuotes(trimmed)
293
+ : "*" /* PathCharTypes.ASTARISK */ + trimmed;
294
+ }
295
+ /**
296
+ * Parse a string path into an array of segments
297
+ */
298
+ function parse(path) {
299
+ const keys = [];
300
+ let index = -1;
301
+ let mode = 0 /* States.BEFORE_PATH */;
302
+ let subPathDepth = 0;
303
+ let c;
304
+ let key; // eslint-disable-line
305
+ let newChar;
306
+ let type;
307
+ let transition;
308
+ let action;
309
+ let typeMap;
310
+ const actions = [];
311
+ actions[0 /* Actions.APPEND */] = () => {
312
+ if (key === undefined) {
313
+ key = newChar;
314
+ }
315
+ else {
316
+ key += newChar;
317
+ }
318
+ };
319
+ actions[1 /* Actions.PUSH */] = () => {
320
+ if (key !== undefined) {
321
+ keys.push(key);
322
+ key = undefined;
323
+ }
324
+ };
325
+ actions[2 /* Actions.INC_SUB_PATH_DEPTH */] = () => {
326
+ actions[0 /* Actions.APPEND */]();
327
+ subPathDepth++;
328
+ };
329
+ actions[3 /* Actions.PUSH_SUB_PATH */] = () => {
330
+ if (subPathDepth > 0) {
331
+ subPathDepth--;
332
+ mode = 4 /* States.IN_SUB_PATH */;
333
+ actions[0 /* Actions.APPEND */]();
334
+ }
335
+ else {
336
+ subPathDepth = 0;
337
+ if (key === undefined) {
338
+ return false;
339
+ }
340
+ key = formatSubPath(key);
341
+ if (key === false) {
342
+ return false;
343
+ }
344
+ else {
345
+ actions[1 /* Actions.PUSH */]();
346
+ }
347
+ }
348
+ };
349
+ function maybeUnescapeQuote() {
350
+ const nextChar = path[index + 1];
351
+ if ((mode === 5 /* States.IN_SINGLE_QUOTE */ &&
352
+ nextChar === "'" /* PathCharTypes.SINGLE_QUOTE */) ||
353
+ (mode === 6 /* States.IN_DOUBLE_QUOTE */ &&
354
+ nextChar === "\"" /* PathCharTypes.DOUBLE_QUOTE */)) {
355
+ index++;
356
+ newChar = '\\' + nextChar;
357
+ actions[0 /* Actions.APPEND */]();
358
+ return true;
359
+ }
360
+ }
361
+ while (mode !== null) {
362
+ index++;
363
+ c = path[index];
364
+ if (c === '\\' && maybeUnescapeQuote()) {
365
+ continue;
366
+ }
367
+ type = getPathCharType(c);
368
+ typeMap = pathStateMachine[mode];
369
+ transition = typeMap[type] || typeMap["l" /* PathCharTypes.ELSE */] || 8 /* States.ERROR */;
370
+ // check parse error
371
+ if (transition === 8 /* States.ERROR */) {
372
+ return;
373
+ }
374
+ mode = transition[0];
375
+ if (transition[1] !== undefined) {
376
+ action = actions[transition[1]];
377
+ if (action) {
378
+ newChar = c;
379
+ if (action() === false) {
380
+ return;
381
+ }
382
+ }
383
+ }
384
+ // check parse finish
385
+ if (mode === 7 /* States.AFTER_PATH */) {
386
+ return keys;
387
+ }
388
+ }
389
+ }
390
+ // path token cache
391
+ const cache = new Map();
392
+ /**
393
+ * key-value message resolver
394
+ *
395
+ * @remarks
396
+ * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
397
+ *
398
+ * @param obj - A target object to be resolved with path
399
+ * @param path - A {@link Path | path} to resolve the value of message
400
+ *
401
+ * @returns A resolved {@link PathValue | path value}
402
+ *
403
+ * @VueI18nGeneral
404
+ */
405
+ function resolveWithKeyValue(obj, path) {
406
+ return isObject(obj) ? obj[path] : null;
407
+ }
408
+ /**
409
+ * message resolver
410
+ *
411
+ * @remarks
412
+ * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
413
+ *
414
+ * @param obj - A target object to be resolved with path
415
+ * @param path - A {@link Path | path} to resolve the value of message
416
+ *
417
+ * @returns A resolved {@link PathValue | path value}
418
+ *
419
+ * @VueI18nGeneral
420
+ */
421
+ function resolveValue(obj, path) {
422
+ // check object
423
+ if (!isObject(obj)) {
424
+ return null;
425
+ }
426
+ // parse path
427
+ let hit = cache.get(path);
428
+ if (!hit) {
429
+ hit = parse(path);
430
+ if (hit) {
431
+ cache.set(path, hit);
432
+ }
433
+ }
434
+ // check hit
435
+ if (!hit) {
436
+ return null;
437
+ }
438
+ // resolve path value
439
+ const len = hit.length;
440
+ let last = obj;
441
+ let i = 0;
442
+ while (i < len) {
443
+ const val = last[hit[i]];
444
+ if (val === undefined) {
445
+ return null;
446
+ }
447
+ last = val;
448
+ i++;
449
+ }
450
+ return last;
446
451
  }
447
452
 
448
- const DEFAULT_MODIFIER = (str) => str;
449
- const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
450
- const DEFAULT_MESSAGE_DATA_TYPE = 'text';
451
- const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
452
- const DEFAULT_INTERPOLATE = toDisplayString;
453
- function pluralDefault(choice, choicesLength) {
454
- choice = Math.abs(choice);
455
- if (choicesLength === 2) {
456
- // prettier-ignore
457
- return choice
458
- ? choice > 1
459
- ? 1
460
- : 0
461
- : 1;
462
- }
463
- return choice ? Math.min(choice, 2) : 0;
464
- }
465
- function getPluralIndex(options) {
466
- // prettier-ignore
467
- const index = isNumber(options.pluralIndex)
468
- ? options.pluralIndex
469
- : -1;
470
- // prettier-ignore
471
- return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
472
- ? isNumber(options.named.count)
473
- ? options.named.count
474
- : isNumber(options.named.n)
475
- ? options.named.n
476
- : index
477
- : index;
478
- }
479
- function normalizeNamed(pluralIndex, props) {
480
- if (!props.count) {
481
- props.count = pluralIndex;
482
- }
483
- if (!props.n) {
484
- props.n = pluralIndex;
485
- }
486
- }
487
- function createMessageContext(options = {}) {
488
- const locale = options.locale;
489
- const pluralIndex = getPluralIndex(options);
490
- const pluralRule = isObject(options.pluralRules) &&
491
- isString(locale) &&
492
- isFunction(options.pluralRules[locale])
493
- ? options.pluralRules[locale]
494
- : pluralDefault;
495
- const orgPluralRule = isObject(options.pluralRules) &&
496
- isString(locale) &&
497
- isFunction(options.pluralRules[locale])
498
- ? pluralDefault
499
- : undefined;
500
- const plural = (messages) => {
501
- return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
502
- };
503
- const _list = options.list || [];
504
- const list = (index) => _list[index];
505
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
506
- const _named = options.named || {};
507
- isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
508
- const named = (key) => _named[key];
509
- function message(key) {
510
- // prettier-ignore
511
- const msg = isFunction(options.messages)
512
- ? options.messages(key)
513
- : isObject(options.messages)
514
- ? options.messages[key]
515
- : false;
516
- return !msg
517
- ? options.parent
518
- ? options.parent.message(key) // resolve from parent messages
519
- : DEFAULT_MESSAGE
520
- : msg;
521
- }
522
- const _modifier = (name) => options.modifiers
523
- ? options.modifiers[name]
524
- : DEFAULT_MODIFIER;
525
- const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
526
- ? options.processor.normalize
527
- : DEFAULT_NORMALIZE;
528
- const interpolate = isPlainObject(options.processor) &&
529
- isFunction(options.processor.interpolate)
530
- ? options.processor.interpolate
531
- : DEFAULT_INTERPOLATE;
532
- const type = isPlainObject(options.processor) && isString(options.processor.type)
533
- ? options.processor.type
534
- : DEFAULT_MESSAGE_DATA_TYPE;
535
- const linked = (key, ...args) => {
536
- const [arg1, arg2] = args;
537
- let type = 'text';
538
- let modifier = '';
539
- if (args.length === 1) {
540
- if (isObject(arg1)) {
541
- modifier = arg1.modifier || modifier;
542
- type = arg1.type || type;
543
- }
544
- else if (isString(arg1)) {
545
- modifier = arg1 || modifier;
546
- }
547
- }
548
- else if (args.length === 2) {
549
- if (isString(arg1)) {
550
- modifier = arg1 || modifier;
551
- }
552
- if (isString(arg2)) {
553
- type = arg2 || type;
554
- }
555
- }
556
- let msg = message(key)(ctx);
557
- // The message in vnode resolved with linked are returned as an array by processor.nomalize
558
- if (type === 'vnode' && isArray(msg) && modifier) {
559
- msg = msg[0];
560
- }
561
- return modifier ? _modifier(modifier)(msg, type) : msg;
562
- };
563
- const ctx = {
564
- ["list" /* HelperNameMap.LIST */]: list,
565
- ["named" /* HelperNameMap.NAMED */]: named,
566
- ["plural" /* HelperNameMap.PLURAL */]: plural,
567
- ["linked" /* HelperNameMap.LINKED */]: linked,
568
- ["message" /* HelperNameMap.MESSAGE */]: message,
569
- ["type" /* HelperNameMap.TYPE */]: type,
570
- ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
571
- ["normalize" /* HelperNameMap.NORMALIZE */]: normalize
572
- };
573
- return ctx;
453
+ const DEFAULT_MODIFIER = (str) => str;
454
+ const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
455
+ const DEFAULT_MESSAGE_DATA_TYPE = 'text';
456
+ const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
457
+ const DEFAULT_INTERPOLATE = toDisplayString;
458
+ function pluralDefault(choice, choicesLength) {
459
+ choice = Math.abs(choice);
460
+ if (choicesLength === 2) {
461
+ // prettier-ignore
462
+ return choice
463
+ ? choice > 1
464
+ ? 1
465
+ : 0
466
+ : 1;
467
+ }
468
+ return choice ? Math.min(choice, 2) : 0;
469
+ }
470
+ function getPluralIndex(options) {
471
+ // prettier-ignore
472
+ const index = isNumber(options.pluralIndex)
473
+ ? options.pluralIndex
474
+ : -1;
475
+ // prettier-ignore
476
+ return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
477
+ ? isNumber(options.named.count)
478
+ ? options.named.count
479
+ : isNumber(options.named.n)
480
+ ? options.named.n
481
+ : index
482
+ : index;
483
+ }
484
+ function normalizeNamed(pluralIndex, props) {
485
+ if (!props.count) {
486
+ props.count = pluralIndex;
487
+ }
488
+ if (!props.n) {
489
+ props.n = pluralIndex;
490
+ }
491
+ }
492
+ function createMessageContext(options = {}) {
493
+ const locale = options.locale;
494
+ const pluralIndex = getPluralIndex(options);
495
+ const pluralRule = isObject(options.pluralRules) &&
496
+ isString(locale) &&
497
+ isFunction(options.pluralRules[locale])
498
+ ? options.pluralRules[locale]
499
+ : pluralDefault;
500
+ const orgPluralRule = isObject(options.pluralRules) &&
501
+ isString(locale) &&
502
+ isFunction(options.pluralRules[locale])
503
+ ? pluralDefault
504
+ : undefined;
505
+ const plural = (messages) => {
506
+ return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
507
+ };
508
+ const _list = options.list || [];
509
+ const list = (index) => _list[index];
510
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
511
+ const _named = options.named || {};
512
+ isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
513
+ const named = (key) => _named[key];
514
+ function message(key) {
515
+ // prettier-ignore
516
+ const msg = isFunction(options.messages)
517
+ ? options.messages(key)
518
+ : isObject(options.messages)
519
+ ? options.messages[key]
520
+ : false;
521
+ return !msg
522
+ ? options.parent
523
+ ? options.parent.message(key) // resolve from parent messages
524
+ : DEFAULT_MESSAGE
525
+ : msg;
526
+ }
527
+ const _modifier = (name) => options.modifiers
528
+ ? options.modifiers[name]
529
+ : DEFAULT_MODIFIER;
530
+ const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
531
+ ? options.processor.normalize
532
+ : DEFAULT_NORMALIZE;
533
+ const interpolate = isPlainObject(options.processor) &&
534
+ isFunction(options.processor.interpolate)
535
+ ? options.processor.interpolate
536
+ : DEFAULT_INTERPOLATE;
537
+ const type = isPlainObject(options.processor) && isString(options.processor.type)
538
+ ? options.processor.type
539
+ : DEFAULT_MESSAGE_DATA_TYPE;
540
+ const linked = (key, ...args) => {
541
+ const [arg1, arg2] = args;
542
+ let type = 'text';
543
+ let modifier = '';
544
+ if (args.length === 1) {
545
+ if (isObject(arg1)) {
546
+ modifier = arg1.modifier || modifier;
547
+ type = arg1.type || type;
548
+ }
549
+ else if (isString(arg1)) {
550
+ modifier = arg1 || modifier;
551
+ }
552
+ }
553
+ else if (args.length === 2) {
554
+ if (isString(arg1)) {
555
+ modifier = arg1 || modifier;
556
+ }
557
+ if (isString(arg2)) {
558
+ type = arg2 || type;
559
+ }
560
+ }
561
+ let msg = message(key)(ctx);
562
+ // The message in vnode resolved with linked are returned as an array by processor.nomalize
563
+ if (type === 'vnode' && isArray(msg) && modifier) {
564
+ msg = msg[0];
565
+ }
566
+ return modifier ? _modifier(modifier)(msg, type) : msg;
567
+ };
568
+ const ctx = {
569
+ ["list" /* HelperNameMap.LIST */]: list,
570
+ ["named" /* HelperNameMap.NAMED */]: named,
571
+ ["plural" /* HelperNameMap.PLURAL */]: plural,
572
+ ["linked" /* HelperNameMap.LINKED */]: linked,
573
+ ["message" /* HelperNameMap.MESSAGE */]: message,
574
+ ["type" /* HelperNameMap.TYPE */]: type,
575
+ ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
576
+ ["normalize" /* HelperNameMap.NORMALIZE */]: normalize
577
+ };
578
+ return ctx;
574
579
  }
575
580
 
576
- const IntlifyDevToolsHooks = {
577
- I18nInit: 'i18n:init',
578
- FunctionTranslate: 'function:translate'
581
+ const IntlifyDevToolsHooks = {
582
+ I18nInit: 'i18n:init',
583
+ FunctionTranslate: 'function:translate'
579
584
  };
580
585
 
581
- let devtools = null;
582
- function setDevToolsHook(hook) {
583
- devtools = hook;
584
- }
585
- function getDevToolsHook() {
586
- return devtools;
587
- }
588
- function initI18nDevTools(i18n, version, meta) {
589
- // TODO: queue if devtools is undefined
590
- devtools &&
591
- devtools.emit(IntlifyDevToolsHooks.I18nInit, {
592
- timestamp: Date.now(),
593
- i18n,
594
- version,
595
- meta
596
- });
597
- }
598
- const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
599
- function createDevToolsHook(hook) {
600
- return (payloads) => devtools && devtools.emit(hook, payloads);
586
+ let devtools = null;
587
+ function setDevToolsHook(hook) {
588
+ devtools = hook;
589
+ }
590
+ function getDevToolsHook() {
591
+ return devtools;
592
+ }
593
+ function initI18nDevTools(i18n, version, meta) {
594
+ // TODO: queue if devtools is undefined
595
+ devtools &&
596
+ devtools.emit(IntlifyDevToolsHooks.I18nInit, {
597
+ timestamp: Date.now(),
598
+ i18n,
599
+ version,
600
+ meta
601
+ });
602
+ }
603
+ const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
604
+ function createDevToolsHook(hook) {
605
+ return (payloads) => devtools && devtools.emit(hook, payloads);
601
606
  }
602
607
 
603
- const CoreWarnCodes = {
604
- NOT_FOUND_KEY: 1,
605
- FALLBACK_TO_TRANSLATE: 2,
606
- CANNOT_FORMAT_NUMBER: 3,
607
- FALLBACK_TO_NUMBER_FORMAT: 4,
608
- CANNOT_FORMAT_DATE: 5,
609
- FALLBACK_TO_DATE_FORMAT: 6,
610
- __EXTEND_POINT__: 7
611
- };
612
- /** @internal */
613
- const warnMessages = {
614
- [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
615
- [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
616
- [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
617
- [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
618
- [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
619
- [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`
620
- };
621
- function getWarnMessage(code, ...args) {
622
- return format(warnMessages[code], ...args);
608
+ const CoreWarnCodes = {
609
+ NOT_FOUND_KEY: 1,
610
+ FALLBACK_TO_TRANSLATE: 2,
611
+ CANNOT_FORMAT_NUMBER: 3,
612
+ FALLBACK_TO_NUMBER_FORMAT: 4,
613
+ CANNOT_FORMAT_DATE: 5,
614
+ FALLBACK_TO_DATE_FORMAT: 6,
615
+ __EXTEND_POINT__: 7
616
+ };
617
+ /** @internal */
618
+ const warnMessages = {
619
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
620
+ [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
621
+ [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
622
+ [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
623
+ [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
624
+ [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`
625
+ };
626
+ function getWarnMessage(code, ...args) {
627
+ return format(warnMessages[code], ...args);
623
628
  }
624
629
 
625
- /**
626
- * Fallback with simple implemenation
627
- *
628
- * @remarks
629
- * A fallback locale function implemented with a simple fallback algorithm.
630
- *
631
- * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
632
- *
633
- * @param ctx - A {@link CoreContext | context}
634
- * @param fallback - A {@link FallbackLocale | fallback locale}
635
- * @param start - A starting {@link Locale | locale}
636
- *
637
- * @returns Fallback locales
638
- *
639
- * @VueI18nGeneral
640
- */
641
- function fallbackWithSimple(ctx, fallback, start // eslint-disable-line @typescript-eslint/no-unused-vars
642
- ) {
643
- // prettier-ignore
644
- return [...new Set([
645
- start,
646
- ...(isArray(fallback)
647
- ? fallback
648
- : isObject(fallback)
649
- ? Object.keys(fallback)
650
- : isString(fallback)
651
- ? [fallback]
652
- : [start])
653
- ])];
654
- }
655
- /**
656
- * Fallback with locale chain
657
- *
658
- * @remarks
659
- * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
660
- *
661
- * @param ctx - A {@link CoreContext | context}
662
- * @param fallback - A {@link FallbackLocale | fallback locale}
663
- * @param start - A starting {@link Locale | locale}
664
- *
665
- * @returns Fallback locales
666
- *
667
- * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
668
- *
669
- * @VueI18nGeneral
670
- */
671
- function fallbackWithLocaleChain(ctx, fallback, start) {
672
- const startLocale = isString(start) ? start : DEFAULT_LOCALE;
673
- const context = ctx;
674
- if (!context.__localeChainCache) {
675
- context.__localeChainCache = new Map();
676
- }
677
- let chain = context.__localeChainCache.get(startLocale);
678
- if (!chain) {
679
- chain = [];
680
- // first block defined by start
681
- let block = [start];
682
- // while any intervening block found
683
- while (isArray(block)) {
684
- block = appendBlockToChain(chain, block, fallback);
685
- }
686
- // prettier-ignore
687
- // last block defined by default
688
- const defaults = isArray(fallback) || !isPlainObject(fallback)
689
- ? fallback
690
- : fallback['default']
691
- ? fallback['default']
692
- : null;
693
- // convert defaults to array
694
- block = isString(defaults) ? [defaults] : defaults;
695
- if (isArray(block)) {
696
- appendBlockToChain(chain, block, false);
697
- }
698
- context.__localeChainCache.set(startLocale, chain);
699
- }
700
- return chain;
701
- }
702
- function appendBlockToChain(chain, block, blocks) {
703
- let follow = true;
704
- for (let i = 0; i < block.length && isBoolean(follow); i++) {
705
- const locale = block[i];
706
- if (isString(locale)) {
707
- follow = appendLocaleToChain(chain, block[i], blocks);
708
- }
709
- }
710
- return follow;
711
- }
712
- function appendLocaleToChain(chain, locale, blocks) {
713
- let follow;
714
- const tokens = locale.split('-');
715
- do {
716
- const target = tokens.join('-');
717
- follow = appendItemToChain(chain, target, blocks);
718
- tokens.splice(-1, 1);
719
- } while (tokens.length && follow === true);
720
- return follow;
721
- }
722
- function appendItemToChain(chain, target, blocks) {
723
- let follow = false;
724
- if (!chain.includes(target)) {
725
- follow = true;
726
- if (target) {
727
- follow = target[target.length - 1] !== '!';
728
- const locale = target.replace(/!/g, '');
729
- chain.push(locale);
730
- if ((isArray(blocks) || isPlainObject(blocks)) &&
731
- blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
732
- ) {
733
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
734
- follow = blocks[locale];
735
- }
736
- }
737
- }
738
- return follow;
630
+ /**
631
+ * Fallback with simple implemenation
632
+ *
633
+ * @remarks
634
+ * A fallback locale function implemented with a simple fallback algorithm.
635
+ *
636
+ * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
637
+ *
638
+ * @param ctx - A {@link CoreContext | context}
639
+ * @param fallback - A {@link FallbackLocale | fallback locale}
640
+ * @param start - A starting {@link Locale | locale}
641
+ *
642
+ * @returns Fallback locales
643
+ *
644
+ * @VueI18nGeneral
645
+ */
646
+ function fallbackWithSimple(ctx, fallback, start // eslint-disable-line @typescript-eslint/no-unused-vars
647
+ ) {
648
+ // prettier-ignore
649
+ return [...new Set([
650
+ start,
651
+ ...(isArray(fallback)
652
+ ? fallback
653
+ : isObject(fallback)
654
+ ? Object.keys(fallback)
655
+ : isString(fallback)
656
+ ? [fallback]
657
+ : [start])
658
+ ])];
659
+ }
660
+ /**
661
+ * Fallback with locale chain
662
+ *
663
+ * @remarks
664
+ * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
665
+ *
666
+ * @param ctx - A {@link CoreContext | context}
667
+ * @param fallback - A {@link FallbackLocale | fallback locale}
668
+ * @param start - A starting {@link Locale | locale}
669
+ *
670
+ * @returns Fallback locales
671
+ *
672
+ * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
673
+ *
674
+ * @VueI18nGeneral
675
+ */
676
+ function fallbackWithLocaleChain(ctx, fallback, start) {
677
+ const startLocale = isString(start) ? start : DEFAULT_LOCALE;
678
+ const context = ctx;
679
+ if (!context.__localeChainCache) {
680
+ context.__localeChainCache = new Map();
681
+ }
682
+ let chain = context.__localeChainCache.get(startLocale);
683
+ if (!chain) {
684
+ chain = [];
685
+ // first block defined by start
686
+ let block = [start];
687
+ // while any intervening block found
688
+ while (isArray(block)) {
689
+ block = appendBlockToChain(chain, block, fallback);
690
+ }
691
+ // prettier-ignore
692
+ // last block defined by default
693
+ const defaults = isArray(fallback) || !isPlainObject(fallback)
694
+ ? fallback
695
+ : fallback['default']
696
+ ? fallback['default']
697
+ : null;
698
+ // convert defaults to array
699
+ block = isString(defaults) ? [defaults] : defaults;
700
+ if (isArray(block)) {
701
+ appendBlockToChain(chain, block, false);
702
+ }
703
+ context.__localeChainCache.set(startLocale, chain);
704
+ }
705
+ return chain;
706
+ }
707
+ function appendBlockToChain(chain, block, blocks) {
708
+ let follow = true;
709
+ for (let i = 0; i < block.length && isBoolean(follow); i++) {
710
+ const locale = block[i];
711
+ if (isString(locale)) {
712
+ follow = appendLocaleToChain(chain, block[i], blocks);
713
+ }
714
+ }
715
+ return follow;
716
+ }
717
+ function appendLocaleToChain(chain, locale, blocks) {
718
+ let follow;
719
+ const tokens = locale.split('-');
720
+ do {
721
+ const target = tokens.join('-');
722
+ follow = appendItemToChain(chain, target, blocks);
723
+ tokens.splice(-1, 1);
724
+ } while (tokens.length && follow === true);
725
+ return follow;
726
+ }
727
+ function appendItemToChain(chain, target, blocks) {
728
+ let follow = false;
729
+ if (!chain.includes(target)) {
730
+ follow = true;
731
+ if (target) {
732
+ follow = target[target.length - 1] !== '!';
733
+ const locale = target.replace(/!/g, '');
734
+ chain.push(locale);
735
+ if ((isArray(blocks) || isPlainObject(blocks)) &&
736
+ blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
737
+ ) {
738
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
739
+ follow = blocks[locale];
740
+ }
741
+ }
742
+ }
743
+ return follow;
739
744
  }
740
745
 
741
- /* eslint-disable @typescript-eslint/no-explicit-any */
742
- /**
743
- * Intlify core-base version
744
- * @internal
745
- */
746
- const VERSION = '9.3.0-beta.17';
747
- const NOT_REOSLVED = -1;
748
- const DEFAULT_LOCALE = 'en-US';
749
- const MISSING_RESOLVE_VALUE = '';
750
- const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
751
- function getDefaultLinkedModifiers() {
752
- return {
753
- upper: (val, type) => {
754
- // prettier-ignore
755
- return type === 'text' && isString(val)
756
- ? val.toUpperCase()
757
- : type === 'vnode' && isObject(val) && '__v_isVNode' in val
758
- ? val.children.toUpperCase()
759
- : val;
760
- },
761
- lower: (val, type) => {
762
- // prettier-ignore
763
- return type === 'text' && isString(val)
764
- ? val.toLowerCase()
765
- : type === 'vnode' && isObject(val) && '__v_isVNode' in val
766
- ? val.children.toLowerCase()
767
- : val;
768
- },
769
- capitalize: (val, type) => {
770
- // prettier-ignore
771
- return (type === 'text' && isString(val)
772
- ? capitalize(val)
773
- : type === 'vnode' && isObject(val) && '__v_isVNode' in val
774
- ? capitalize(val.children)
775
- : val);
776
- }
777
- };
778
- }
779
- let _compiler;
780
- function registerMessageCompiler(compiler) {
781
- _compiler = compiler;
782
- }
783
- let _resolver;
784
- /**
785
- * Register the message resolver
786
- *
787
- * @param resolver - A {@link MessageResolver} function
788
- *
789
- * @VueI18nGeneral
790
- */
791
- function registerMessageResolver(resolver) {
792
- _resolver = resolver;
793
- }
794
- let _fallbacker;
795
- /**
796
- * Register the locale fallbacker
797
- *
798
- * @param fallbacker - A {@link LocaleFallbacker} function
799
- *
800
- * @VueI18nGeneral
801
- */
802
- function registerLocaleFallbacker(fallbacker) {
803
- _fallbacker = fallbacker;
804
- }
805
- // Additional Meta for Intlify DevTools
806
- let _additionalMeta = null;
807
- const setAdditionalMeta = (meta) => {
808
- _additionalMeta = meta;
809
- };
810
- const getAdditionalMeta = () => _additionalMeta;
811
- let _fallbackContext = null;
812
- const setFallbackContext = (context) => {
813
- _fallbackContext = context;
814
- };
815
- const getFallbackContext = () => _fallbackContext;
816
- // ID for CoreContext
817
- let _cid = 0;
818
- function createCoreContext(options = {}) {
819
- // setup options
820
- const version = isString(options.version) ? options.version : VERSION;
821
- const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
822
- const fallbackLocale = isArray(options.fallbackLocale) ||
823
- isPlainObject(options.fallbackLocale) ||
824
- isString(options.fallbackLocale) ||
825
- options.fallbackLocale === false
826
- ? options.fallbackLocale
827
- : locale;
828
- const messages = isPlainObject(options.messages)
829
- ? options.messages
830
- : { [locale]: {} };
831
- const datetimeFormats = isPlainObject(options.datetimeFormats)
832
- ? options.datetimeFormats
833
- : { [locale]: {} }
834
- ;
835
- const numberFormats = isPlainObject(options.numberFormats)
836
- ? options.numberFormats
837
- : { [locale]: {} }
838
- ;
839
- const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
840
- const pluralRules = options.pluralRules || {};
841
- const missing = isFunction(options.missing) ? options.missing : null;
842
- const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
843
- ? options.missingWarn
844
- : true;
845
- const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
846
- ? options.fallbackWarn
847
- : true;
848
- const fallbackFormat = !!options.fallbackFormat;
849
- const unresolving = !!options.unresolving;
850
- const postTranslation = isFunction(options.postTranslation)
851
- ? options.postTranslation
852
- : null;
853
- const processor = isPlainObject(options.processor) ? options.processor : null;
854
- const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
855
- ? options.warnHtmlMessage
856
- : true;
857
- const escapeParameter = !!options.escapeParameter;
858
- const messageCompiler = isFunction(options.messageCompiler)
859
- ? options.messageCompiler
860
- : _compiler;
861
- const messageResolver = isFunction(options.messageResolver)
862
- ? options.messageResolver
863
- : _resolver || resolveWithKeyValue;
864
- const localeFallbacker = isFunction(options.localeFallbacker)
865
- ? options.localeFallbacker
866
- : _fallbacker || fallbackWithSimple;
867
- const fallbackContext = isObject(options.fallbackContext)
868
- ? options.fallbackContext
869
- : undefined;
870
- const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
871
- // setup internal options
872
- const internalOptions = options;
873
- const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
874
- ? internalOptions.__datetimeFormatters
875
- : new Map()
876
- ;
877
- const __numberFormatters = isObject(internalOptions.__numberFormatters)
878
- ? internalOptions.__numberFormatters
879
- : new Map()
880
- ;
881
- const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
882
- _cid++;
883
- const context = {
884
- version,
885
- cid: _cid,
886
- locale,
887
- fallbackLocale,
888
- messages,
889
- modifiers,
890
- pluralRules,
891
- missing,
892
- missingWarn,
893
- fallbackWarn,
894
- fallbackFormat,
895
- unresolving,
896
- postTranslation,
897
- processor,
898
- warnHtmlMessage,
899
- escapeParameter,
900
- messageCompiler,
901
- messageResolver,
902
- localeFallbacker,
903
- fallbackContext,
904
- onWarn,
905
- __meta
906
- };
907
- {
908
- context.datetimeFormats = datetimeFormats;
909
- context.numberFormats = numberFormats;
910
- context.__datetimeFormatters = __datetimeFormatters;
911
- context.__numberFormatters = __numberFormatters;
912
- }
913
- // for vue-devtools timeline event
914
- {
915
- context.__v_emitter =
916
- internalOptions.__v_emitter != null
917
- ? internalOptions.__v_emitter
918
- : undefined;
919
- }
920
- // NOTE: experimental !!
921
- {
922
- initI18nDevTools(context, version, __meta);
923
- }
924
- return context;
925
- }
926
- /** @internal */
927
- function isTranslateFallbackWarn(fallback, key) {
928
- return fallback instanceof RegExp ? fallback.test(key) : fallback;
929
- }
930
- /** @internal */
931
- function isTranslateMissingWarn(missing, key) {
932
- return missing instanceof RegExp ? missing.test(key) : missing;
933
- }
934
- /** @internal */
935
- function handleMissing(context, key, locale, missingWarn, type) {
936
- const { missing, onWarn } = context;
937
- // for vue-devtools timeline event
938
- {
939
- const emitter = context.__v_emitter;
940
- if (emitter) {
941
- emitter.emit("missing" /* VueDevToolsTimelineEvents.MISSING */, {
942
- locale,
943
- key,
944
- type,
945
- groupId: `${type}:${key}`
946
- });
947
- }
948
- }
949
- if (missing !== null) {
950
- const ret = missing(context, locale, key, type);
951
- return isString(ret) ? ret : key;
952
- }
953
- else {
954
- if (isTranslateMissingWarn(missingWarn, key)) {
955
- onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
956
- }
957
- return key;
958
- }
959
- }
960
- /** @internal */
961
- function updateFallbackLocale(ctx, locale, fallback) {
962
- const context = ctx;
963
- context.__localeChainCache = new Map();
964
- ctx.localeFallbacker(ctx, fallback, locale);
965
- }
746
+ /* eslint-disable @typescript-eslint/no-explicit-any */
747
+ /**
748
+ * Intlify core-base version
749
+ * @internal
750
+ */
751
+ const VERSION = '9.3.0-beta.18';
752
+ const NOT_REOSLVED = -1;
753
+ const DEFAULT_LOCALE = 'en-US';
754
+ const MISSING_RESOLVE_VALUE = '';
755
+ const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
756
+ function getDefaultLinkedModifiers() {
757
+ return {
758
+ upper: (val, type) => {
759
+ // prettier-ignore
760
+ return type === 'text' && isString(val)
761
+ ? val.toUpperCase()
762
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
763
+ ? val.children.toUpperCase()
764
+ : val;
765
+ },
766
+ lower: (val, type) => {
767
+ // prettier-ignore
768
+ return type === 'text' && isString(val)
769
+ ? val.toLowerCase()
770
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
771
+ ? val.children.toLowerCase()
772
+ : val;
773
+ },
774
+ capitalize: (val, type) => {
775
+ // prettier-ignore
776
+ return (type === 'text' && isString(val)
777
+ ? capitalize(val)
778
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
779
+ ? capitalize(val.children)
780
+ : val);
781
+ }
782
+ };
783
+ }
784
+ let _compiler;
785
+ function registerMessageCompiler(compiler) {
786
+ _compiler = compiler;
787
+ }
788
+ let _resolver;
789
+ /**
790
+ * Register the message resolver
791
+ *
792
+ * @param resolver - A {@link MessageResolver} function
793
+ *
794
+ * @VueI18nGeneral
795
+ */
796
+ function registerMessageResolver(resolver) {
797
+ _resolver = resolver;
798
+ }
799
+ let _fallbacker;
800
+ /**
801
+ * Register the locale fallbacker
802
+ *
803
+ * @param fallbacker - A {@link LocaleFallbacker} function
804
+ *
805
+ * @VueI18nGeneral
806
+ */
807
+ function registerLocaleFallbacker(fallbacker) {
808
+ _fallbacker = fallbacker;
809
+ }
810
+ // Additional Meta for Intlify DevTools
811
+ let _additionalMeta = null;
812
+ const setAdditionalMeta = (meta) => {
813
+ _additionalMeta = meta;
814
+ };
815
+ const getAdditionalMeta = () => _additionalMeta;
816
+ let _fallbackContext = null;
817
+ const setFallbackContext = (context) => {
818
+ _fallbackContext = context;
819
+ };
820
+ const getFallbackContext = () => _fallbackContext;
821
+ // ID for CoreContext
822
+ let _cid = 0;
823
+ function createCoreContext(options = {}) {
824
+ // setup options
825
+ const version = isString(options.version) ? options.version : VERSION;
826
+ const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
827
+ const fallbackLocale = isArray(options.fallbackLocale) ||
828
+ isPlainObject(options.fallbackLocale) ||
829
+ isString(options.fallbackLocale) ||
830
+ options.fallbackLocale === false
831
+ ? options.fallbackLocale
832
+ : locale;
833
+ const messages = isPlainObject(options.messages)
834
+ ? options.messages
835
+ : { [locale]: {} };
836
+ const datetimeFormats = isPlainObject(options.datetimeFormats)
837
+ ? options.datetimeFormats
838
+ : { [locale]: {} }
839
+ ;
840
+ const numberFormats = isPlainObject(options.numberFormats)
841
+ ? options.numberFormats
842
+ : { [locale]: {} }
843
+ ;
844
+ const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
845
+ const pluralRules = options.pluralRules || {};
846
+ const missing = isFunction(options.missing) ? options.missing : null;
847
+ const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
848
+ ? options.missingWarn
849
+ : true;
850
+ const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
851
+ ? options.fallbackWarn
852
+ : true;
853
+ const fallbackFormat = !!options.fallbackFormat;
854
+ const unresolving = !!options.unresolving;
855
+ const postTranslation = isFunction(options.postTranslation)
856
+ ? options.postTranslation
857
+ : null;
858
+ const processor = isPlainObject(options.processor) ? options.processor : null;
859
+ const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
860
+ ? options.warnHtmlMessage
861
+ : true;
862
+ const escapeParameter = !!options.escapeParameter;
863
+ const messageCompiler = isFunction(options.messageCompiler)
864
+ ? options.messageCompiler
865
+ : _compiler;
866
+ const messageResolver = isFunction(options.messageResolver)
867
+ ? options.messageResolver
868
+ : _resolver || resolveWithKeyValue;
869
+ const localeFallbacker = isFunction(options.localeFallbacker)
870
+ ? options.localeFallbacker
871
+ : _fallbacker || fallbackWithSimple;
872
+ const fallbackContext = isObject(options.fallbackContext)
873
+ ? options.fallbackContext
874
+ : undefined;
875
+ const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
876
+ // setup internal options
877
+ const internalOptions = options;
878
+ const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
879
+ ? internalOptions.__datetimeFormatters
880
+ : new Map()
881
+ ;
882
+ const __numberFormatters = isObject(internalOptions.__numberFormatters)
883
+ ? internalOptions.__numberFormatters
884
+ : new Map()
885
+ ;
886
+ const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
887
+ _cid++;
888
+ const context = {
889
+ version,
890
+ cid: _cid,
891
+ locale,
892
+ fallbackLocale,
893
+ messages,
894
+ modifiers,
895
+ pluralRules,
896
+ missing,
897
+ missingWarn,
898
+ fallbackWarn,
899
+ fallbackFormat,
900
+ unresolving,
901
+ postTranslation,
902
+ processor,
903
+ warnHtmlMessage,
904
+ escapeParameter,
905
+ messageCompiler,
906
+ messageResolver,
907
+ localeFallbacker,
908
+ fallbackContext,
909
+ onWarn,
910
+ __meta
911
+ };
912
+ {
913
+ context.datetimeFormats = datetimeFormats;
914
+ context.numberFormats = numberFormats;
915
+ context.__datetimeFormatters = __datetimeFormatters;
916
+ context.__numberFormatters = __numberFormatters;
917
+ }
918
+ // for vue-devtools timeline event
919
+ {
920
+ context.__v_emitter =
921
+ internalOptions.__v_emitter != null
922
+ ? internalOptions.__v_emitter
923
+ : undefined;
924
+ }
925
+ // NOTE: experimental !!
926
+ {
927
+ initI18nDevTools(context, version, __meta);
928
+ }
929
+ return context;
930
+ }
931
+ /** @internal */
932
+ function isTranslateFallbackWarn(fallback, key) {
933
+ return fallback instanceof RegExp ? fallback.test(key) : fallback;
934
+ }
935
+ /** @internal */
936
+ function isTranslateMissingWarn(missing, key) {
937
+ return missing instanceof RegExp ? missing.test(key) : missing;
938
+ }
939
+ /** @internal */
940
+ function handleMissing(context, key, locale, missingWarn, type) {
941
+ const { missing, onWarn } = context;
942
+ // for vue-devtools timeline event
943
+ {
944
+ const emitter = context.__v_emitter;
945
+ if (emitter) {
946
+ emitter.emit("missing" /* VueDevToolsTimelineEvents.MISSING */, {
947
+ locale,
948
+ key,
949
+ type,
950
+ groupId: `${type}:${key}`
951
+ });
952
+ }
953
+ }
954
+ if (missing !== null) {
955
+ const ret = missing(context, locale, key, type);
956
+ return isString(ret) ? ret : key;
957
+ }
958
+ else {
959
+ if (isTranslateMissingWarn(missingWarn, key)) {
960
+ onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
961
+ }
962
+ return key;
963
+ }
964
+ }
965
+ /** @internal */
966
+ function updateFallbackLocale(ctx, locale, fallback) {
967
+ const context = ctx;
968
+ context.__localeChainCache = new Map();
969
+ ctx.localeFallbacker(ctx, fallback, locale);
970
+ }
966
971
  /* eslint-enable @typescript-eslint/no-explicit-any */
967
972
 
968
- function clearCompileCache() {
969
- }
970
- function compileToFunction(source, options = {}) {
971
- {
972
- warn(`Runtime compilation is not supported in ${'core.runtime.esm-browser.js' }.`);
973
- return (() => source);
974
- }
973
+ function clearCompileCache() {
974
+ }
975
+ function compileToFunction(source, options = {}) {
976
+ {
977
+ warn(`Runtime compilation is not supported in ${'core.runtime.esm-browser.js' }.`);
978
+ return (() => source);
979
+ }
975
980
  }
976
981
 
977
- let code = CompileErrorCodes.__EXTEND_POINT__;
978
- const inc = () => ++code;
979
- const CoreErrorCodes = {
980
- INVALID_ARGUMENT: code,
981
- INVALID_DATE_ARGUMENT: inc(),
982
- INVALID_ISO_DATE_ARGUMENT: inc(),
983
- __EXTEND_POINT__: inc() // 18
984
- };
985
- function createCoreError(code) {
986
- return createCompileError(code, null, { messages: errorMessages } );
987
- }
988
- /** @internal */
989
- const errorMessages = {
990
- [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
991
- [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
992
- 'Make sure your Date represents a valid date.',
993
- [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string'
982
+ let code = CompileErrorCodes.__EXTEND_POINT__;
983
+ const inc = () => ++code;
984
+ const CoreErrorCodes = {
985
+ INVALID_ARGUMENT: code,
986
+ INVALID_DATE_ARGUMENT: inc(),
987
+ INVALID_ISO_DATE_ARGUMENT: inc(),
988
+ __EXTEND_POINT__: inc() // 18
989
+ };
990
+ function createCoreError(code) {
991
+ return createCompileError(code, null, { messages: errorMessages } );
992
+ }
993
+ /** @internal */
994
+ const errorMessages = {
995
+ [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
996
+ [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
997
+ 'Make sure your Date represents a valid date.',
998
+ [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string'
994
999
  };
995
1000
 
996
- const NOOP_MESSAGE_FUNCTION = () => '';
997
- const isMessageFunction = (val) => isFunction(val);
998
- // implementation of `translate` function
999
- function translate(context, ...args) {
1000
- const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
1001
- const [key, options] = parseTranslateArgs(...args);
1002
- const missingWarn = isBoolean(options.missingWarn)
1003
- ? options.missingWarn
1004
- : context.missingWarn;
1005
- const fallbackWarn = isBoolean(options.fallbackWarn)
1006
- ? options.fallbackWarn
1007
- : context.fallbackWarn;
1008
- const escapeParameter = isBoolean(options.escapeParameter)
1009
- ? options.escapeParameter
1010
- : context.escapeParameter;
1011
- const resolvedMessage = !!options.resolvedMessage;
1012
- // prettier-ignore
1013
- const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
1014
- ? !isBoolean(options.default)
1015
- ? options.default
1016
- : (!messageCompiler ? () => key : key)
1017
- : fallbackFormat // default by `fallbackFormat` option
1018
- ? (!messageCompiler ? () => key : key)
1019
- : '';
1020
- const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
1021
- const locale = isString(options.locale) ? options.locale : context.locale;
1022
- // escape params
1023
- escapeParameter && escapeParams(options);
1024
- // resolve message format
1025
- // eslint-disable-next-line prefer-const
1026
- let [formatScope, targetLocale, message] = !resolvedMessage
1027
- ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
1028
- : [
1029
- key,
1030
- locale,
1031
- messages[locale] || {}
1032
- ];
1033
- // NOTE:
1034
- // Fix to work around `ssrTransfrom` bug in Vite.
1035
- // https://github.com/vitejs/vite/issues/4306
1036
- // To get around this, use temporary variables.
1037
- // https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
1038
- let format = formatScope;
1039
- // if you use default message, set it as message format!
1040
- let cacheBaseKey = key;
1041
- if (!resolvedMessage &&
1042
- !(isString(format) || isMessageFunction(format))) {
1043
- if (enableDefaultMsg) {
1044
- format = defaultMsgOrKey;
1045
- cacheBaseKey = format;
1046
- }
1047
- }
1048
- // checking message format and target locale
1049
- if (!resolvedMessage &&
1050
- (!(isString(format) || isMessageFunction(format)) ||
1051
- !isString(targetLocale))) {
1052
- return unresolving ? NOT_REOSLVED : key;
1053
- }
1054
- if (isString(format) && context.messageCompiler == null) {
1055
- warn(`The message format compilation is not supported in this build. ` +
1056
- `Because message compiler isn't included. ` +
1057
- `You need to pre-compilation all message format. ` +
1058
- `So translate function return '${key}'.`);
1059
- return key;
1060
- }
1061
- // setup compile error detecting
1062
- let occurred = false;
1063
- const errorDetector = () => {
1064
- occurred = true;
1065
- };
1066
- // compile message format
1067
- const msg = !isMessageFunction(format)
1068
- ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
1069
- : format;
1070
- // if occurred compile error, return the message format
1071
- if (occurred) {
1072
- return format;
1073
- }
1074
- // evaluate message with context
1075
- const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
1076
- const msgContext = createMessageContext(ctxOptions);
1077
- const messaged = evaluateMessage(context, msg, msgContext);
1078
- // if use post translation option, proceed it with handler
1079
- const ret = postTranslation
1080
- ? postTranslation(messaged, key)
1081
- : messaged;
1082
- // NOTE: experimental !!
1083
- {
1084
- // prettier-ignore
1085
- const payloads = {
1086
- timestamp: Date.now(),
1087
- key: isString(key)
1088
- ? key
1089
- : isMessageFunction(format)
1090
- ? format.key
1091
- : '',
1092
- locale: targetLocale || (isMessageFunction(format)
1093
- ? format.locale
1094
- : ''),
1095
- format: isString(format)
1096
- ? format
1097
- : isMessageFunction(format)
1098
- ? format.source
1099
- : '',
1100
- message: ret
1101
- };
1102
- payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
1103
- translateDevTools(payloads);
1104
- }
1105
- return ret;
1106
- }
1107
- function escapeParams(options) {
1108
- if (isArray(options.list)) {
1109
- options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
1110
- }
1111
- else if (isObject(options.named)) {
1112
- Object.keys(options.named).forEach(key => {
1113
- if (isString(options.named[key])) {
1114
- options.named[key] = escapeHtml(options.named[key]);
1115
- }
1116
- });
1117
- }
1118
- }
1119
- function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1120
- const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1121
- const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1122
- let message = {};
1123
- let targetLocale;
1124
- let format = null;
1125
- let from = locale;
1126
- let to = null;
1127
- const type = 'translate';
1128
- for (let i = 0; i < locales.length; i++) {
1129
- targetLocale = to = locales[i];
1130
- if (locale !== targetLocale &&
1131
- isTranslateFallbackWarn(fallbackWarn, key)) {
1132
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
1133
- key,
1134
- target: targetLocale
1135
- }));
1136
- }
1137
- // for vue-devtools timeline event
1138
- if (locale !== targetLocale) {
1139
- const emitter = context.__v_emitter;
1140
- if (emitter) {
1141
- emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1142
- type,
1143
- key,
1144
- from,
1145
- to,
1146
- groupId: `${type}:${key}`
1147
- });
1148
- }
1149
- }
1150
- message =
1151
- messages[targetLocale] || {};
1152
- // for vue-devtools timeline event
1153
- let start = null;
1154
- let startTag;
1155
- let endTag;
1156
- if (inBrowser) {
1157
- start = window.performance.now();
1158
- startTag = 'intlify-message-resolve-start';
1159
- endTag = 'intlify-message-resolve-end';
1160
- mark && mark(startTag);
1161
- }
1162
- if ((format = resolveValue(message, key)) === null) {
1163
- // if null, resolve with object key path
1164
- format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
1165
- }
1166
- // for vue-devtools timeline event
1167
- if (inBrowser) {
1168
- const end = window.performance.now();
1169
- const emitter = context.__v_emitter;
1170
- if (emitter && start && format) {
1171
- emitter.emit("message-resolve" /* VueDevToolsTimelineEvents.MESSAGE_RESOLVE */, {
1172
- type: "message-resolve" /* VueDevToolsTimelineEvents.MESSAGE_RESOLVE */,
1173
- key,
1174
- message: format,
1175
- time: end - start,
1176
- groupId: `${type}:${key}`
1177
- });
1178
- }
1179
- if (startTag && endTag && mark && measure) {
1180
- mark(endTag);
1181
- measure('intlify message resolve', startTag, endTag);
1182
- }
1183
- }
1184
- if (isString(format) || isFunction(format))
1185
- break;
1186
- const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1187
- key, targetLocale, missingWarn, type);
1188
- if (missingRet !== key) {
1189
- format = missingRet;
1190
- }
1191
- from = to;
1192
- }
1193
- return [format, targetLocale, message];
1194
- }
1195
- function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
1196
- const { messageCompiler, warnHtmlMessage } = context;
1197
- if (isMessageFunction(format)) {
1198
- const msg = format;
1199
- msg.locale = msg.locale || targetLocale;
1200
- msg.key = msg.key || key;
1201
- return msg;
1202
- }
1203
- if (messageCompiler == null) {
1204
- const msg = (() => format);
1205
- msg.locale = targetLocale;
1206
- msg.key = key;
1207
- return msg;
1208
- }
1209
- // for vue-devtools timeline event
1210
- let start = null;
1211
- let startTag;
1212
- let endTag;
1213
- if (inBrowser) {
1214
- start = window.performance.now();
1215
- startTag = 'intlify-message-compilation-start';
1216
- endTag = 'intlify-message-compilation-end';
1217
- mark && mark(startTag);
1218
- }
1219
- const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
1220
- // for vue-devtools timeline event
1221
- if (inBrowser) {
1222
- const end = window.performance.now();
1223
- const emitter = context.__v_emitter;
1224
- if (emitter && start) {
1225
- emitter.emit("message-compilation" /* VueDevToolsTimelineEvents.MESSAGE_COMPILATION */, {
1226
- type: "message-compilation" /* VueDevToolsTimelineEvents.MESSAGE_COMPILATION */,
1227
- message: format,
1228
- time: end - start,
1229
- groupId: `${'translate'}:${key}`
1230
- });
1231
- }
1232
- if (startTag && endTag && mark && measure) {
1233
- mark(endTag);
1234
- measure('intlify message compilation', startTag, endTag);
1235
- }
1236
- }
1237
- msg.locale = targetLocale;
1238
- msg.key = key;
1239
- msg.source = format;
1240
- return msg;
1241
- }
1242
- function evaluateMessage(context, msg, msgCtx) {
1243
- // for vue-devtools timeline event
1244
- let start = null;
1245
- let startTag;
1246
- let endTag;
1247
- if (inBrowser) {
1248
- start = window.performance.now();
1249
- startTag = 'intlify-message-evaluation-start';
1250
- endTag = 'intlify-message-evaluation-end';
1251
- mark && mark(startTag);
1252
- }
1253
- const messaged = msg(msgCtx);
1254
- // for vue-devtools timeline event
1255
- if (inBrowser) {
1256
- const end = window.performance.now();
1257
- const emitter = context.__v_emitter;
1258
- if (emitter && start) {
1259
- emitter.emit("message-evaluation" /* VueDevToolsTimelineEvents.MESSAGE_EVALUATION */, {
1260
- type: "message-evaluation" /* VueDevToolsTimelineEvents.MESSAGE_EVALUATION */,
1261
- value: messaged,
1262
- time: end - start,
1263
- groupId: `${'translate'}:${msg.key}`
1264
- });
1265
- }
1266
- if (startTag && endTag && mark && measure) {
1267
- mark(endTag);
1268
- measure('intlify message evaluation', startTag, endTag);
1269
- }
1270
- }
1271
- return messaged;
1272
- }
1273
- /** @internal */
1274
- function parseTranslateArgs(...args) {
1275
- const [arg1, arg2, arg3] = args;
1276
- const options = {};
1277
- if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) {
1278
- throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1279
- }
1280
- // prettier-ignore
1281
- const key = isNumber(arg1)
1282
- ? String(arg1)
1283
- : isMessageFunction(arg1)
1284
- ? arg1
1285
- : arg1;
1286
- if (isNumber(arg2)) {
1287
- options.plural = arg2;
1288
- }
1289
- else if (isString(arg2)) {
1290
- options.default = arg2;
1291
- }
1292
- else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
1293
- options.named = arg2;
1294
- }
1295
- else if (isArray(arg2)) {
1296
- options.list = arg2;
1297
- }
1298
- if (isNumber(arg3)) {
1299
- options.plural = arg3;
1300
- }
1301
- else if (isString(arg3)) {
1302
- options.default = arg3;
1303
- }
1304
- else if (isPlainObject(arg3)) {
1305
- assign(options, arg3);
1306
- }
1307
- return [key, options];
1308
- }
1309
- function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
1310
- return {
1311
- warnHtmlMessage,
1312
- onError: (err) => {
1313
- errorDetector && errorDetector(err);
1314
- {
1315
- const message = `Message compilation error: ${err.message}`;
1316
- const codeFrame = err.location &&
1317
- generateCodeFrame(source, err.location.start.offset, err.location.end.offset);
1318
- const emitter = context.__v_emitter;
1319
- if (emitter) {
1320
- emitter.emit("compile-error" /* VueDevToolsTimelineEvents.COMPILE_ERROR */, {
1321
- message: source,
1322
- error: err.message,
1323
- start: err.location && err.location.start.offset,
1324
- end: err.location && err.location.end.offset,
1325
- groupId: `${'translate'}:${key}`
1326
- });
1327
- }
1328
- console.error(codeFrame ? `${message}\n${codeFrame}` : message);
1329
- }
1330
- },
1331
- onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
1332
- };
1333
- }
1334
- function getMessageContextOptions(context, locale, message, options) {
1335
- const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
1336
- const resolveMessage = (key) => {
1337
- let val = resolveValue(message, key);
1338
- // fallback to root context
1339
- if (val == null && fallbackContext) {
1340
- const [, , message] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
1341
- val = resolveValue(message, key);
1342
- }
1343
- if (isString(val)) {
1344
- let occurred = false;
1345
- const errorDetector = () => {
1346
- occurred = true;
1347
- };
1348
- const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
1349
- return !occurred
1350
- ? msg
1351
- : NOOP_MESSAGE_FUNCTION;
1352
- }
1353
- else if (isMessageFunction(val)) {
1354
- return val;
1355
- }
1356
- else {
1357
- // TODO: should be implemented warning message
1358
- return NOOP_MESSAGE_FUNCTION;
1359
- }
1360
- };
1361
- const ctxOptions = {
1362
- locale,
1363
- modifiers,
1364
- pluralRules,
1365
- messages: resolveMessage
1366
- };
1367
- if (context.processor) {
1368
- ctxOptions.processor = context.processor;
1369
- }
1370
- if (options.list) {
1371
- ctxOptions.list = options.list;
1372
- }
1373
- if (options.named) {
1374
- ctxOptions.named = options.named;
1375
- }
1376
- if (isNumber(options.plural)) {
1377
- ctxOptions.pluralIndex = options.plural;
1378
- }
1379
- return ctxOptions;
1001
+ const NOOP_MESSAGE_FUNCTION = () => '';
1002
+ const isMessageFunction = (val) => isFunction(val);
1003
+ // implementation of `translate` function
1004
+ function translate(context, ...args) {
1005
+ const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
1006
+ const [key, options] = parseTranslateArgs(...args);
1007
+ const missingWarn = isBoolean(options.missingWarn)
1008
+ ? options.missingWarn
1009
+ : context.missingWarn;
1010
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1011
+ ? options.fallbackWarn
1012
+ : context.fallbackWarn;
1013
+ const escapeParameter = isBoolean(options.escapeParameter)
1014
+ ? options.escapeParameter
1015
+ : context.escapeParameter;
1016
+ const resolvedMessage = !!options.resolvedMessage;
1017
+ // prettier-ignore
1018
+ const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
1019
+ ? !isBoolean(options.default)
1020
+ ? options.default
1021
+ : (!messageCompiler ? () => key : key)
1022
+ : fallbackFormat // default by `fallbackFormat` option
1023
+ ? (!messageCompiler ? () => key : key)
1024
+ : '';
1025
+ const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
1026
+ const locale = isString(options.locale) ? options.locale : context.locale;
1027
+ // escape params
1028
+ escapeParameter && escapeParams(options);
1029
+ // resolve message format
1030
+ // eslint-disable-next-line prefer-const
1031
+ let [formatScope, targetLocale, message] = !resolvedMessage
1032
+ ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
1033
+ : [
1034
+ key,
1035
+ locale,
1036
+ messages[locale] || {}
1037
+ ];
1038
+ // NOTE:
1039
+ // Fix to work around `ssrTransfrom` bug in Vite.
1040
+ // https://github.com/vitejs/vite/issues/4306
1041
+ // To get around this, use temporary variables.
1042
+ // https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
1043
+ let format = formatScope;
1044
+ // if you use default message, set it as message format!
1045
+ let cacheBaseKey = key;
1046
+ if (!resolvedMessage &&
1047
+ !(isString(format) || isMessageFunction(format))) {
1048
+ if (enableDefaultMsg) {
1049
+ format = defaultMsgOrKey;
1050
+ cacheBaseKey = format;
1051
+ }
1052
+ }
1053
+ // checking message format and target locale
1054
+ if (!resolvedMessage &&
1055
+ (!(isString(format) || isMessageFunction(format)) ||
1056
+ !isString(targetLocale))) {
1057
+ return unresolving ? NOT_REOSLVED : key;
1058
+ }
1059
+ if (isString(format) && context.messageCompiler == null) {
1060
+ warn(`The message format compilation is not supported in this build. ` +
1061
+ `Because message compiler isn't included. ` +
1062
+ `You need to pre-compilation all message format. ` +
1063
+ `So translate function return '${key}'.`);
1064
+ return key;
1065
+ }
1066
+ // setup compile error detecting
1067
+ let occurred = false;
1068
+ const errorDetector = () => {
1069
+ occurred = true;
1070
+ };
1071
+ // compile message format
1072
+ const msg = !isMessageFunction(format)
1073
+ ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
1074
+ : format;
1075
+ // if occurred compile error, return the message format
1076
+ if (occurred) {
1077
+ return format;
1078
+ }
1079
+ // evaluate message with context
1080
+ const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
1081
+ const msgContext = createMessageContext(ctxOptions);
1082
+ const messaged = evaluateMessage(context, msg, msgContext);
1083
+ // if use post translation option, proceed it with handler
1084
+ const ret = postTranslation
1085
+ ? postTranslation(messaged, key)
1086
+ : messaged;
1087
+ // NOTE: experimental !!
1088
+ {
1089
+ // prettier-ignore
1090
+ const payloads = {
1091
+ timestamp: Date.now(),
1092
+ key: isString(key)
1093
+ ? key
1094
+ : isMessageFunction(format)
1095
+ ? format.key
1096
+ : '',
1097
+ locale: targetLocale || (isMessageFunction(format)
1098
+ ? format.locale
1099
+ : ''),
1100
+ format: isString(format)
1101
+ ? format
1102
+ : isMessageFunction(format)
1103
+ ? format.source
1104
+ : '',
1105
+ message: ret
1106
+ };
1107
+ payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
1108
+ translateDevTools(payloads);
1109
+ }
1110
+ return ret;
1111
+ }
1112
+ function escapeParams(options) {
1113
+ if (isArray(options.list)) {
1114
+ options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
1115
+ }
1116
+ else if (isObject(options.named)) {
1117
+ Object.keys(options.named).forEach(key => {
1118
+ if (isString(options.named[key])) {
1119
+ options.named[key] = escapeHtml(options.named[key]);
1120
+ }
1121
+ });
1122
+ }
1123
+ }
1124
+ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1125
+ const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1126
+ const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1127
+ let message = {};
1128
+ let targetLocale;
1129
+ let format = null;
1130
+ let from = locale;
1131
+ let to = null;
1132
+ const type = 'translate';
1133
+ for (let i = 0; i < locales.length; i++) {
1134
+ targetLocale = to = locales[i];
1135
+ if (locale !== targetLocale &&
1136
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1137
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
1138
+ key,
1139
+ target: targetLocale
1140
+ }));
1141
+ }
1142
+ // for vue-devtools timeline event
1143
+ if (locale !== targetLocale) {
1144
+ const emitter = context.__v_emitter;
1145
+ if (emitter) {
1146
+ emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1147
+ type,
1148
+ key,
1149
+ from,
1150
+ to,
1151
+ groupId: `${type}:${key}`
1152
+ });
1153
+ }
1154
+ }
1155
+ message =
1156
+ messages[targetLocale] || {};
1157
+ // for vue-devtools timeline event
1158
+ let start = null;
1159
+ let startTag;
1160
+ let endTag;
1161
+ if (inBrowser) {
1162
+ start = window.performance.now();
1163
+ startTag = 'intlify-message-resolve-start';
1164
+ endTag = 'intlify-message-resolve-end';
1165
+ mark && mark(startTag);
1166
+ }
1167
+ if ((format = resolveValue(message, key)) === null) {
1168
+ // if null, resolve with object key path
1169
+ format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
1170
+ }
1171
+ // for vue-devtools timeline event
1172
+ if (inBrowser) {
1173
+ const end = window.performance.now();
1174
+ const emitter = context.__v_emitter;
1175
+ if (emitter && start && format) {
1176
+ emitter.emit("message-resolve" /* VueDevToolsTimelineEvents.MESSAGE_RESOLVE */, {
1177
+ type: "message-resolve" /* VueDevToolsTimelineEvents.MESSAGE_RESOLVE */,
1178
+ key,
1179
+ message: format,
1180
+ time: end - start,
1181
+ groupId: `${type}:${key}`
1182
+ });
1183
+ }
1184
+ if (startTag && endTag && mark && measure) {
1185
+ mark(endTag);
1186
+ measure('intlify message resolve', startTag, endTag);
1187
+ }
1188
+ }
1189
+ if (isString(format) || isFunction(format))
1190
+ break;
1191
+ const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1192
+ key, targetLocale, missingWarn, type);
1193
+ if (missingRet !== key) {
1194
+ format = missingRet;
1195
+ }
1196
+ from = to;
1197
+ }
1198
+ return [format, targetLocale, message];
1199
+ }
1200
+ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
1201
+ const { messageCompiler, warnHtmlMessage } = context;
1202
+ if (isMessageFunction(format)) {
1203
+ const msg = format;
1204
+ msg.locale = msg.locale || targetLocale;
1205
+ msg.key = msg.key || key;
1206
+ return msg;
1207
+ }
1208
+ if (messageCompiler == null) {
1209
+ const msg = (() => format);
1210
+ msg.locale = targetLocale;
1211
+ msg.key = key;
1212
+ return msg;
1213
+ }
1214
+ // for vue-devtools timeline event
1215
+ let start = null;
1216
+ let startTag;
1217
+ let endTag;
1218
+ if (inBrowser) {
1219
+ start = window.performance.now();
1220
+ startTag = 'intlify-message-compilation-start';
1221
+ endTag = 'intlify-message-compilation-end';
1222
+ mark && mark(startTag);
1223
+ }
1224
+ const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
1225
+ // for vue-devtools timeline event
1226
+ if (inBrowser) {
1227
+ const end = window.performance.now();
1228
+ const emitter = context.__v_emitter;
1229
+ if (emitter && start) {
1230
+ emitter.emit("message-compilation" /* VueDevToolsTimelineEvents.MESSAGE_COMPILATION */, {
1231
+ type: "message-compilation" /* VueDevToolsTimelineEvents.MESSAGE_COMPILATION */,
1232
+ message: format,
1233
+ time: end - start,
1234
+ groupId: `${'translate'}:${key}`
1235
+ });
1236
+ }
1237
+ if (startTag && endTag && mark && measure) {
1238
+ mark(endTag);
1239
+ measure('intlify message compilation', startTag, endTag);
1240
+ }
1241
+ }
1242
+ msg.locale = targetLocale;
1243
+ msg.key = key;
1244
+ msg.source = format;
1245
+ return msg;
1246
+ }
1247
+ function evaluateMessage(context, msg, msgCtx) {
1248
+ // for vue-devtools timeline event
1249
+ let start = null;
1250
+ let startTag;
1251
+ let endTag;
1252
+ if (inBrowser) {
1253
+ start = window.performance.now();
1254
+ startTag = 'intlify-message-evaluation-start';
1255
+ endTag = 'intlify-message-evaluation-end';
1256
+ mark && mark(startTag);
1257
+ }
1258
+ const messaged = msg(msgCtx);
1259
+ // for vue-devtools timeline event
1260
+ if (inBrowser) {
1261
+ const end = window.performance.now();
1262
+ const emitter = context.__v_emitter;
1263
+ if (emitter && start) {
1264
+ emitter.emit("message-evaluation" /* VueDevToolsTimelineEvents.MESSAGE_EVALUATION */, {
1265
+ type: "message-evaluation" /* VueDevToolsTimelineEvents.MESSAGE_EVALUATION */,
1266
+ value: messaged,
1267
+ time: end - start,
1268
+ groupId: `${'translate'}:${msg.key}`
1269
+ });
1270
+ }
1271
+ if (startTag && endTag && mark && measure) {
1272
+ mark(endTag);
1273
+ measure('intlify message evaluation', startTag, endTag);
1274
+ }
1275
+ }
1276
+ return messaged;
1277
+ }
1278
+ /** @internal */
1279
+ function parseTranslateArgs(...args) {
1280
+ const [arg1, arg2, arg3] = args;
1281
+ const options = {};
1282
+ if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) {
1283
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1284
+ }
1285
+ // prettier-ignore
1286
+ const key = isNumber(arg1)
1287
+ ? String(arg1)
1288
+ : isMessageFunction(arg1)
1289
+ ? arg1
1290
+ : arg1;
1291
+ if (isNumber(arg2)) {
1292
+ options.plural = arg2;
1293
+ }
1294
+ else if (isString(arg2)) {
1295
+ options.default = arg2;
1296
+ }
1297
+ else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
1298
+ options.named = arg2;
1299
+ }
1300
+ else if (isArray(arg2)) {
1301
+ options.list = arg2;
1302
+ }
1303
+ if (isNumber(arg3)) {
1304
+ options.plural = arg3;
1305
+ }
1306
+ else if (isString(arg3)) {
1307
+ options.default = arg3;
1308
+ }
1309
+ else if (isPlainObject(arg3)) {
1310
+ assign(options, arg3);
1311
+ }
1312
+ return [key, options];
1313
+ }
1314
+ function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
1315
+ return {
1316
+ warnHtmlMessage,
1317
+ onError: (err) => {
1318
+ errorDetector && errorDetector(err);
1319
+ {
1320
+ const message = `Message compilation error: ${err.message}`;
1321
+ const codeFrame = err.location &&
1322
+ generateCodeFrame(source, err.location.start.offset, err.location.end.offset);
1323
+ const emitter = context.__v_emitter;
1324
+ if (emitter) {
1325
+ emitter.emit("compile-error" /* VueDevToolsTimelineEvents.COMPILE_ERROR */, {
1326
+ message: source,
1327
+ error: err.message,
1328
+ start: err.location && err.location.start.offset,
1329
+ end: err.location && err.location.end.offset,
1330
+ groupId: `${'translate'}:${key}`
1331
+ });
1332
+ }
1333
+ console.error(codeFrame ? `${message}\n${codeFrame}` : message);
1334
+ }
1335
+ },
1336
+ onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
1337
+ };
1338
+ }
1339
+ function getMessageContextOptions(context, locale, message, options) {
1340
+ const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
1341
+ const resolveMessage = (key) => {
1342
+ let val = resolveValue(message, key);
1343
+ // fallback to root context
1344
+ if (val == null && fallbackContext) {
1345
+ const [, , message] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
1346
+ val = resolveValue(message, key);
1347
+ }
1348
+ if (isString(val)) {
1349
+ let occurred = false;
1350
+ const errorDetector = () => {
1351
+ occurred = true;
1352
+ };
1353
+ const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
1354
+ return !occurred
1355
+ ? msg
1356
+ : NOOP_MESSAGE_FUNCTION;
1357
+ }
1358
+ else if (isMessageFunction(val)) {
1359
+ return val;
1360
+ }
1361
+ else {
1362
+ // TODO: should be implemented warning message
1363
+ return NOOP_MESSAGE_FUNCTION;
1364
+ }
1365
+ };
1366
+ const ctxOptions = {
1367
+ locale,
1368
+ modifiers,
1369
+ pluralRules,
1370
+ messages: resolveMessage
1371
+ };
1372
+ if (context.processor) {
1373
+ ctxOptions.processor = context.processor;
1374
+ }
1375
+ if (options.list) {
1376
+ ctxOptions.list = options.list;
1377
+ }
1378
+ if (options.named) {
1379
+ ctxOptions.named = options.named;
1380
+ }
1381
+ if (isNumber(options.plural)) {
1382
+ ctxOptions.pluralIndex = options.plural;
1383
+ }
1384
+ return ctxOptions;
1380
1385
  }
1381
1386
 
1382
- const intlDefined = typeof Intl !== 'undefined';
1383
- const Availabilities = {
1384
- dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
1385
- numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
1387
+ const intlDefined = typeof Intl !== 'undefined';
1388
+ const Availabilities = {
1389
+ dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
1390
+ numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
1386
1391
  };
1387
1392
 
1388
- // implementation of `datetime` function
1389
- function datetime(context, ...args) {
1390
- const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1391
- const { __datetimeFormatters } = context;
1392
- if (!Availabilities.dateTimeFormat) {
1393
- onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
1394
- return MISSING_RESOLVE_VALUE;
1395
- }
1396
- const [key, value, options, overrides] = parseDateTimeArgs(...args);
1397
- const missingWarn = isBoolean(options.missingWarn)
1398
- ? options.missingWarn
1399
- : context.missingWarn;
1400
- const fallbackWarn = isBoolean(options.fallbackWarn)
1401
- ? options.fallbackWarn
1402
- : context.fallbackWarn;
1403
- const part = !!options.part;
1404
- const locale = isString(options.locale) ? options.locale : context.locale;
1405
- const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1406
- fallbackLocale, locale);
1407
- if (!isString(key) || key === '') {
1408
- return new Intl.DateTimeFormat(locale, overrides).format(value);
1409
- }
1410
- // resolve format
1411
- let datetimeFormat = {};
1412
- let targetLocale;
1413
- let format = null;
1414
- let from = locale;
1415
- let to = null;
1416
- const type = 'datetime format';
1417
- for (let i = 0; i < locales.length; i++) {
1418
- targetLocale = to = locales[i];
1419
- if (locale !== targetLocale &&
1420
- isTranslateFallbackWarn(fallbackWarn, key)) {
1421
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1422
- key,
1423
- target: targetLocale
1424
- }));
1425
- }
1426
- // for vue-devtools timeline event
1427
- if (locale !== targetLocale) {
1428
- const emitter = context.__v_emitter;
1429
- if (emitter) {
1430
- emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1431
- type,
1432
- key,
1433
- from,
1434
- to,
1435
- groupId: `${type}:${key}`
1436
- });
1437
- }
1438
- }
1439
- datetimeFormat =
1440
- datetimeFormats[targetLocale] || {};
1441
- format = datetimeFormat[key];
1442
- if (isPlainObject(format))
1443
- break;
1444
- handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1445
- from = to;
1446
- }
1447
- // checking format and target locale
1448
- if (!isPlainObject(format) || !isString(targetLocale)) {
1449
- return unresolving ? NOT_REOSLVED : key;
1450
- }
1451
- let id = `${targetLocale}__${key}`;
1452
- if (!isEmptyObject(overrides)) {
1453
- id = `${id}__${JSON.stringify(overrides)}`;
1454
- }
1455
- let formatter = __datetimeFormatters.get(id);
1456
- if (!formatter) {
1457
- formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1458
- __datetimeFormatters.set(id, formatter);
1459
- }
1460
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1461
- }
1462
- /** @internal */
1463
- const DATETIME_FORMAT_OPTIONS_KEYS = [
1464
- 'localeMatcher',
1465
- 'weekday',
1466
- 'era',
1467
- 'year',
1468
- 'month',
1469
- 'day',
1470
- 'hour',
1471
- 'minute',
1472
- 'second',
1473
- 'timeZoneName',
1474
- 'formatMatcher',
1475
- 'hour12',
1476
- 'timeZone',
1477
- 'dateStyle',
1478
- 'timeStyle',
1479
- 'calendar',
1480
- 'dayPeriod',
1481
- 'numberingSystem',
1482
- 'hourCycle',
1483
- 'fractionalSecondDigits'
1484
- ];
1485
- /** @internal */
1486
- function parseDateTimeArgs(...args) {
1487
- const [arg1, arg2, arg3, arg4] = args;
1488
- const options = {};
1489
- let overrides = {};
1490
- let value;
1491
- if (isString(arg1)) {
1492
- // Only allow ISO strings - other date formats are often supported,
1493
- // but may cause different results in different browsers.
1494
- const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
1495
- if (!matches) {
1496
- throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1497
- }
1498
- // Some browsers can not parse the iso datetime separated by space,
1499
- // this is a compromise solution by replace the 'T'/' ' with 'T'
1500
- const dateTime = matches[3]
1501
- ? matches[3].trim().startsWith('T')
1502
- ? `${matches[1].trim()}${matches[3].trim()}`
1503
- : `${matches[1].trim()}T${matches[3].trim()}`
1504
- : matches[1].trim();
1505
- value = new Date(dateTime);
1506
- try {
1507
- // This will fail if the date is not valid
1508
- value.toISOString();
1509
- }
1510
- catch (e) {
1511
- throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1512
- }
1513
- }
1514
- else if (isDate(arg1)) {
1515
- if (isNaN(arg1.getTime())) {
1516
- throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
1517
- }
1518
- value = arg1;
1519
- }
1520
- else if (isNumber(arg1)) {
1521
- value = arg1;
1522
- }
1523
- else {
1524
- throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1525
- }
1526
- if (isString(arg2)) {
1527
- options.key = arg2;
1528
- }
1529
- else if (isPlainObject(arg2)) {
1530
- Object.keys(arg2).forEach(key => {
1531
- if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
1532
- overrides[key] = arg2[key];
1533
- }
1534
- else {
1535
- options[key] = arg2[key];
1536
- }
1537
- });
1538
- }
1539
- if (isString(arg3)) {
1540
- options.locale = arg3;
1541
- }
1542
- else if (isPlainObject(arg3)) {
1543
- overrides = arg3;
1544
- }
1545
- if (isPlainObject(arg4)) {
1546
- overrides = arg4;
1547
- }
1548
- return [options.key || '', value, options, overrides];
1549
- }
1550
- /** @internal */
1551
- function clearDateTimeFormat(ctx, locale, format) {
1552
- const context = ctx;
1553
- for (const key in format) {
1554
- const id = `${locale}__${key}`;
1555
- if (!context.__datetimeFormatters.has(id)) {
1556
- continue;
1557
- }
1558
- context.__datetimeFormatters.delete(id);
1559
- }
1393
+ // implementation of `datetime` function
1394
+ function datetime(context, ...args) {
1395
+ const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1396
+ const { __datetimeFormatters } = context;
1397
+ if (!Availabilities.dateTimeFormat) {
1398
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
1399
+ return MISSING_RESOLVE_VALUE;
1400
+ }
1401
+ const [key, value, options, overrides] = parseDateTimeArgs(...args);
1402
+ const missingWarn = isBoolean(options.missingWarn)
1403
+ ? options.missingWarn
1404
+ : context.missingWarn;
1405
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1406
+ ? options.fallbackWarn
1407
+ : context.fallbackWarn;
1408
+ const part = !!options.part;
1409
+ const locale = isString(options.locale) ? options.locale : context.locale;
1410
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1411
+ fallbackLocale, locale);
1412
+ if (!isString(key) || key === '') {
1413
+ return new Intl.DateTimeFormat(locale, overrides).format(value);
1414
+ }
1415
+ // resolve format
1416
+ let datetimeFormat = {};
1417
+ let targetLocale;
1418
+ let format = null;
1419
+ let from = locale;
1420
+ let to = null;
1421
+ const type = 'datetime format';
1422
+ for (let i = 0; i < locales.length; i++) {
1423
+ targetLocale = to = locales[i];
1424
+ if (locale !== targetLocale &&
1425
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1426
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1427
+ key,
1428
+ target: targetLocale
1429
+ }));
1430
+ }
1431
+ // for vue-devtools timeline event
1432
+ if (locale !== targetLocale) {
1433
+ const emitter = context.__v_emitter;
1434
+ if (emitter) {
1435
+ emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1436
+ type,
1437
+ key,
1438
+ from,
1439
+ to,
1440
+ groupId: `${type}:${key}`
1441
+ });
1442
+ }
1443
+ }
1444
+ datetimeFormat =
1445
+ datetimeFormats[targetLocale] || {};
1446
+ format = datetimeFormat[key];
1447
+ if (isPlainObject(format))
1448
+ break;
1449
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1450
+ from = to;
1451
+ }
1452
+ // checking format and target locale
1453
+ if (!isPlainObject(format) || !isString(targetLocale)) {
1454
+ return unresolving ? NOT_REOSLVED : key;
1455
+ }
1456
+ let id = `${targetLocale}__${key}`;
1457
+ if (!isEmptyObject(overrides)) {
1458
+ id = `${id}__${JSON.stringify(overrides)}`;
1459
+ }
1460
+ let formatter = __datetimeFormatters.get(id);
1461
+ if (!formatter) {
1462
+ formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1463
+ __datetimeFormatters.set(id, formatter);
1464
+ }
1465
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1466
+ }
1467
+ /** @internal */
1468
+ const DATETIME_FORMAT_OPTIONS_KEYS = [
1469
+ 'localeMatcher',
1470
+ 'weekday',
1471
+ 'era',
1472
+ 'year',
1473
+ 'month',
1474
+ 'day',
1475
+ 'hour',
1476
+ 'minute',
1477
+ 'second',
1478
+ 'timeZoneName',
1479
+ 'formatMatcher',
1480
+ 'hour12',
1481
+ 'timeZone',
1482
+ 'dateStyle',
1483
+ 'timeStyle',
1484
+ 'calendar',
1485
+ 'dayPeriod',
1486
+ 'numberingSystem',
1487
+ 'hourCycle',
1488
+ 'fractionalSecondDigits'
1489
+ ];
1490
+ /** @internal */
1491
+ function parseDateTimeArgs(...args) {
1492
+ const [arg1, arg2, arg3, arg4] = args;
1493
+ const options = {};
1494
+ let overrides = {};
1495
+ let value;
1496
+ if (isString(arg1)) {
1497
+ // Only allow ISO strings - other date formats are often supported,
1498
+ // but may cause different results in different browsers.
1499
+ const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
1500
+ if (!matches) {
1501
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1502
+ }
1503
+ // Some browsers can not parse the iso datetime separated by space,
1504
+ // this is a compromise solution by replace the 'T'/' ' with 'T'
1505
+ const dateTime = matches[3]
1506
+ ? matches[3].trim().startsWith('T')
1507
+ ? `${matches[1].trim()}${matches[3].trim()}`
1508
+ : `${matches[1].trim()}T${matches[3].trim()}`
1509
+ : matches[1].trim();
1510
+ value = new Date(dateTime);
1511
+ try {
1512
+ // This will fail if the date is not valid
1513
+ value.toISOString();
1514
+ }
1515
+ catch (e) {
1516
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1517
+ }
1518
+ }
1519
+ else if (isDate(arg1)) {
1520
+ if (isNaN(arg1.getTime())) {
1521
+ throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
1522
+ }
1523
+ value = arg1;
1524
+ }
1525
+ else if (isNumber(arg1)) {
1526
+ value = arg1;
1527
+ }
1528
+ else {
1529
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1530
+ }
1531
+ if (isString(arg2)) {
1532
+ options.key = arg2;
1533
+ }
1534
+ else if (isPlainObject(arg2)) {
1535
+ Object.keys(arg2).forEach(key => {
1536
+ if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
1537
+ overrides[key] = arg2[key];
1538
+ }
1539
+ else {
1540
+ options[key] = arg2[key];
1541
+ }
1542
+ });
1543
+ }
1544
+ if (isString(arg3)) {
1545
+ options.locale = arg3;
1546
+ }
1547
+ else if (isPlainObject(arg3)) {
1548
+ overrides = arg3;
1549
+ }
1550
+ if (isPlainObject(arg4)) {
1551
+ overrides = arg4;
1552
+ }
1553
+ return [options.key || '', value, options, overrides];
1554
+ }
1555
+ /** @internal */
1556
+ function clearDateTimeFormat(ctx, locale, format) {
1557
+ const context = ctx;
1558
+ for (const key in format) {
1559
+ const id = `${locale}__${key}`;
1560
+ if (!context.__datetimeFormatters.has(id)) {
1561
+ continue;
1562
+ }
1563
+ context.__datetimeFormatters.delete(id);
1564
+ }
1560
1565
  }
1561
1566
 
1562
- // implementation of `number` function
1563
- function number(context, ...args) {
1564
- const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1565
- const { __numberFormatters } = context;
1566
- if (!Availabilities.numberFormat) {
1567
- onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
1568
- return MISSING_RESOLVE_VALUE;
1569
- }
1570
- const [key, value, options, overrides] = parseNumberArgs(...args);
1571
- const missingWarn = isBoolean(options.missingWarn)
1572
- ? options.missingWarn
1573
- : context.missingWarn;
1574
- const fallbackWarn = isBoolean(options.fallbackWarn)
1575
- ? options.fallbackWarn
1576
- : context.fallbackWarn;
1577
- const part = !!options.part;
1578
- const locale = isString(options.locale) ? options.locale : context.locale;
1579
- const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1580
- fallbackLocale, locale);
1581
- if (!isString(key) || key === '') {
1582
- return new Intl.NumberFormat(locale, overrides).format(value);
1583
- }
1584
- // resolve format
1585
- let numberFormat = {};
1586
- let targetLocale;
1587
- let format = null;
1588
- let from = locale;
1589
- let to = null;
1590
- const type = 'number format';
1591
- for (let i = 0; i < locales.length; i++) {
1592
- targetLocale = to = locales[i];
1593
- if (locale !== targetLocale &&
1594
- isTranslateFallbackWarn(fallbackWarn, key)) {
1595
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1596
- key,
1597
- target: targetLocale
1598
- }));
1599
- }
1600
- // for vue-devtools timeline event
1601
- if (locale !== targetLocale) {
1602
- const emitter = context.__v_emitter;
1603
- if (emitter) {
1604
- emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1605
- type,
1606
- key,
1607
- from,
1608
- to,
1609
- groupId: `${type}:${key}`
1610
- });
1611
- }
1612
- }
1613
- numberFormat =
1614
- numberFormats[targetLocale] || {};
1615
- format = numberFormat[key];
1616
- if (isPlainObject(format))
1617
- break;
1618
- handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1619
- from = to;
1620
- }
1621
- // checking format and target locale
1622
- if (!isPlainObject(format) || !isString(targetLocale)) {
1623
- return unresolving ? NOT_REOSLVED : key;
1624
- }
1625
- let id = `${targetLocale}__${key}`;
1626
- if (!isEmptyObject(overrides)) {
1627
- id = `${id}__${JSON.stringify(overrides)}`;
1628
- }
1629
- let formatter = __numberFormatters.get(id);
1630
- if (!formatter) {
1631
- formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1632
- __numberFormatters.set(id, formatter);
1633
- }
1634
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1635
- }
1636
- /** @internal */
1637
- const NUMBER_FORMAT_OPTIONS_KEYS = [
1638
- 'localeMatcher',
1639
- 'style',
1640
- 'currency',
1641
- 'currencyDisplay',
1642
- 'currencySign',
1643
- 'useGrouping',
1644
- 'minimumIntegerDigits',
1645
- 'minimumFractionDigits',
1646
- 'maximumFractionDigits',
1647
- 'minimumSignificantDigits',
1648
- 'maximumSignificantDigits',
1649
- 'compactDisplay',
1650
- 'notation',
1651
- 'signDisplay',
1652
- 'unit',
1653
- 'unitDisplay',
1654
- 'roundingMode',
1655
- 'roundingPriority',
1656
- 'roundingIncrement',
1657
- 'trailingZeroDisplay'
1658
- ];
1659
- /** @internal */
1660
- function parseNumberArgs(...args) {
1661
- const [arg1, arg2, arg3, arg4] = args;
1662
- const options = {};
1663
- let overrides = {};
1664
- if (!isNumber(arg1)) {
1665
- throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1666
- }
1667
- const value = arg1;
1668
- if (isString(arg2)) {
1669
- options.key = arg2;
1670
- }
1671
- else if (isPlainObject(arg2)) {
1672
- Object.keys(arg2).forEach(key => {
1673
- if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
1674
- overrides[key] = arg2[key];
1675
- }
1676
- else {
1677
- options[key] = arg2[key];
1678
- }
1679
- });
1680
- }
1681
- if (isString(arg3)) {
1682
- options.locale = arg3;
1683
- }
1684
- else if (isPlainObject(arg3)) {
1685
- overrides = arg3;
1686
- }
1687
- if (isPlainObject(arg4)) {
1688
- overrides = arg4;
1689
- }
1690
- return [options.key || '', value, options, overrides];
1691
- }
1692
- /** @internal */
1693
- function clearNumberFormat(ctx, locale, format) {
1694
- const context = ctx;
1695
- for (const key in format) {
1696
- const id = `${locale}__${key}`;
1697
- if (!context.__numberFormatters.has(id)) {
1698
- continue;
1699
- }
1700
- context.__numberFormatters.delete(id);
1701
- }
1567
+ // implementation of `number` function
1568
+ function number(context, ...args) {
1569
+ const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1570
+ const { __numberFormatters } = context;
1571
+ if (!Availabilities.numberFormat) {
1572
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
1573
+ return MISSING_RESOLVE_VALUE;
1574
+ }
1575
+ const [key, value, options, overrides] = parseNumberArgs(...args);
1576
+ const missingWarn = isBoolean(options.missingWarn)
1577
+ ? options.missingWarn
1578
+ : context.missingWarn;
1579
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1580
+ ? options.fallbackWarn
1581
+ : context.fallbackWarn;
1582
+ const part = !!options.part;
1583
+ const locale = isString(options.locale) ? options.locale : context.locale;
1584
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1585
+ fallbackLocale, locale);
1586
+ if (!isString(key) || key === '') {
1587
+ return new Intl.NumberFormat(locale, overrides).format(value);
1588
+ }
1589
+ // resolve format
1590
+ let numberFormat = {};
1591
+ let targetLocale;
1592
+ let format = null;
1593
+ let from = locale;
1594
+ let to = null;
1595
+ const type = 'number format';
1596
+ for (let i = 0; i < locales.length; i++) {
1597
+ targetLocale = to = locales[i];
1598
+ if (locale !== targetLocale &&
1599
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1600
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1601
+ key,
1602
+ target: targetLocale
1603
+ }));
1604
+ }
1605
+ // for vue-devtools timeline event
1606
+ if (locale !== targetLocale) {
1607
+ const emitter = context.__v_emitter;
1608
+ if (emitter) {
1609
+ emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1610
+ type,
1611
+ key,
1612
+ from,
1613
+ to,
1614
+ groupId: `${type}:${key}`
1615
+ });
1616
+ }
1617
+ }
1618
+ numberFormat =
1619
+ numberFormats[targetLocale] || {};
1620
+ format = numberFormat[key];
1621
+ if (isPlainObject(format))
1622
+ break;
1623
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1624
+ from = to;
1625
+ }
1626
+ // checking format and target locale
1627
+ if (!isPlainObject(format) || !isString(targetLocale)) {
1628
+ return unresolving ? NOT_REOSLVED : key;
1629
+ }
1630
+ let id = `${targetLocale}__${key}`;
1631
+ if (!isEmptyObject(overrides)) {
1632
+ id = `${id}__${JSON.stringify(overrides)}`;
1633
+ }
1634
+ let formatter = __numberFormatters.get(id);
1635
+ if (!formatter) {
1636
+ formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1637
+ __numberFormatters.set(id, formatter);
1638
+ }
1639
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1640
+ }
1641
+ /** @internal */
1642
+ const NUMBER_FORMAT_OPTIONS_KEYS = [
1643
+ 'localeMatcher',
1644
+ 'style',
1645
+ 'currency',
1646
+ 'currencyDisplay',
1647
+ 'currencySign',
1648
+ 'useGrouping',
1649
+ 'minimumIntegerDigits',
1650
+ 'minimumFractionDigits',
1651
+ 'maximumFractionDigits',
1652
+ 'minimumSignificantDigits',
1653
+ 'maximumSignificantDigits',
1654
+ 'compactDisplay',
1655
+ 'notation',
1656
+ 'signDisplay',
1657
+ 'unit',
1658
+ 'unitDisplay',
1659
+ 'roundingMode',
1660
+ 'roundingPriority',
1661
+ 'roundingIncrement',
1662
+ 'trailingZeroDisplay'
1663
+ ];
1664
+ /** @internal */
1665
+ function parseNumberArgs(...args) {
1666
+ const [arg1, arg2, arg3, arg4] = args;
1667
+ const options = {};
1668
+ let overrides = {};
1669
+ if (!isNumber(arg1)) {
1670
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1671
+ }
1672
+ const value = arg1;
1673
+ if (isString(arg2)) {
1674
+ options.key = arg2;
1675
+ }
1676
+ else if (isPlainObject(arg2)) {
1677
+ Object.keys(arg2).forEach(key => {
1678
+ if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
1679
+ overrides[key] = arg2[key];
1680
+ }
1681
+ else {
1682
+ options[key] = arg2[key];
1683
+ }
1684
+ });
1685
+ }
1686
+ if (isString(arg3)) {
1687
+ options.locale = arg3;
1688
+ }
1689
+ else if (isPlainObject(arg3)) {
1690
+ overrides = arg3;
1691
+ }
1692
+ if (isPlainObject(arg4)) {
1693
+ overrides = arg4;
1694
+ }
1695
+ return [options.key || '', value, options, overrides];
1696
+ }
1697
+ /** @internal */
1698
+ function clearNumberFormat(ctx, locale, format) {
1699
+ const context = ctx;
1700
+ for (const key in format) {
1701
+ const id = `${locale}__${key}`;
1702
+ if (!context.__numberFormatters.has(id)) {
1703
+ continue;
1704
+ }
1705
+ context.__numberFormatters.delete(id);
1706
+ }
1702
1707
  }
1703
1708
 
1704
- // register message resolver at @intlify/core
1705
- registerMessageResolver(resolveValue);
1706
- // register fallback locale at @intlify/core
1709
+ // register message resolver at @intlify/core
1710
+ registerMessageResolver(resolveValue);
1711
+ // register fallback locale at @intlify/core
1707
1712
  registerLocaleFallbacker(fallbackWithLocaleChain);
1708
1713
 
1709
1714
  export { CompileErrorCodes, CoreErrorCodes, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_REOSLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compileToFunction, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getAdditionalMeta, getDevToolsHook, getFallbackContext, getWarnMessage, handleMissing, initI18nDevTools, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveValue, resolveWithKeyValue, setAdditionalMeta, setDevToolsHook, setFallbackContext, translate, translateDevTools, updateFallbackLocale };