@wordpress/i18n 5.26.0 → 6.0.1-next.46f643fa0.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 +6 -0
- package/README.md +28 -27
- package/build/create-i18n.js +56 -201
- package/build/create-i18n.js.map +1 -1
- package/build/default-i18n.js +41 -34
- package/build/default-i18n.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/sprintf.js +10 -22
- package/build/sprintf.js.map +1 -1
- package/build/types.js +6 -0
- package/build/types.js.map +1 -0
- package/build-module/create-i18n.js +56 -201
- package/build-module/create-i18n.js.map +1 -1
- package/build-module/default-i18n.js +41 -35
- package/build-module/default-i18n.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/sprintf.js +10 -22
- package/build-module/sprintf.js.map +1 -1
- package/build-module/types.js +2 -0
- package/build-module/types.js.map +1 -0
- package/build-types/create-i18n.d.ts +11 -115
- package/build-types/create-i18n.d.ts.map +1 -1
- package/build-types/default-i18n.d.ts +55 -47
- package/build-types/default-i18n.d.ts.map +1 -1
- package/build-types/index.d.ts +4 -3
- package/build-types/index.d.ts.map +1 -1
- package/build-types/sprintf.d.ts +4 -10
- package/build-types/sprintf.d.ts.map +1 -1
- package/build-types/types.d.ts +114 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/create-i18n.ts +405 -0
- package/src/{default-i18n.js → default-i18n.ts} +47 -35
- package/src/index.ts +16 -0
- package/src/sprintf.ts +37 -0
- package/src/test/{create-i18n.js → create-i18n.ts} +63 -30
- package/src/test/{sprintf.js → sprintf.ts} +5 -10
- package/src/test/{subscribe-i18n.js → subscribe-i18n.ts} +3 -3
- package/src/types.ts +167 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/create-i18n.js +0 -506
- package/src/sprintf.js +0 -36
- /package/src/test/{default-i18n.js → default-i18n.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 6.0.0 (2025-07-23)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- Improve type declarations for `sprintf` by replacing the `sprintf-js` dependency with `@tannin/sprintf` ([#70434](https://github.com/WordPress/gutenberg/pull/70434))
|
|
10
|
+
|
|
5
11
|
## 5.26.0 (2025-06-25)
|
|
6
12
|
|
|
7
13
|
## 5.25.0 (2025-06-04)
|
package/README.md
CHANGED
|
@@ -33,13 +33,13 @@ Create an i18n instance
|
|
|
33
33
|
|
|
34
34
|
_Parameters_
|
|
35
35
|
|
|
36
|
-
- _initialData_ `[LocaleData]`: Locale data configuration.
|
|
37
|
-
- _initialDomain_ `[
|
|
36
|
+
- _initialData_ `[LocaleData< TextDomain >]`: Locale data configuration.
|
|
37
|
+
- _initialDomain_ `[TextDomain]`: Domain for which configuration applies.
|
|
38
38
|
- _hooks_ `[Hooks]`: Hooks implementation.
|
|
39
39
|
|
|
40
40
|
_Returns_
|
|
41
41
|
|
|
42
|
-
- `I18n
|
|
42
|
+
- `I18n< TextDomain >`: I18n instance.
|
|
43
43
|
|
|
44
44
|
### defaultI18n
|
|
45
45
|
|
|
@@ -55,7 +55,7 @@ _Related_
|
|
|
55
55
|
|
|
56
56
|
_Parameters_
|
|
57
57
|
|
|
58
|
-
- _domain_ `[string]`: Domain for which to get the data.
|
|
58
|
+
- _domain_ `[ string | undefined ]`: Domain for which to get the data.
|
|
59
59
|
|
|
60
60
|
_Returns_
|
|
61
61
|
|
|
@@ -68,8 +68,8 @@ Check if there is a translation for a given string (in singular form).
|
|
|
68
68
|
_Parameters_
|
|
69
69
|
|
|
70
70
|
- _single_ `string`: Singular form of the string to look up.
|
|
71
|
-
- _context_ `
|
|
72
|
-
- _domain_ `
|
|
71
|
+
- _context_ `string`: Context information for the translators.
|
|
72
|
+
- _domain_ `string`: Domain to retrieve the translated text.
|
|
73
73
|
|
|
74
74
|
_Returns_
|
|
75
75
|
|
|
@@ -96,7 +96,7 @@ _Related_
|
|
|
96
96
|
_Parameters_
|
|
97
97
|
|
|
98
98
|
- _data_ `[LocaleData]`: Locale data configuration.
|
|
99
|
-
- _domain_ `[string]`: Domain for which configuration applies.
|
|
99
|
+
- _domain_ `[string | undefined]`: Domain for which configuration applies.
|
|
100
100
|
|
|
101
101
|
### setLocaleData
|
|
102
102
|
|
|
@@ -108,21 +108,21 @@ _Related_
|
|
|
108
108
|
|
|
109
109
|
_Parameters_
|
|
110
110
|
|
|
111
|
-
- _data_ `[LocaleData]`: Locale data configuration.
|
|
112
|
-
- _domain_ `[string]`: Domain for which configuration applies.
|
|
111
|
+
- _data_ `[LocaleData ]`: Locale data configuration.
|
|
112
|
+
- _domain_ `[string | undefined]`: Domain for which configuration applies.
|
|
113
113
|
|
|
114
114
|
### sprintf
|
|
115
115
|
|
|
116
|
-
Returns a formatted string.
|
|
116
|
+
Returns a formatted string.
|
|
117
117
|
|
|
118
118
|
_Related_
|
|
119
119
|
|
|
120
|
-
- <https://www.npmjs.com/package/sprintf
|
|
120
|
+
- <https://www.npmjs.com/package/@tannin/sprintf>
|
|
121
121
|
|
|
122
122
|
_Parameters_
|
|
123
123
|
|
|
124
|
-
- _format_ `
|
|
125
|
-
- _args_
|
|
124
|
+
- _format_ `T | TranslatableText< T >`: The format of the string to generate.
|
|
125
|
+
- _args_ `DistributeSprintfArgs< T >`: Arguments to apply to the format.
|
|
126
126
|
|
|
127
127
|
_Returns_
|
|
128
128
|
|
|
@@ -150,14 +150,14 @@ _Related_
|
|
|
150
150
|
|
|
151
151
|
_Parameters_
|
|
152
152
|
|
|
153
|
-
- _single_ `
|
|
154
|
-
- _plural_ `
|
|
153
|
+
- _single_ `Single`: The text to be used if the number is singular.
|
|
154
|
+
- _plural_ `Plural`: The text to be used if the number is plural.
|
|
155
155
|
- _number_ `number`: The number to compare against to use either the singular or plural form.
|
|
156
|
-
- _domain_ `
|
|
156
|
+
- _domain_ `string | undefined`: Domain to retrieve the translated text.
|
|
157
157
|
|
|
158
158
|
_Returns_
|
|
159
159
|
|
|
160
|
-
- `
|
|
160
|
+
- `TranslatableText<Single | Plural>`: The translated singular or plural form.
|
|
161
161
|
|
|
162
162
|
### \_nx
|
|
163
163
|
|
|
@@ -169,15 +169,16 @@ _Related_
|
|
|
169
169
|
|
|
170
170
|
_Parameters_
|
|
171
171
|
|
|
172
|
-
- _single_ `
|
|
173
|
-
-
|
|
172
|
+
- _single_ `Single`: The text to be used if the number is singular.
|
|
173
|
+
- _single_ `Single`: The text to be used if the number is singular.
|
|
174
|
+
- _plural_ `Plural`: The text to be used if the number is plural.
|
|
174
175
|
- _number_ `number`: The number to compare against to use either the singular or plural form.
|
|
175
176
|
- _context_ `string`: Context information for the translators.
|
|
176
|
-
- _domain_ `[string]`: Domain to retrieve the translated text.
|
|
177
|
+
- _domain_ `[string | undefined]`: Domain to retrieve the translated text.
|
|
177
178
|
|
|
178
179
|
_Returns_
|
|
179
180
|
|
|
180
|
-
- `
|
|
181
|
+
- `TranslatableText<Single | Plural>`: The translated singular or plural form.
|
|
181
182
|
|
|
182
183
|
### \_x
|
|
183
184
|
|
|
@@ -189,13 +190,13 @@ _Related_
|
|
|
189
190
|
|
|
190
191
|
_Parameters_
|
|
191
192
|
|
|
192
|
-
- _text_ `
|
|
193
|
+
- _text_ `Text`: Text to translate.
|
|
193
194
|
- _context_ `string`: Context information for the translators.
|
|
194
|
-
- _domain_ `
|
|
195
|
+
- _domain_ `string | undefined`: Domain to retrieve the translated text.
|
|
195
196
|
|
|
196
197
|
_Returns_
|
|
197
198
|
|
|
198
|
-
- `
|
|
199
|
+
- `TranslatableText<Text>`: Translated context string without pipe.
|
|
199
200
|
|
|
200
201
|
### \_\_
|
|
201
202
|
|
|
@@ -207,12 +208,12 @@ _Related_
|
|
|
207
208
|
|
|
208
209
|
_Parameters_
|
|
209
210
|
|
|
210
|
-
- _text_ `
|
|
211
|
-
- _domain_ `
|
|
211
|
+
- _text_ `Text`: Text to translate.
|
|
212
|
+
- _domain_ `string | undefined`: Domain to retrieve the translated text.
|
|
212
213
|
|
|
213
214
|
_Returns_
|
|
214
215
|
|
|
215
|
-
- `
|
|
216
|
+
- `TranslatableText<Text>`: Translated text.
|
|
216
217
|
|
|
217
218
|
<!-- END TOKEN(Autogenerated API docs) -->
|
|
218
219
|
|
package/build/create-i18n.js
CHANGED
|
@@ -11,18 +11,19 @@ var _tannin = _interopRequireDefault(require("tannin"));
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
15
19
|
*/
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* Default locale data to use for Tannin domain when not otherwise provided.
|
|
19
23
|
* Assumes an English plural forms expression.
|
|
20
|
-
*
|
|
21
|
-
* @type {LocaleData}
|
|
22
24
|
*/
|
|
23
25
|
const DEFAULT_LOCALE_DATA = {
|
|
24
26
|
'': {
|
|
25
|
-
/** @param {number} n */
|
|
26
27
|
plural_forms(n) {
|
|
27
28
|
return n === 1 ? 0 : 1;
|
|
28
29
|
}
|
|
@@ -35,136 +36,18 @@ const DEFAULT_LOCALE_DATA = {
|
|
|
35
36
|
*/
|
|
36
37
|
const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
37
38
|
|
|
38
|
-
/**
|
|
39
|
-
* @typedef {(domain?: string) => LocaleData} GetLocaleData
|
|
40
|
-
*
|
|
41
|
-
* Returns locale data by domain in a
|
|
42
|
-
* Jed-formatted JSON object shape.
|
|
43
|
-
*
|
|
44
|
-
* @see http://messageformat.github.io/Jed/
|
|
45
|
-
*/
|
|
46
|
-
/**
|
|
47
|
-
* @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
|
|
48
|
-
*
|
|
49
|
-
* Merges locale data into the Tannin instance by domain. Note that this
|
|
50
|
-
* function will overwrite the domain configuration. Accepts data in a
|
|
51
|
-
* Jed-formatted JSON object shape.
|
|
52
|
-
*
|
|
53
|
-
* @see http://messageformat.github.io/Jed/
|
|
54
|
-
*/
|
|
55
|
-
/**
|
|
56
|
-
* @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
|
|
57
|
-
*
|
|
58
|
-
* Merges locale data into the Tannin instance by domain. Note that this
|
|
59
|
-
* function will also merge the domain configuration. Accepts data in a
|
|
60
|
-
* Jed-formatted JSON object shape.
|
|
61
|
-
*
|
|
62
|
-
* @see http://messageformat.github.io/Jed/
|
|
63
|
-
*/
|
|
64
|
-
/**
|
|
65
|
-
* @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData
|
|
66
|
-
*
|
|
67
|
-
* Resets all current Tannin instance locale data and sets the specified
|
|
68
|
-
* locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
|
|
69
|
-
*
|
|
70
|
-
* @see http://messageformat.github.io/Jed/
|
|
71
|
-
*/
|
|
72
|
-
/** @typedef {() => void} SubscribeCallback */
|
|
73
|
-
/** @typedef {() => void} UnsubscribeCallback */
|
|
74
|
-
/**
|
|
75
|
-
* @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe
|
|
76
|
-
*
|
|
77
|
-
* Subscribes to changes of locale data
|
|
78
|
-
*/
|
|
79
|
-
/**
|
|
80
|
-
* @typedef {(domain?: string) => string} GetFilterDomain
|
|
81
|
-
* Retrieve the domain to use when calling domain-specific filters.
|
|
82
|
-
*/
|
|
83
|
-
/**
|
|
84
|
-
* @typedef {(text: string, domain?: string) => string} __
|
|
85
|
-
*
|
|
86
|
-
* Retrieve the translation of text.
|
|
87
|
-
*
|
|
88
|
-
* @see https://developer.wordpress.org/reference/functions/__/
|
|
89
|
-
*/
|
|
90
|
-
/**
|
|
91
|
-
* @typedef {(text: string, context: string, domain?: string) => string} _x
|
|
92
|
-
*
|
|
93
|
-
* Retrieve translated string with gettext context.
|
|
94
|
-
*
|
|
95
|
-
* @see https://developer.wordpress.org/reference/functions/_x/
|
|
96
|
-
*/
|
|
97
|
-
/**
|
|
98
|
-
* @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
|
|
99
|
-
*
|
|
100
|
-
* Translates and retrieves the singular or plural form based on the supplied
|
|
101
|
-
* number.
|
|
102
|
-
*
|
|
103
|
-
* @see https://developer.wordpress.org/reference/functions/_n/
|
|
104
|
-
*/
|
|
105
|
-
/**
|
|
106
|
-
* @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
|
|
107
|
-
*
|
|
108
|
-
* Translates and retrieves the singular or plural form based on the supplied
|
|
109
|
-
* number, with gettext context.
|
|
110
|
-
*
|
|
111
|
-
* @see https://developer.wordpress.org/reference/functions/_nx/
|
|
112
|
-
*/
|
|
113
|
-
/**
|
|
114
|
-
* @typedef {() => boolean} IsRtl
|
|
115
|
-
*
|
|
116
|
-
* Check if current locale is RTL.
|
|
117
|
-
*
|
|
118
|
-
* **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
|
|
119
|
-
* For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
|
|
120
|
-
* language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
|
|
121
|
-
* including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
|
|
122
|
-
*/
|
|
123
|
-
/**
|
|
124
|
-
* @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation
|
|
125
|
-
*
|
|
126
|
-
* Check if there is a translation for a given string in singular form.
|
|
127
|
-
*/
|
|
128
|
-
/** @typedef {import('@wordpress/hooks').Hooks} Hooks */
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* An i18n instance
|
|
132
|
-
*
|
|
133
|
-
* @typedef I18n
|
|
134
|
-
* @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.
|
|
135
|
-
* @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this
|
|
136
|
-
* function will overwrite the domain configuration. Accepts data in a
|
|
137
|
-
* Jed-formatted JSON object shape.
|
|
138
|
-
* @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this
|
|
139
|
-
* function will also merge the domain configuration. Accepts data in a
|
|
140
|
-
* Jed-formatted JSON object shape.
|
|
141
|
-
* @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified
|
|
142
|
-
* locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
|
|
143
|
-
* @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.
|
|
144
|
-
* @property {__} __ Retrieve the translation of text.
|
|
145
|
-
* @property {_x} _x Retrieve translated string with gettext context.
|
|
146
|
-
* @property {_n} _n Translates and retrieves the singular or plural form based on the supplied
|
|
147
|
-
* number.
|
|
148
|
-
* @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied
|
|
149
|
-
* number, with gettext context.
|
|
150
|
-
* @property {IsRtl} isRTL Check if current locale is RTL.
|
|
151
|
-
* @property {HasTranslation} hasTranslation Check if there is a translation for a given string.
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
39
|
/**
|
|
155
40
|
* Create an i18n instance
|
|
156
41
|
*
|
|
157
|
-
* @param
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
42
|
+
* @param [initialData] Locale data configuration.
|
|
43
|
+
* @param [initialDomain] Domain for which configuration applies.
|
|
44
|
+
* @param [hooks] Hooks implementation.
|
|
160
45
|
*
|
|
161
|
-
* @return
|
|
46
|
+
* @return I18n instance.
|
|
162
47
|
*/
|
|
163
48
|
const createI18n = (initialData, initialDomain, hooks) => {
|
|
164
49
|
/**
|
|
165
50
|
* The underlying instance of Tannin to which exported functions interface.
|
|
166
|
-
*
|
|
167
|
-
* @type {Tannin}
|
|
168
51
|
*/
|
|
169
52
|
const tannin = new _tannin.default({});
|
|
170
53
|
const listeners = new Set();
|
|
@@ -175,20 +58,18 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
175
58
|
/**
|
|
176
59
|
* Subscribe to changes of locale data.
|
|
177
60
|
*
|
|
178
|
-
* @param
|
|
179
|
-
* @return
|
|
61
|
+
* @param callback Subscription callback.
|
|
62
|
+
* @return Unsubscribe callback.
|
|
180
63
|
*/
|
|
181
64
|
const subscribe = callback => {
|
|
182
65
|
listeners.add(callback);
|
|
183
66
|
return () => listeners.delete(callback);
|
|
184
67
|
};
|
|
185
|
-
|
|
186
|
-
/** @type {GetLocaleData} */
|
|
187
68
|
const getLocaleData = (domain = 'default') => tannin.data[domain];
|
|
188
69
|
|
|
189
70
|
/**
|
|
190
|
-
* @param
|
|
191
|
-
* @param
|
|
71
|
+
* @param [data]
|
|
72
|
+
* @param [domain]
|
|
192
73
|
*/
|
|
193
74
|
const doSetLocaleData = (data, domain = 'default') => {
|
|
194
75
|
tannin.data[domain] = {
|
|
@@ -206,14 +87,10 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
206
87
|
// Clean up cached plural forms functions cache as it might be updated.
|
|
207
88
|
delete tannin.pluralForms[domain];
|
|
208
89
|
};
|
|
209
|
-
|
|
210
|
-
/** @type {SetLocaleData} */
|
|
211
90
|
const setLocaleData = (data, domain) => {
|
|
212
91
|
doSetLocaleData(data, domain);
|
|
213
92
|
notifyListeners();
|
|
214
93
|
};
|
|
215
|
-
|
|
216
|
-
/** @type {AddLocaleData} */
|
|
217
94
|
const addLocaleData = (data, domain = 'default') => {
|
|
218
95
|
tannin.data[domain] = {
|
|
219
96
|
...tannin.data[domain],
|
|
@@ -231,8 +108,6 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
231
108
|
delete tannin.pluralForms[domain];
|
|
232
109
|
notifyListeners();
|
|
233
110
|
};
|
|
234
|
-
|
|
235
|
-
/** @type {ResetLocaleData} */
|
|
236
111
|
const resetLocaleData = (data, domain) => {
|
|
237
112
|
// Reset all current Tannin locale data.
|
|
238
113
|
tannin.data = {};
|
|
@@ -246,16 +121,16 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
246
121
|
* Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
|
|
247
122
|
* otherwise previously assigned.
|
|
248
123
|
*
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* @param
|
|
252
|
-
*
|
|
253
|
-
* @param
|
|
254
|
-
*
|
|
255
|
-
* @param
|
|
256
|
-
*
|
|
124
|
+
* @param domain Domain to retrieve the translated text.
|
|
125
|
+
* @param context Context information for the translators.
|
|
126
|
+
* @param single Text to translate if non-plural. Used as
|
|
127
|
+
* fallback return value on a caught error.
|
|
128
|
+
* @param [plural] The text to be used if the number is
|
|
129
|
+
* plural.
|
|
130
|
+
* @param [number] The number to compare against to use
|
|
131
|
+
* either the singular or plural form.
|
|
257
132
|
*
|
|
258
|
-
* @return
|
|
133
|
+
* @return The translated string.
|
|
259
134
|
*/
|
|
260
135
|
const dcnpgettext = (domain = 'default', context, single, plural, number) => {
|
|
261
136
|
if (!tannin.data[domain]) {
|
|
@@ -264,11 +139,7 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
264
139
|
}
|
|
265
140
|
return tannin.dcnpgettext(domain, context, single, plural, number);
|
|
266
141
|
};
|
|
267
|
-
|
|
268
|
-
/** @type {GetFilterDomain} */
|
|
269
|
-
const getFilterDomain = (domain = 'default') => domain;
|
|
270
|
-
|
|
271
|
-
/** @type {__} */
|
|
142
|
+
const getFilterDomain = domain => domain || 'default';
|
|
272
143
|
const __ = (text, domain) => {
|
|
273
144
|
let translation = dcnpgettext(domain, undefined, text);
|
|
274
145
|
if (!hooks) {
|
|
@@ -278,16 +149,13 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
278
149
|
/**
|
|
279
150
|
* Filters text with its translation.
|
|
280
151
|
*
|
|
281
|
-
* @param
|
|
282
|
-
* @param
|
|
283
|
-
* @param
|
|
152
|
+
* @param translation Translated text.
|
|
153
|
+
* @param text Text to translate.
|
|
154
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
284
155
|
*/
|
|
285
|
-
translation =
|
|
286
|
-
|
|
287
|
-
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
|
|
156
|
+
translation = hooks.applyFilters('i18n.gettext', translation, text, domain);
|
|
157
|
+
return hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
|
|
288
158
|
};
|
|
289
|
-
|
|
290
|
-
/** @type {_x} */
|
|
291
159
|
const _x = (text, context, domain) => {
|
|
292
160
|
let translation = dcnpgettext(domain, context, text);
|
|
293
161
|
if (!hooks) {
|
|
@@ -297,17 +165,14 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
297
165
|
/**
|
|
298
166
|
* Filters text with its translation based on context information.
|
|
299
167
|
*
|
|
300
|
-
* @param
|
|
301
|
-
* @param
|
|
302
|
-
* @param
|
|
303
|
-
* @param
|
|
168
|
+
* @param translation Translated text.
|
|
169
|
+
* @param text Text to translate.
|
|
170
|
+
* @param context Context information for the translators.
|
|
171
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
304
172
|
*/
|
|
305
|
-
translation =
|
|
306
|
-
|
|
307
|
-
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
|
|
173
|
+
translation = hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
|
|
174
|
+
return hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
|
|
308
175
|
};
|
|
309
|
-
|
|
310
|
-
/** @type {_n} */
|
|
311
176
|
const _n = (single, plural, number, domain) => {
|
|
312
177
|
let translation = dcnpgettext(domain, undefined, single, plural, number);
|
|
313
178
|
if (!hooks) {
|
|
@@ -317,18 +182,15 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
317
182
|
/**
|
|
318
183
|
* Filters the singular or plural form of a string.
|
|
319
184
|
*
|
|
320
|
-
* @param
|
|
321
|
-
* @param
|
|
322
|
-
* @param
|
|
323
|
-
* @param
|
|
324
|
-
* @param
|
|
185
|
+
* @param translation Translated text.
|
|
186
|
+
* @param single The text to be used if the number is singular.
|
|
187
|
+
* @param plural The text to be used if the number is plural.
|
|
188
|
+
* @param number The number to compare against to use either the singular or plural form.
|
|
189
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
325
190
|
*/
|
|
326
|
-
translation =
|
|
327
|
-
|
|
328
|
-
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
|
|
191
|
+
translation = hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
|
|
192
|
+
return hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
|
|
329
193
|
};
|
|
330
|
-
|
|
331
|
-
/** @type {_nx} */
|
|
332
194
|
const _nx = (single, plural, number, context, domain) => {
|
|
333
195
|
let translation = dcnpgettext(domain, context, single, plural, number);
|
|
334
196
|
if (!hooks) {
|
|
@@ -338,24 +200,19 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
338
200
|
/**
|
|
339
201
|
* Filters the singular or plural form of a string with gettext context.
|
|
340
202
|
*
|
|
341
|
-
* @param
|
|
342
|
-
* @param
|
|
343
|
-
* @param
|
|
344
|
-
* @param
|
|
345
|
-
* @param
|
|
346
|
-
* @param
|
|
203
|
+
* @param translation Translated text.
|
|
204
|
+
* @param single The text to be used if the number is singular.
|
|
205
|
+
* @param plural The text to be used if the number is plural.
|
|
206
|
+
* @param number The number to compare against to use either the singular or plural form.
|
|
207
|
+
* @param context Context information for the translators.
|
|
208
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
347
209
|
*/
|
|
348
|
-
translation =
|
|
349
|
-
|
|
350
|
-
return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
|
|
210
|
+
translation = hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
|
|
211
|
+
return hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
|
|
351
212
|
};
|
|
352
|
-
|
|
353
|
-
/** @type {IsRtl} */
|
|
354
213
|
const isRTL = () => {
|
|
355
214
|
return 'rtl' === _x('ltr', 'text direction');
|
|
356
215
|
};
|
|
357
|
-
|
|
358
|
-
/** @type {HasTranslation} */
|
|
359
216
|
const hasTranslation = (single, context, domain) => {
|
|
360
217
|
const key = context ? context + '\u0004' + single : single;
|
|
361
218
|
let result = !!tannin.data?.[domain !== null && domain !== void 0 ? domain : 'default']?.[key];
|
|
@@ -363,15 +220,13 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
363
220
|
/**
|
|
364
221
|
* Filters the presence of a translation in the locale data.
|
|
365
222
|
*
|
|
366
|
-
* @param
|
|
367
|
-
* @param
|
|
368
|
-
* @param
|
|
369
|
-
* @param
|
|
223
|
+
* @param hasTranslation Whether the translation is present or not..
|
|
224
|
+
* @param single The singular form of the translated text (used as key in locale data)
|
|
225
|
+
* @param context Context information for the translators.
|
|
226
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
370
227
|
*/
|
|
371
|
-
result =
|
|
372
|
-
|
|
373
|
-
result = /** @type { boolean } */
|
|
374
|
-
/** @type {*} */hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
|
|
228
|
+
result = hooks.applyFilters('i18n.has_translation', result, single, context, domain);
|
|
229
|
+
result = hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
|
|
375
230
|
}
|
|
376
231
|
return result;
|
|
377
232
|
};
|
|
@@ -380,7 +235,7 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
380
235
|
}
|
|
381
236
|
if (hooks) {
|
|
382
237
|
/**
|
|
383
|
-
* @param
|
|
238
|
+
* @param hookName
|
|
384
239
|
*/
|
|
385
240
|
const onHookAddedOrRemoved = hookName => {
|
|
386
241
|
if (I18N_HOOK_REGEXP.test(hookName)) {
|
package/build/create-i18n.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_tannin","_interopRequireDefault","require","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","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","exports"],"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":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;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;AACO,MAAMC,UAAU,GAAGA,CAAEC,WAAW,EAAEC,aAAa,EAAEC,KAAK,KAAM;EAClE;AACD;AACA;AACA;AACA;EACC,MAAMC,MAAM,GAAG,IAAIC,eAAM,CAAE,CAAC,CAAE,CAAC;EAE/B,MAAMC,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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uB,GAAGJ,eAAe,CAAEb,MAAO,CAAC,EACnDwB,MAAM,EACNf,MAAM,EACND,OAAO,EACPR,MACD,CACA;IACF;IACA,OAAOwB,MAAM;EACd,CAAC;EAED,IAAKvC,WAAW,EAAG;IAClBmB,aAAa,CAAEnB,WAAW,EAAEC,aAAc,CAAC;EAC5C;EAEA,IAAKC,KAAK,EAAG;IACZ;AACF;AACA;IACE,MAAMsC,oBAAoB,GAAKC,QAAQ,IAAM;MAC5C,IAAK3C,gBAAgB,CAAC4C,IAAI,CAAED,QAAS,CAAC,EAAG;QACxClC,eAAe,CAAC,CAAC;MAClB;IACD,CAAC;IAEDL,KAAK,CAACyC,SAAS,CAAE,WAAW,EAAE,WAAW,EAAEH,oBAAqB,CAAC;IACjEtC,KAAK,CAACyC,SAAS,CAAE,aAAa,EAAE,WAAW,EAAEH,oBAAqB,CAAC;EACpE;EAEA,OAAO;IACN1B,aAAa;IACbK,aAAa;IACbC,aAAa;IACbC,eAAe;IACfX,SAAS;IACTmB,EAAE;IACFI,EAAE;IACFC,EAAE;IACFC,GAAG;IACHC,KAAK;IACLC;EACD,CAAC;AACF,CAAC;AAACO,OAAA,CAAA7C,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_tannin","_interopRequireDefault","require","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","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","exports"],"sources":["@wordpress/i18n/src/create-i18n.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { TanninLocaleDomain } from 'tannin';\nimport Tannin from 'tannin';\n/**\n * Internal dependencies\n */\nimport type {\n\tgetFilterDomain,\n\tI18n,\n\tLocaleData,\n\tSubscribeCallback,\n\tTranslatableText,\n\tUnsubscribeCallback,\n} from './types';\n/**\n * WordPress dependencies\n */\nimport type { Hooks } from '@wordpress/hooks';\n/**\n * Default locale data to use for Tannin domain when not otherwise provided.\n * Assumes an English plural forms expression.\n */\nconst DEFAULT_LOCALE_DATA: LocaleData = {\n\t'': {\n\t\tplural_forms( n: number ) {\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 * Create an i18n instance\n *\n * @param [initialData] Locale data configuration.\n * @param [initialDomain] Domain for which configuration applies.\n * @param [hooks] Hooks implementation.\n *\n * @return I18n instance.\n */\nexport const createI18n = < TextDomain extends string >(\n\tinitialData?: LocaleData< TextDomain >,\n\tinitialDomain?: TextDomain,\n\thooks?: Hooks\n): I18n< TextDomain > => {\n\t/**\n\t * The underlying instance of Tannin to which exported functions interface.\n\t */\n\tconst tannin = new Tannin( {} );\n\n\tconst listeners = new Set< () => void >();\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 callback Subscription callback.\n\t * @return Unsubscribe callback.\n\t */\n\tconst subscribe = ( callback: SubscribeCallback ): UnsubscribeCallback => {\n\t\tlisteners.add( callback );\n\t\treturn () => listeners.delete( callback );\n\t};\n\n\tconst getLocaleData: I18n< TextDomain >[ 'getLocaleData' ] = (\n\t\tdomain = 'default' as TextDomain\n\t) => tannin.data[ domain ] as LocaleData< TextDomain >;\n\n\t/**\n\t * @param [data]\n\t * @param [domain]\n\t */\n\tconst doSetLocaleData = (\n\t\tdata?: LocaleData,\n\t\tdomain: TextDomain = 'default' as TextDomain\n\t) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t} as TanninLocaleDomain;\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\tconst setLocaleData: I18n< TextDomain >[ 'setLocaleData' ] = (\n\t\tdata,\n\t\tdomain\n\t) => {\n\t\tdoSetLocaleData( data, domain );\n\t\tnotifyListeners();\n\t};\n\n\tconst addLocaleData: I18n< TextDomain >[ 'addLocaleData' ] = (\n\t\tdata,\n\t\tdomain = 'default' as TextDomain\n\t) => {\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} as TanninLocaleDomain;\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\tconst resetLocaleData: I18n< TextDomain >[ 'resetLocaleData' ] = (\n\t\tdata,\n\t\tdomain\n\t) => {\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 domain Domain to retrieve the translated text.\n\t * @param context Context information for the translators.\n\t * @param single Text to translate if non-plural. Used as\n\t * fallback return value on a caught error.\n\t * @param [plural] The text to be used if the number is\n\t * plural.\n\t * @param [number] The number to compare against to use\n\t * either the singular or plural form.\n\t *\n\t * @return The translated string.\n\t */\n\tconst dcnpgettext = (\n\t\tdomain = 'default' as TextDomain,\n\t\tcontext: string | void,\n\t\tsingle: string,\n\t\tplural?: string,\n\t\tnumber?: number\n\t): string => {\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\tconst getFilterDomain: getFilterDomain = ( domain ) => domain || 'default';\n\n\tconst __: I18n< TextDomain >[ '__' ] = ( text, domain ) => {\n\t\tlet translation = dcnpgettext( domain, undefined, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation as TranslatableText< typeof text >;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation.\n\t\t *\n\t\t * @param translation Translated text.\n\t\t * @param text Text to translate.\n\t\t * @param domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = hooks.applyFilters(\n\t\t\t'i18n.gettext',\n\t\t\ttranslation,\n\t\t\ttext,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof text >;\n\n\t\treturn hooks.applyFilters(\n\t\t\t'i18n.gettext_' + getFilterDomain( domain ),\n\t\t\ttranslation,\n\t\t\ttext,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof text >;\n\t};\n\n\tconst _x: I18n< TextDomain >[ '_x' ] = ( text, context, domain ) => {\n\t\tlet translation = dcnpgettext( domain, context, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation as TranslatableText< typeof text >;\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 translation Translated text.\n\t\t * @param text Text to translate.\n\t\t * @param context Context information for the translators.\n\t\t * @param domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = hooks.applyFilters(\n\t\t\t'i18n.gettext_with_context',\n\t\t\ttranslation,\n\t\t\ttext,\n\t\t\tcontext,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof text >;\n\n\t\treturn hooks.applyFilters(\n\t\t\t'i18n.gettext_with_context_' + getFilterDomain( domain ),\n\t\t\ttranslation,\n\t\t\ttext,\n\t\t\tcontext,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof text >;\n\t};\n\n\tconst _n: I18n< TextDomain >[ '_n' ] = (\n\t\tsingle,\n\t\tplural,\n\t\tnumber,\n\t\tdomain\n\t) => {\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 as TranslatableText<\n\t\t\t\ttypeof single | typeof plural\n\t\t\t>;\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 translation Translated text.\n\t\t * @param single The text to be used if the number is singular.\n\t\t * @param plural The text to be used if the number is plural.\n\t\t * @param number The number to compare against to use either the singular or plural form.\n\t\t * @param domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = hooks.applyFilters(\n\t\t\t'i18n.ngettext',\n\t\t\ttranslation,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof single | typeof plural >;\n\n\t\treturn hooks.applyFilters(\n\t\t\t'i18n.ngettext_' + getFilterDomain( domain ),\n\t\t\ttranslation,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof single | typeof plural >;\n\t};\n\n\tconst _nx: I18n< TextDomain >[ '_nx' ] = (\n\t\tsingle,\n\t\tplural,\n\t\tnumber,\n\t\tcontext,\n\t\tdomain\n\t) => {\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 as TranslatableText<\n\t\t\t\ttypeof single | typeof plural\n\t\t\t>;\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 translation Translated text.\n\t\t * @param single The text to be used if the number is singular.\n\t\t * @param plural The text to be used if the number is plural.\n\t\t * @param number The number to compare against to use either the singular or plural form.\n\t\t * @param context Context information for the translators.\n\t\t * @param domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = hooks.applyFilters(\n\t\t\t'i18n.ngettext_with_context',\n\t\t\ttranslation,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber,\n\t\t\tcontext,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof single | typeof plural >;\n\n\t\treturn hooks.applyFilters(\n\t\t\t'i18n.ngettext_with_context_' + getFilterDomain( domain ),\n\t\t\ttranslation,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber,\n\t\t\tcontext,\n\t\t\tdomain\n\t\t) as TranslatableText< typeof single | typeof plural >;\n\t};\n\n\tconst isRTL: I18n< TextDomain >[ 'isRTL' ] = () => {\n\t\treturn 'rtl' === _x( 'ltr', 'text direction' );\n\t};\n\n\tconst hasTranslation: I18n< TextDomain >[ 'hasTranslation' ] = (\n\t\tsingle,\n\t\tcontext,\n\t\tdomain\n\t) => {\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 hasTranslation Whether the translation is present or not..\n\t\t\t * @param single The singular form of the translated text (used as key in locale data)\n\t\t\t * @param context Context information for the translators.\n\t\t\t * @param domain Text domain. Unique identifier for retrieving translated strings.\n\t\t\t */\n\t\t\tresult = hooks.applyFilters(\n\t\t\t\t'i18n.has_translation',\n\t\t\t\tresult,\n\t\t\t\tsingle,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t) as boolean;\n\n\t\t\tresult = hooks.applyFilters(\n\t\t\t\t'i18n.has_translation_' + getFilterDomain( domain ),\n\t\t\t\tresult,\n\t\t\t\tsingle,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t) as boolean;\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 hookName\n\t\t */\n\t\tconst onHookAddedOrRemoved = ( hookName: string ) => {\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":";;;;;;;AAIA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAMC,mBAA+B,GAAG;EACvC,EAAE,EAAE;IACHC,YAAYA,CAAEC,CAAS,EAAG;MACzB,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;AACO,MA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