@wordpress/i18n 4.38.0 → 4.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/create-i18n.js +57 -128
- package/build/create-i18n.js.map +1 -1
- package/build/default-i18n.js +11 -24
- package/build/default-i18n.js.map +1 -1
- package/build/index.js +0 -6
- package/build/index.js.map +1 -1
- package/build/sprintf.js +0 -6
- package/build/sprintf.js.map +1 -1
- package/build-module/create-i18n.js +58 -125
- package/build-module/create-i18n.js.map +1 -1
- package/build-module/default-i18n.js +12 -12
- package/build-module/default-i18n.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/sprintf.js +1 -3
- package/build-module/sprintf.js.map +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import Tannin from 'tannin';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {Record<string,any>} LocaleData
|
|
7
8
|
*/
|
|
@@ -12,22 +13,21 @@ import Tannin from 'tannin';
|
|
|
12
13
|
*
|
|
13
14
|
* @type {LocaleData}
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
16
|
const DEFAULT_LOCALE_DATA = {
|
|
17
17
|
'': {
|
|
18
18
|
/** @param {number} n */
|
|
19
19
|
plural_forms(n) {
|
|
20
20
|
return n === 1 ? 0 : 1;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
}
|
|
24
23
|
};
|
|
24
|
+
|
|
25
25
|
/*
|
|
26
26
|
* Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,
|
|
27
27
|
* `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
29
|
const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
30
|
+
|
|
31
31
|
/**
|
|
32
32
|
* @typedef {(domain?: string) => LocaleData} GetLocaleData
|
|
33
33
|
*
|
|
@@ -36,7 +36,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
36
36
|
*
|
|
37
37
|
* @see http://messageformat.github.io/Jed/
|
|
38
38
|
*/
|
|
39
|
-
|
|
40
39
|
/**
|
|
41
40
|
* @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
|
|
42
41
|
*
|
|
@@ -46,7 +45,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
46
45
|
*
|
|
47
46
|
* @see http://messageformat.github.io/Jed/
|
|
48
47
|
*/
|
|
49
|
-
|
|
50
48
|
/**
|
|
51
49
|
* @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
|
|
52
50
|
*
|
|
@@ -56,7 +54,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
56
54
|
*
|
|
57
55
|
* @see http://messageformat.github.io/Jed/
|
|
58
56
|
*/
|
|
59
|
-
|
|
60
57
|
/**
|
|
61
58
|
* @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData
|
|
62
59
|
*
|
|
@@ -65,22 +62,17 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
65
62
|
*
|
|
66
63
|
* @see http://messageformat.github.io/Jed/
|
|
67
64
|
*/
|
|
68
|
-
|
|
69
65
|
/** @typedef {() => void} SubscribeCallback */
|
|
70
|
-
|
|
71
66
|
/** @typedef {() => void} UnsubscribeCallback */
|
|
72
|
-
|
|
73
67
|
/**
|
|
74
68
|
* @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe
|
|
75
69
|
*
|
|
76
70
|
* Subscribes to changes of locale data
|
|
77
71
|
*/
|
|
78
|
-
|
|
79
72
|
/**
|
|
80
73
|
* @typedef {(domain?: string) => string} GetFilterDomain
|
|
81
74
|
* Retrieve the domain to use when calling domain-specific filters.
|
|
82
75
|
*/
|
|
83
|
-
|
|
84
76
|
/**
|
|
85
77
|
* @typedef {(text: string, domain?: string) => string} __
|
|
86
78
|
*
|
|
@@ -88,7 +80,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
88
80
|
*
|
|
89
81
|
* @see https://developer.wordpress.org/reference/functions/__/
|
|
90
82
|
*/
|
|
91
|
-
|
|
92
83
|
/**
|
|
93
84
|
* @typedef {(text: string, context: string, domain?: string) => string} _x
|
|
94
85
|
*
|
|
@@ -96,7 +87,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
96
87
|
*
|
|
97
88
|
* @see https://developer.wordpress.org/reference/functions/_x/
|
|
98
89
|
*/
|
|
99
|
-
|
|
100
90
|
/**
|
|
101
91
|
* @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
|
|
102
92
|
*
|
|
@@ -105,7 +95,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
105
95
|
*
|
|
106
96
|
* @see https://developer.wordpress.org/reference/functions/_n/
|
|
107
97
|
*/
|
|
108
|
-
|
|
109
98
|
/**
|
|
110
99
|
* @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
|
|
111
100
|
*
|
|
@@ -114,7 +103,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
114
103
|
*
|
|
115
104
|
* @see https://developer.wordpress.org/reference/functions/_nx/
|
|
116
105
|
*/
|
|
117
|
-
|
|
118
106
|
/**
|
|
119
107
|
* @typedef {() => boolean} IsRtl
|
|
120
108
|
*
|
|
@@ -125,13 +113,11 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
125
113
|
* language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
|
|
126
114
|
* including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
|
|
127
115
|
*/
|
|
128
|
-
|
|
129
116
|
/**
|
|
130
117
|
* @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation
|
|
131
118
|
*
|
|
132
119
|
* Check if there is a translation for a given string in singular form.
|
|
133
120
|
*/
|
|
134
|
-
|
|
135
121
|
/** @typedef {import('@wordpress/hooks').Hooks} Hooks */
|
|
136
122
|
|
|
137
123
|
/**
|
|
@@ -167,7 +153,6 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
|
167
153
|
*
|
|
168
154
|
* @return {I18n} I18n instance.
|
|
169
155
|
*/
|
|
170
|
-
|
|
171
156
|
export const createI18n = (initialData, initialDomain, hooks) => {
|
|
172
157
|
/**
|
|
173
158
|
* The underlying instance of Tannin to which exported functions interface.
|
|
@@ -176,78 +161,80 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
176
161
|
*/
|
|
177
162
|
const tannin = new Tannin({});
|
|
178
163
|
const listeners = new Set();
|
|
179
|
-
|
|
180
164
|
const notifyListeners = () => {
|
|
181
165
|
listeners.forEach(listener => listener());
|
|
182
166
|
};
|
|
167
|
+
|
|
183
168
|
/**
|
|
184
169
|
* Subscribe to changes of locale data.
|
|
185
170
|
*
|
|
186
171
|
* @param {SubscribeCallback} callback Subscription callback.
|
|
187
172
|
* @return {UnsubscribeCallback} Unsubscribe callback.
|
|
188
173
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
174
|
const subscribe = callback => {
|
|
192
175
|
listeners.add(callback);
|
|
193
176
|
return () => listeners.delete(callback);
|
|
194
177
|
};
|
|
195
|
-
/** @type {GetLocaleData} */
|
|
196
|
-
|
|
197
178
|
|
|
179
|
+
/** @type {GetLocaleData} */
|
|
198
180
|
const getLocaleData = (domain = 'default') => tannin.data[domain];
|
|
181
|
+
|
|
199
182
|
/**
|
|
200
183
|
* @param {LocaleData} [data]
|
|
201
184
|
* @param {string} [domain]
|
|
202
185
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
186
|
const doSetLocaleData = (data, domain = 'default') => {
|
|
206
|
-
tannin.data[domain] = {
|
|
187
|
+
tannin.data[domain] = {
|
|
188
|
+
...tannin.data[domain],
|
|
207
189
|
...data
|
|
208
|
-
};
|
|
209
|
-
// a plural forms expression).
|
|
190
|
+
};
|
|
210
191
|
|
|
211
|
-
|
|
192
|
+
// Populate default domain configuration (supported locale date which omits
|
|
193
|
+
// a plural forms expression).
|
|
194
|
+
tannin.data[domain][''] = {
|
|
195
|
+
...DEFAULT_LOCALE_DATA[''],
|
|
212
196
|
...tannin.data[domain]?.['']
|
|
213
|
-
};
|
|
197
|
+
};
|
|
214
198
|
|
|
199
|
+
// Clean up cached plural forms functions cache as it might be updated.
|
|
215
200
|
delete tannin.pluralForms[domain];
|
|
216
201
|
};
|
|
217
|
-
/** @type {SetLocaleData} */
|
|
218
|
-
|
|
219
202
|
|
|
203
|
+
/** @type {SetLocaleData} */
|
|
220
204
|
const setLocaleData = (data, domain) => {
|
|
221
205
|
doSetLocaleData(data, domain);
|
|
222
206
|
notifyListeners();
|
|
223
207
|
};
|
|
224
|
-
/** @type {AddLocaleData} */
|
|
225
|
-
|
|
226
208
|
|
|
209
|
+
/** @type {AddLocaleData} */
|
|
227
210
|
const addLocaleData = (data, domain = 'default') => {
|
|
228
|
-
tannin.data[domain] = {
|
|
211
|
+
tannin.data[domain] = {
|
|
212
|
+
...tannin.data[domain],
|
|
229
213
|
...data,
|
|
230
214
|
// Populate default domain configuration (supported locale date which omits
|
|
231
215
|
// a plural forms expression).
|
|
232
|
-
'': {
|
|
216
|
+
'': {
|
|
217
|
+
...DEFAULT_LOCALE_DATA[''],
|
|
233
218
|
...tannin.data[domain]?.[''],
|
|
234
219
|
...data?.['']
|
|
235
220
|
}
|
|
236
|
-
};
|
|
221
|
+
};
|
|
237
222
|
|
|
223
|
+
// Clean up cached plural forms functions cache as it might be updated.
|
|
238
224
|
delete tannin.pluralForms[domain];
|
|
239
225
|
notifyListeners();
|
|
240
226
|
};
|
|
241
|
-
/** @type {ResetLocaleData} */
|
|
242
|
-
|
|
243
227
|
|
|
228
|
+
/** @type {ResetLocaleData} */
|
|
244
229
|
const resetLocaleData = (data, domain) => {
|
|
245
230
|
// Reset all current Tannin locale data.
|
|
246
|
-
tannin.data = {};
|
|
231
|
+
tannin.data = {};
|
|
247
232
|
|
|
233
|
+
// Reset cached plural forms functions cache.
|
|
248
234
|
tannin.pluralForms = {};
|
|
249
235
|
setLocaleData(data, domain);
|
|
250
236
|
};
|
|
237
|
+
|
|
251
238
|
/**
|
|
252
239
|
* Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
|
|
253
240
|
* otherwise previously assigned.
|
|
@@ -263,29 +250,24 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
263
250
|
*
|
|
264
251
|
* @return {string} The translated string.
|
|
265
252
|
*/
|
|
266
|
-
|
|
267
|
-
|
|
268
253
|
const dcnpgettext = (domain = 'default', context, single, plural, number) => {
|
|
269
254
|
if (!tannin.data[domain]) {
|
|
270
255
|
// Use `doSetLocaleData` to set silently, without notifying listeners.
|
|
271
256
|
doSetLocaleData(undefined, domain);
|
|
272
257
|
}
|
|
273
|
-
|
|
274
258
|
return tannin.dcnpgettext(domain, context, single, plural, number);
|
|
275
259
|
};
|
|
276
|
-
/** @type {GetFilterDomain} */
|
|
277
|
-
|
|
278
260
|
|
|
261
|
+
/** @type {GetFilterDomain} */
|
|
279
262
|
const getFilterDomain = (domain = 'default') => domain;
|
|
280
|
-
/** @type {__} */
|
|
281
|
-
|
|
282
263
|
|
|
264
|
+
/** @type {__} */
|
|
283
265
|
const __ = (text, domain) => {
|
|
284
266
|
let translation = dcnpgettext(domain, undefined, text);
|
|
285
|
-
|
|
286
267
|
if (!hooks) {
|
|
287
268
|
return translation;
|
|
288
269
|
}
|
|
270
|
+
|
|
289
271
|
/**
|
|
290
272
|
* Filters text with its translation.
|
|
291
273
|
*
|
|
@@ -293,29 +275,20 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
293
275
|
* @param {string} text Text to translate.
|
|
294
276
|
* @param {string} domain Text domain. Unique identifier for retrieving translated strings.
|
|
295
277
|
*/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
/** @type {*} */
|
|
302
|
-
hooks.applyFilters('i18n.gettext', translation, text, domain);
|
|
303
|
-
return (
|
|
304
|
-
/** @type {string} */
|
|
305
|
-
|
|
306
|
-
/** @type {*} */
|
|
307
|
-
hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain)
|
|
278
|
+
translation = /** @type {string} */
|
|
279
|
+
/** @type {*} */hooks.applyFilters('i18n.gettext', translation, text, domain);
|
|
280
|
+
return (/** @type {string} */
|
|
281
|
+
/** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain)
|
|
308
282
|
);
|
|
309
283
|
};
|
|
310
|
-
/** @type {_x} */
|
|
311
|
-
|
|
312
284
|
|
|
285
|
+
/** @type {_x} */
|
|
313
286
|
const _x = (text, context, domain) => {
|
|
314
287
|
let translation = dcnpgettext(domain, context, text);
|
|
315
|
-
|
|
316
288
|
if (!hooks) {
|
|
317
289
|
return translation;
|
|
318
290
|
}
|
|
291
|
+
|
|
319
292
|
/**
|
|
320
293
|
* Filters text with its translation based on context information.
|
|
321
294
|
*
|
|
@@ -324,29 +297,20 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
324
297
|
* @param {string} context Context information for the translators.
|
|
325
298
|
* @param {string} domain Text domain. Unique identifier for retrieving translated strings.
|
|
326
299
|
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
/** @type {*} */
|
|
333
|
-
hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
|
|
334
|
-
return (
|
|
335
|
-
/** @type {string} */
|
|
336
|
-
|
|
337
|
-
/** @type {*} */
|
|
338
|
-
hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain)
|
|
300
|
+
translation = /** @type {string} */
|
|
301
|
+
/** @type {*} */hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
|
|
302
|
+
return (/** @type {string} */
|
|
303
|
+
/** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain)
|
|
339
304
|
);
|
|
340
305
|
};
|
|
341
|
-
/** @type {_n} */
|
|
342
|
-
|
|
343
306
|
|
|
307
|
+
/** @type {_n} */
|
|
344
308
|
const _n = (single, plural, number, domain) => {
|
|
345
309
|
let translation = dcnpgettext(domain, undefined, single, plural, number);
|
|
346
|
-
|
|
347
310
|
if (!hooks) {
|
|
348
311
|
return translation;
|
|
349
312
|
}
|
|
313
|
+
|
|
350
314
|
/**
|
|
351
315
|
* Filters the singular or plural form of a string.
|
|
352
316
|
*
|
|
@@ -356,29 +320,20 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
356
320
|
* @param {string} number The number to compare against to use either the singular or plural form.
|
|
357
321
|
* @param {string} domain Text domain. Unique identifier for retrieving translated strings.
|
|
358
322
|
*/
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
/** @type {*} */
|
|
365
|
-
hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
|
|
366
|
-
return (
|
|
367
|
-
/** @type {string} */
|
|
368
|
-
|
|
369
|
-
/** @type {*} */
|
|
370
|
-
hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain)
|
|
323
|
+
translation = /** @type {string} */
|
|
324
|
+
/** @type {*} */hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
|
|
325
|
+
return (/** @type {string} */
|
|
326
|
+
/** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain)
|
|
371
327
|
);
|
|
372
328
|
};
|
|
373
|
-
/** @type {_nx} */
|
|
374
|
-
|
|
375
329
|
|
|
330
|
+
/** @type {_nx} */
|
|
376
331
|
const _nx = (single, plural, number, context, domain) => {
|
|
377
332
|
let translation = dcnpgettext(domain, context, single, plural, number);
|
|
378
|
-
|
|
379
333
|
if (!hooks) {
|
|
380
334
|
return translation;
|
|
381
335
|
}
|
|
336
|
+
|
|
382
337
|
/**
|
|
383
338
|
* Filters the singular or plural form of a string with gettext context.
|
|
384
339
|
*
|
|
@@ -389,33 +344,22 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
389
344
|
* @param {string} context Context information for the translators.
|
|
390
345
|
* @param {string} domain Text domain. Unique identifier for retrieving translated strings.
|
|
391
346
|
*/
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
/** @type {*} */
|
|
398
|
-
hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
|
|
399
|
-
return (
|
|
400
|
-
/** @type {string} */
|
|
401
|
-
|
|
402
|
-
/** @type {*} */
|
|
403
|
-
hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain)
|
|
347
|
+
translation = /** @type {string} */
|
|
348
|
+
/** @type {*} */hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
|
|
349
|
+
return (/** @type {string} */
|
|
350
|
+
/** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain)
|
|
404
351
|
);
|
|
405
352
|
};
|
|
406
|
-
/** @type {IsRtl} */
|
|
407
|
-
|
|
408
353
|
|
|
354
|
+
/** @type {IsRtl} */
|
|
409
355
|
const isRTL = () => {
|
|
410
356
|
return 'rtl' === _x('ltr', 'text direction');
|
|
411
357
|
};
|
|
412
|
-
/** @type {HasTranslation} */
|
|
413
|
-
|
|
414
358
|
|
|
359
|
+
/** @type {HasTranslation} */
|
|
415
360
|
const hasTranslation = (single, context, domain) => {
|
|
416
361
|
const key = context ? context + '\u0004' + single : single;
|
|
417
362
|
let result = !!tannin.data?.[domain !== null && domain !== void 0 ? domain : 'default']?.[key];
|
|
418
|
-
|
|
419
363
|
if (hooks) {
|
|
420
364
|
/**
|
|
421
365
|
* Filters the presence of a translation in the locale data.
|
|
@@ -425,25 +369,16 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
425
369
|
* @param {string} context Context information for the translators.
|
|
426
370
|
* @param {string} domain Text domain. Unique identifier for retrieving translated strings.
|
|
427
371
|
*/
|
|
428
|
-
result =
|
|
429
|
-
/** @type {
|
|
430
|
-
|
|
431
|
-
/** @type {*} */
|
|
432
|
-
hooks.applyFilters('i18n.has_translation', result, single, context, domain);
|
|
433
|
-
result =
|
|
434
|
-
/** @type { boolean } */
|
|
435
|
-
|
|
436
|
-
/** @type {*} */
|
|
437
|
-
hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
|
|
372
|
+
result = /** @type { boolean } */
|
|
373
|
+
/** @type {*} */hooks.applyFilters('i18n.has_translation', result, single, context, domain);
|
|
374
|
+
result = /** @type { boolean } */
|
|
375
|
+
/** @type {*} */hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
|
|
438
376
|
}
|
|
439
|
-
|
|
440
377
|
return result;
|
|
441
378
|
};
|
|
442
|
-
|
|
443
379
|
if (initialData) {
|
|
444
380
|
setLocaleData(initialData, initialDomain);
|
|
445
381
|
}
|
|
446
|
-
|
|
447
382
|
if (hooks) {
|
|
448
383
|
/**
|
|
449
384
|
* @param {string} hookName
|
|
@@ -453,11 +388,9 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
453
388
|
notifyListeners();
|
|
454
389
|
}
|
|
455
390
|
};
|
|
456
|
-
|
|
457
391
|
hooks.addAction('hookAdded', 'core/i18n', onHookAddedOrRemoved);
|
|
458
392
|
hooks.addAction('hookRemoved', 'core/i18n', onHookAddedOrRemoved);
|
|
459
393
|
}
|
|
460
|
-
|
|
461
394
|
return {
|
|
462
395
|
getLocaleData,
|
|
463
396
|
setLocaleData,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/i18n/src/create-i18n.js"],"names":["Tannin","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","listeners","Set","notifyListeners","forEach","listener","subscribe","callback","add","delete","getLocaleData","domain","data","doSetLocaleData","pluralForms","setLocaleData","addLocaleData","resetLocaleData","dcnpgettext","context","single","plural","number","undefined","getFilterDomain","__","text","translation","applyFilters","_x","_n","_nx","isRTL","hasTranslation","key","result","onHookAddedOrRemoved","hookName","test","addAction"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,QAAnB;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAG;AAC3B,MAAI;AACH;AACAC,IAAAA,YAAY,CAAEC,CAAF,EAAM;AACjB,aAAOA,CAAC,KAAK,CAAN,GAAU,CAAV,GAAc,CAArB;AACA;;AAJE;AADuB,CAA5B;AASA;AACA;AACA;AACA;;AACA,MAAMC,gBAAgB,GAAG,yCAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;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;AAClBkB,IAAAA,aAAa,CAAElB,WAAF,EAAeC,aAAf,CAAb;AACA;;AAED,MAAKC,KAAL,EAAa;AACZ;AACF;AACA;AACE,UAAMqC,oBAAoB,GAAKC,QAAF,IAAgB;AAC5C,UAAK1C,gBAAgB,CAAC2C,IAAjB,CAAuBD,QAAvB,CAAL,EAAyC;AACxClC,QAAAA,eAAe;AACf;AACD,KAJD;;AAMAJ,IAAAA,KAAK,CAACwC,SAAN,CAAiB,WAAjB,EAA8B,WAA9B,EAA2CH,oBAA3C;AACArC,IAAAA,KAAK,CAACwC,SAAN,CAAiB,aAAjB,EAAgC,WAAhC,EAA6CH,oBAA7C;AACA;;AAED,SAAO;AACN1B,IAAAA,aADM;AAENK,IAAAA,aAFM;AAGNC,IAAAA,aAHM;AAINC,IAAAA,eAJM;AAKNX,IAAAA,SALM;AAMNmB,IAAAA,EANM;AAONI,IAAAA,EAPM;AAQNC,IAAAA,EARM;AASNC,IAAAA,GATM;AAUNC,IAAAA,KAVM;AAWNC,IAAAA;AAXM,GAAP;AAaA,CA9VM","sourcesContent":["/**\n * External dependencies\n */\nimport Tannin from 'tannin';\n\n/**\n * @typedef {Record<string,any>} LocaleData\n */\n\n/**\n * Default locale data to use for Tannin domain when not otherwise provided.\n * Assumes an English plural forms expression.\n *\n * @type {LocaleData}\n */\nconst DEFAULT_LOCALE_DATA = {\n\t'': {\n\t\t/** @param {number} n */\n\t\tplural_forms( n ) {\n\t\t\treturn n === 1 ? 0 : 1;\n\t\t},\n\t},\n};\n\n/*\n * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,\n * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.\n */\nconst I18N_HOOK_REGEXP = /^i18n\\.(n?gettext|has_translation)(_|$)/;\n\n/**\n * @typedef {(domain?: string) => LocaleData} GetLocaleData\n *\n * Returns locale data by domain in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData\n *\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/** @typedef {() => void} SubscribeCallback */\n/** @typedef {() => void} UnsubscribeCallback */\n/**\n * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe\n *\n * Subscribes to changes of locale data\n */\n/**\n * @typedef {(domain?: string) => string} GetFilterDomain\n * Retrieve the domain to use when calling domain-specific filters.\n */\n/**\n * @typedef {(text: string, domain?: string) => string} __\n *\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n */\n/**\n * @typedef {(text: string, context: string, domain?: string) => string} _x\n *\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n */\n/**\n * @typedef {() => boolean} IsRtl\n *\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n */\n/**\n * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation\n *\n * Check if there is a translation for a given string in singular form.\n */\n/** @typedef {import('@wordpress/hooks').Hooks} Hooks */\n\n/**\n * An i18n instance\n *\n * @typedef I18n\n * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.\n * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n * @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.\n * @property {__} __ Retrieve the translation of text.\n * @property {_x} _x Retrieve translated string with gettext context.\n * @property {_n} _n Translates and retrieves the singular or plural form based on the supplied\n * number.\n * @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n * @property {IsRtl} isRTL Check if current locale is RTL.\n * @property {HasTranslation} hasTranslation Check if there is a translation for a given string.\n */\n\n/**\n * Create an i18n instance\n *\n * @param {LocaleData} [initialData] Locale data configuration.\n * @param {string} [initialDomain] Domain for which configuration applies.\n * @param {Hooks} [hooks] Hooks implementation.\n *\n * @return {I18n} I18n instance.\n */\nexport const createI18n = ( initialData, initialDomain, hooks ) => {\n\t/**\n\t * The underlying instance of Tannin to which exported functions interface.\n\t *\n\t * @type {Tannin}\n\t */\n\tconst tannin = new Tannin( {} );\n\n\tconst listeners = new Set();\n\n\tconst notifyListeners = () => {\n\t\tlisteners.forEach( ( listener ) => listener() );\n\t};\n\n\t/**\n\t * Subscribe to changes of locale data.\n\t *\n\t * @param {SubscribeCallback} callback Subscription callback.\n\t * @return {UnsubscribeCallback} Unsubscribe callback.\n\t */\n\tconst subscribe = ( callback ) => {\n\t\tlisteners.add( callback );\n\t\treturn () => listeners.delete( callback );\n\t};\n\n\t/** @type {GetLocaleData} */\n\tconst getLocaleData = ( domain = 'default' ) => tannin.data[ domain ];\n\n\t/**\n\t * @param {LocaleData} [data]\n\t * @param {string} [domain]\n\t */\n\tconst doSetLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t};\n\n\t\t// Populate default domain configuration (supported locale date which omits\n\t\t// a plural forms expression).\n\t\ttannin.data[ domain ][ '' ] = {\n\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\t};\n\n\t/** @type {SetLocaleData} */\n\tconst setLocaleData = ( data, domain ) => {\n\t\tdoSetLocaleData( data, domain );\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {AddLocaleData} */\n\tconst addLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t\t// Populate default domain configuration (supported locale date which omits\n\t\t\t// a plural forms expression).\n\t\t\t'': {\n\t\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t\t\t...data?.[ '' ],\n\t\t\t},\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {ResetLocaleData} */\n\tconst resetLocaleData = ( data, domain ) => {\n\t\t// Reset all current Tannin locale data.\n\t\ttannin.data = {};\n\n\t\t// Reset cached plural forms functions cache.\n\t\ttannin.pluralForms = {};\n\n\t\tsetLocaleData( data, domain );\n\t};\n\n\t/**\n\t * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not\n\t * otherwise previously assigned.\n\t *\n\t * @param {string|undefined} domain Domain to retrieve the translated text.\n\t * @param {string|undefined} context Context information for the translators.\n\t * @param {string} single Text to translate if non-plural. Used as\n\t * fallback return value on a caught error.\n\t * @param {string} [plural] The text to be used if the number is\n\t * plural.\n\t * @param {number} [number] The number to compare against to use\n\t * either the singular or plural form.\n\t *\n\t * @return {string} The translated string.\n\t */\n\tconst dcnpgettext = (\n\t\tdomain = 'default',\n\t\tcontext,\n\t\tsingle,\n\t\tplural,\n\t\tnumber\n\t) => {\n\t\tif ( ! tannin.data[ domain ] ) {\n\t\t\t// Use `doSetLocaleData` to set silently, without notifying listeners.\n\t\t\tdoSetLocaleData( undefined, domain );\n\t\t}\n\n\t\treturn tannin.dcnpgettext( domain, context, single, plural, number );\n\t};\n\n\t/** @type {GetFilterDomain} */\n\tconst getFilterDomain = ( domain = 'default' ) => domain;\n\n\t/** @type {__} */\n\tconst __ = ( text, domain ) => {\n\t\tlet translation = dcnpgettext( domain, undefined, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_x} */\n\tconst _x = ( text, context, domain ) => {\n\t\tlet translation = dcnpgettext( domain, context, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation based on context information.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_n} */\n\tconst _n = ( single, plural, number, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tundefined,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_nx} */\n\tconst _nx = ( single, plural, number, context, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tcontext,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string with gettext context.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {IsRtl} */\n\tconst isRTL = () => {\n\t\treturn 'rtl' === _x( 'ltr', 'text direction' );\n\t};\n\n\t/** @type {HasTranslation} */\n\tconst hasTranslation = ( single, context, domain ) => {\n\t\tconst key = context ? context + '\\u0004' + single : single;\n\t\tlet result = !! tannin.data?.[ domain ?? 'default' ]?.[ key ];\n\t\tif ( hooks ) {\n\t\t\t/**\n\t\t\t * Filters the presence of a translation in the locale data.\n\t\t\t *\n\t\t\t * @param {boolean} hasTranslation Whether the translation is present or not..\n\t\t\t * @param {string} single The singular form of the translated text (used as key in locale data)\n\t\t\t * @param {string} context Context information for the translators.\n\t\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t\t */\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation',\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation_' + getFilterDomain( domain ),\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t};\n\n\tif ( initialData ) {\n\t\tsetLocaleData( initialData, initialDomain );\n\t}\n\n\tif ( hooks ) {\n\t\t/**\n\t\t * @param {string} hookName\n\t\t */\n\t\tconst onHookAddedOrRemoved = ( hookName ) => {\n\t\t\tif ( I18N_HOOK_REGEXP.test( hookName ) ) {\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t};\n\n\t\thooks.addAction( 'hookAdded', 'core/i18n', onHookAddedOrRemoved );\n\t\thooks.addAction( 'hookRemoved', 'core/i18n', onHookAddedOrRemoved );\n\t}\n\n\treturn {\n\t\tgetLocaleData,\n\t\tsetLocaleData,\n\t\taddLocaleData,\n\t\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"]}
|
|
1
|
+
{"version":3,"names":["Tannin","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","listeners","Set","notifyListeners","forEach","listener","subscribe","callback","add","delete","getLocaleData","domain","data","doSetLocaleData","pluralForms","setLocaleData","addLocaleData","resetLocaleData","dcnpgettext","context","single","plural","number","undefined","getFilterDomain","__","text","translation","applyFilters","_x","_n","_nx","isRTL","hasTranslation","key","result","onHookAddedOrRemoved","hookName","test","addAction"],"sources":["@wordpress/i18n/src/create-i18n.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport Tannin from 'tannin';\n\n/**\n * @typedef {Record<string,any>} LocaleData\n */\n\n/**\n * Default locale data to use for Tannin domain when not otherwise provided.\n * Assumes an English plural forms expression.\n *\n * @type {LocaleData}\n */\nconst DEFAULT_LOCALE_DATA = {\n\t'': {\n\t\t/** @param {number} n */\n\t\tplural_forms( n ) {\n\t\t\treturn n === 1 ? 0 : 1;\n\t\t},\n\t},\n};\n\n/*\n * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,\n * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.\n */\nconst I18N_HOOK_REGEXP = /^i18n\\.(n?gettext|has_translation)(_|$)/;\n\n/**\n * @typedef {(domain?: string) => LocaleData} GetLocaleData\n *\n * Returns locale data by domain in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData\n *\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/** @typedef {() => void} SubscribeCallback */\n/** @typedef {() => void} UnsubscribeCallback */\n/**\n * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe\n *\n * Subscribes to changes of locale data\n */\n/**\n * @typedef {(domain?: string) => string} GetFilterDomain\n * Retrieve the domain to use when calling domain-specific filters.\n */\n/**\n * @typedef {(text: string, domain?: string) => string} __\n *\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n */\n/**\n * @typedef {(text: string, context: string, domain?: string) => string} _x\n *\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n */\n/**\n * @typedef {() => boolean} IsRtl\n *\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n */\n/**\n * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation\n *\n * Check if there is a translation for a given string in singular form.\n */\n/** @typedef {import('@wordpress/hooks').Hooks} Hooks */\n\n/**\n * An i18n instance\n *\n * @typedef I18n\n * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.\n * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n * @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.\n * @property {__} __ Retrieve the translation of text.\n * @property {_x} _x Retrieve translated string with gettext context.\n * @property {_n} _n Translates and retrieves the singular or plural form based on the supplied\n * number.\n * @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n * @property {IsRtl} isRTL Check if current locale is RTL.\n * @property {HasTranslation} hasTranslation Check if there is a translation for a given string.\n */\n\n/**\n * Create an i18n instance\n *\n * @param {LocaleData} [initialData] Locale data configuration.\n * @param {string} [initialDomain] Domain for which configuration applies.\n * @param {Hooks} [hooks] Hooks implementation.\n *\n * @return {I18n} I18n instance.\n */\nexport const createI18n = ( initialData, initialDomain, hooks ) => {\n\t/**\n\t * The underlying instance of Tannin to which exported functions interface.\n\t *\n\t * @type {Tannin}\n\t */\n\tconst tannin = new Tannin( {} );\n\n\tconst listeners = new Set();\n\n\tconst notifyListeners = () => {\n\t\tlisteners.forEach( ( listener ) => listener() );\n\t};\n\n\t/**\n\t * Subscribe to changes of locale data.\n\t *\n\t * @param {SubscribeCallback} callback Subscription callback.\n\t * @return {UnsubscribeCallback} Unsubscribe callback.\n\t */\n\tconst subscribe = ( callback ) => {\n\t\tlisteners.add( callback );\n\t\treturn () => listeners.delete( callback );\n\t};\n\n\t/** @type {GetLocaleData} */\n\tconst getLocaleData = ( domain = 'default' ) => tannin.data[ domain ];\n\n\t/**\n\t * @param {LocaleData} [data]\n\t * @param {string} [domain]\n\t */\n\tconst doSetLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t};\n\n\t\t// Populate default domain configuration (supported locale date which omits\n\t\t// a plural forms expression).\n\t\ttannin.data[ domain ][ '' ] = {\n\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\t};\n\n\t/** @type {SetLocaleData} */\n\tconst setLocaleData = ( data, domain ) => {\n\t\tdoSetLocaleData( data, domain );\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {AddLocaleData} */\n\tconst addLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t\t// Populate default domain configuration (supported locale date which omits\n\t\t\t// a plural forms expression).\n\t\t\t'': {\n\t\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t\t\t...data?.[ '' ],\n\t\t\t},\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {ResetLocaleData} */\n\tconst resetLocaleData = ( data, domain ) => {\n\t\t// Reset all current Tannin locale data.\n\t\ttannin.data = {};\n\n\t\t// Reset cached plural forms functions cache.\n\t\ttannin.pluralForms = {};\n\n\t\tsetLocaleData( data, domain );\n\t};\n\n\t/**\n\t * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not\n\t * otherwise previously assigned.\n\t *\n\t * @param {string|undefined} domain Domain to retrieve the translated text.\n\t * @param {string|undefined} context Context information for the translators.\n\t * @param {string} single Text to translate if non-plural. Used as\n\t * fallback return value on a caught error.\n\t * @param {string} [plural] The text to be used if the number is\n\t * plural.\n\t * @param {number} [number] The number to compare against to use\n\t * either the singular or plural form.\n\t *\n\t * @return {string} The translated string.\n\t */\n\tconst dcnpgettext = (\n\t\tdomain = 'default',\n\t\tcontext,\n\t\tsingle,\n\t\tplural,\n\t\tnumber\n\t) => {\n\t\tif ( ! tannin.data[ domain ] ) {\n\t\t\t// Use `doSetLocaleData` to set silently, without notifying listeners.\n\t\t\tdoSetLocaleData( undefined, domain );\n\t\t}\n\n\t\treturn tannin.dcnpgettext( domain, context, single, plural, number );\n\t};\n\n\t/** @type {GetFilterDomain} */\n\tconst getFilterDomain = ( domain = 'default' ) => domain;\n\n\t/** @type {__} */\n\tconst __ = ( text, domain ) => {\n\t\tlet translation = dcnpgettext( domain, undefined, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_x} */\n\tconst _x = ( text, context, domain ) => {\n\t\tlet translation = dcnpgettext( domain, context, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation based on context information.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_n} */\n\tconst _n = ( single, plural, number, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tundefined,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_nx} */\n\tconst _nx = ( single, plural, number, context, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tcontext,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string with gettext context.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {IsRtl} */\n\tconst isRTL = () => {\n\t\treturn 'rtl' === _x( 'ltr', 'text direction' );\n\t};\n\n\t/** @type {HasTranslation} */\n\tconst hasTranslation = ( single, context, domain ) => {\n\t\tconst key = context ? context + '\\u0004' + single : single;\n\t\tlet result = !! tannin.data?.[ domain ?? 'default' ]?.[ key ];\n\t\tif ( hooks ) {\n\t\t\t/**\n\t\t\t * Filters the presence of a translation in the locale data.\n\t\t\t *\n\t\t\t * @param {boolean} hasTranslation Whether the translation is present or not..\n\t\t\t * @param {string} single The singular form of the translated text (used as key in locale data)\n\t\t\t * @param {string} context Context information for the translators.\n\t\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t\t */\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation',\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation_' + getFilterDomain( domain ),\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t};\n\n\tif ( initialData ) {\n\t\tsetLocaleData( initialData, initialDomain );\n\t}\n\n\tif ( hooks ) {\n\t\t/**\n\t\t * @param {string} hookName\n\t\t */\n\t\tconst onHookAddedOrRemoved = ( hookName ) => {\n\t\t\tif ( I18N_HOOK_REGEXP.test( hookName ) ) {\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t};\n\n\t\thooks.addAction( 'hookAdded', 'core/i18n', onHookAddedOrRemoved );\n\t\thooks.addAction( 'hookRemoved', 'core/i18n', onHookAddedOrRemoved );\n\t}\n\n\treturn {\n\t\tgetLocaleData,\n\t\tsetLocaleData,\n\t\taddLocaleData,\n\t\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAM,MAAM,QAAQ;;AAE3B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG;EAC3B,EAAE,EAAE;IACH;IACAC,YAAYA,CAAEC,CAAC,EAAG;MACjB,OAAOA,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;IACvB;EACD;AACD,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG,yCAAyC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAGA,CAAEC,WAAW,EAAEC,aAAa,EAAEC,KAAK,KAAM;EAClE;AACD;AACA;AACA;AACA;EACC,MAAMC,MAAM,GAAG,IAAIT,MAAM,CAAE,CAAC,CAAE,CAAC;EAE/B,MAAMU,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAE3B,MAAMC,eAAe,GAAGA,CAAA,KAAM;IAC7BF,SAAS,CAACG,OAAO,CAAIC,QAAQ,IAAMA,QAAQ,CAAC,CAAE,CAAC;EAChD,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;EACC,MAAMC,SAAS,GAAKC,QAAQ,IAAM;IACjCN,SAAS,CAACO,GAAG,CAAED,QAAS,CAAC;IACzB,OAAO,MAAMN,SAAS,CAACQ,MAAM,CAAEF,QAAS,CAAC;EAC1C,CAAC;;EAED;EACA,MAAMG,aAAa,GAAGA,CAAEC,MAAM,GAAG,SAAS,KAAMX,MAAM,CAACY,IAAI,CAAED,MAAM,CAAE;;EAErE;AACD;AACA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