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