@wordpress/i18n 5.26.0 → 6.0.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 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
@@ -113,16 +113,16 @@ _Parameters_
113
113
 
114
114
  ### sprintf
115
115
 
116
- Returns a formatted string. If an error occurs in applying the format, the original format string is returned.
116
+ Returns a formatted string.
117
117
 
118
118
  _Related_
119
119
 
120
- - <https://www.npmjs.com/package/sprintf-js>
120
+ - <https://www.npmjs.com/package/@tannin/sprintf>
121
121
 
122
122
  _Parameters_
123
123
 
124
- - _format_ `string`: The format of the string to generate.
125
- - _args_ `...*`: Arguments to apply to the format.
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_ `string`: The text to be used if the number is singular.
154
- - _plural_ `string`: The text to be used if the number is 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
156
  - _domain_ `[string]`: Domain to retrieve the translated text.
157
157
 
158
158
  _Returns_
159
159
 
160
- - `string`: The translated singular or plural form.
160
+ - `import('./types').TranslatableText< Single | Plural >`: The translated singular or plural form.
161
161
 
162
162
  ### \_nx
163
163
 
@@ -169,15 +169,15 @@ _Related_
169
169
 
170
170
  _Parameters_
171
171
 
172
- - _single_ `string`: The text to be used if the number is singular.
173
- - _plural_ `string`: The text to be used if the number is plural.
172
+ - _single_ `Single`: The text to be used if the number is singular.
173
+ - _plural_ `Plural`: The text to be used if the number is plural.
174
174
  - _number_ `number`: The number to compare against to use either the singular or plural form.
175
175
  - _context_ `string`: Context information for the translators.
176
176
  - _domain_ `[string]`: Domain to retrieve the translated text.
177
177
 
178
178
  _Returns_
179
179
 
180
- - `string`: The translated singular or plural form.
180
+ - `import('./types').TranslatableText< Single | Plural >`: The translated singular or plural form.
181
181
 
182
182
  ### \_x
183
183
 
@@ -189,13 +189,13 @@ _Related_
189
189
 
190
190
  _Parameters_
191
191
 
192
- - _text_ `string`: Text to translate.
192
+ - _text_ `Text`: Text to translate.
193
193
  - _context_ `string`: Context information for the translators.
194
194
  - _domain_ `[string]`: Domain to retrieve the translated text.
195
195
 
196
196
  _Returns_
197
197
 
198
- - `string`: Translated context string without pipe.
198
+ - `import('./types').TranslatableText< Text >`: Translated context string without pipe.
199
199
 
200
200
  ### \_\_
201
201
 
@@ -207,12 +207,12 @@ _Related_
207
207
 
208
208
  _Parameters_
209
209
 
210
- - _text_ `string`: Text to translate.
210
+ - _text_ `Text`: Text to translate.
211
211
  - _domain_ `[string]`: Domain to retrieve the translated text.
212
212
 
213
213
  _Returns_
214
214
 
215
- - `string`: Translated text.
215
+ - `import('./types').TranslatableText< Text >`: Translated text.
216
216
 
217
217
  <!-- END TOKEN(Autogenerated API docs) -->
218
218
 
@@ -81,21 +81,21 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
81
81
  * Retrieve the domain to use when calling domain-specific filters.
82
82
  */
83
83
  /**
84
- * @typedef {(text: string, domain?: string) => string} __
84
+ * @typedef {<Text extends string>(text: Text, domain?: string) => import('./types').TranslatableText< Text >} __
85
85
  *
86
86
  * Retrieve the translation of text.
87
87
  *
88
88
  * @see https://developer.wordpress.org/reference/functions/__/
89
89
  */
90
90
  /**
91
- * @typedef {(text: string, context: string, domain?: string) => string} _x
91
+ * @typedef {<Text extends string>(text: Text, context: string, domain?: string) => import('./types').TranslatableText< Text >} _x
92
92
  *
93
93
  * Retrieve translated string with gettext context.
94
94
  *
95
95
  * @see https://developer.wordpress.org/reference/functions/_x/
96
96
  */
97
97
  /**
98
- * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
98
+ * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string) => import('./types').TranslatableText< Single | Plural >} _n
99
99
  *
100
100
  * Translates and retrieves the singular or plural form based on the supplied
101
101
  * number.
@@ -103,7 +103,7 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
103
103
  * @see https://developer.wordpress.org/reference/functions/_n/
104
104
  */
105
105
  /**
106
- * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
106
+ * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: string) => import('./types').TranslatableText< Single | Plural >} _nx
107
107
  *
108
108
  * Translates and retrieves the singular or plural form based on the supplied
109
109
  * number, with gettext context.
@@ -272,7 +272,7 @@ const createI18n = (initialData, initialDomain, hooks) => {
272
272
  const __ = (text, domain) => {
273
273
  let translation = dcnpgettext(domain, undefined, text);
274
274
  if (!hooks) {
275
- return translation;
275
+ return /** @type {import('./types').TranslatableText<typeof text>} */translation;
276
276
  }
277
277
 
278
278
  /**
@@ -284,14 +284,14 @@ const createI18n = (initialData, initialDomain, hooks) => {
284
284
  */
285
285
  translation = /** @type {string} */
286
286
  /** @type {*} */hooks.applyFilters('i18n.gettext', translation, text, domain);
287
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
287
+ return /** @type {import('./types').TranslatableText<typeof text>} */ /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
288
288
  };
289
289
 
290
290
  /** @type {_x} */
291
291
  const _x = (text, context, domain) => {
292
292
  let translation = dcnpgettext(domain, context, text);
293
293
  if (!hooks) {
294
- return translation;
294
+ return /** @type {import('./types').TranslatableText<typeof text>} */translation;
295
295
  }
296
296
 
297
297
  /**
@@ -304,14 +304,14 @@ const createI18n = (initialData, initialDomain, hooks) => {
304
304
  */
305
305
  translation = /** @type {string} */
306
306
  /** @type {*} */hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
307
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
307
+ return /** @type {import('./types').TranslatableText<typeof text>} */ /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
308
308
  };
309
309
 
310
310
  /** @type {_n} */
311
311
  const _n = (single, plural, number, domain) => {
312
312
  let translation = dcnpgettext(domain, undefined, single, plural, number);
313
313
  if (!hooks) {
314
- return translation;
314
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */translation;
315
315
  }
316
316
 
317
317
  /**
@@ -325,14 +325,14 @@ const createI18n = (initialData, initialDomain, hooks) => {
325
325
  */
326
326
  translation = /** @type {string} */
327
327
  /** @type {*} */hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
328
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
328
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
329
329
  };
330
330
 
331
331
  /** @type {_nx} */
332
332
  const _nx = (single, plural, number, context, domain) => {
333
333
  let translation = dcnpgettext(domain, context, single, plural, number);
334
334
  if (!hooks) {
335
- return translation;
335
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */translation;
336
336
  }
337
337
 
338
338
  /**
@@ -347,7 +347,7 @@ const createI18n = (initialData, initialDomain, hooks) => {
347
347
  */
348
348
  translation = /** @type {string} */
349
349
  /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
350
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
350
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
351
351
  };
352
352
 
353
353
  /** @type {IsRtl} */
@@ -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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MACGqC,MAAM,GAAG;MACR,gBAAiBrC,KAAK,CAAC8B,YAAY,CAClC,sBAAsB,EACtBO,MAAM,EACNf,MAAM,EACND,OAAO,EACPR,MACD,CACA;MAEDwB,MAAM,GAAG;MACR,gBAAiBrC,KAAK,CAAC8B,YAAY,CAClC,uBAAuB,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.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 extends string>(text: Text, domain?: string) => import('./types').TranslatableText< Text >} __\n *\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n */\n/**\n * @typedef {<Text extends string>(text: Text, context: string, domain?: string) => import('./types').TranslatableText< Text >} _x\n *\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n */\n/**\n * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string) => import('./types').TranslatableText< Single | Plural >} _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 extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: string) => import('./types').TranslatableText< Single | Plural >} _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 /** @type {import('./types').TranslatableText<typeof text>} */ (\n\t\t\t\ttranslation\n\t\t\t);\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 {import('./types').TranslatableText<typeof text>} */ (\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 /** @type {import('./types').TranslatableText<typeof text>} */ (\n\t\t\t\ttranslation\n\t\t\t);\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 {import('./types').TranslatableText<typeof text>} */ (\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 /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (\n\t\t\t\ttranslation\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 {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 {import('./types').TranslatableText<typeof single | typeof plural>} */ (\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 /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (\n\t\t\t\ttranslation\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 {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 {import('./types').TranslatableText<typeof single | typeof plural>} */ (\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,SAA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B,MAAM,GAAG;MACR,gBAAiBrC,KAAK,CAAC8B,YAAY,CAClC,uBAAuB,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":[]}
@@ -74,10 +74,12 @@ const subscribe = exports.subscribe = i18n.subscribe.bind(i18n);
74
74
  *
75
75
  * @see https://developer.wordpress.org/reference/functions/__/
76
76
  *
77
- * @param {string} text Text to translate.
77
+ * @template {string} Text
78
+ *
79
+ * @param {Text} text Text to translate.
78
80
  * @param {string} [domain] Domain to retrieve the translated text.
79
81
  *
80
- * @return {string} Translated text.
82
+ * @return {import('./types').TranslatableText< Text >} Translated text.
81
83
  */
82
84
  const __ = exports.__ = i18n.__.bind(i18n);
83
85
 
@@ -86,11 +88,13 @@ const __ = exports.__ = i18n.__.bind(i18n);
86
88
  *
87
89
  * @see https://developer.wordpress.org/reference/functions/_x/
88
90
  *
89
- * @param {string} text Text to translate.
91
+ * @template {string} Text
92
+ *
93
+ * @param {Text} text Text to translate.
90
94
  * @param {string} context Context information for the translators.
91
95
  * @param {string} [domain] Domain to retrieve the translated text.
92
96
  *
93
- * @return {string} Translated context string without pipe.
97
+ * @return {import('./types').TranslatableText< Text >} Translated context string without pipe.
94
98
  */
95
99
  const _x = exports._x = i18n._x.bind(i18n);
96
100
 
@@ -100,13 +104,16 @@ const _x = exports._x = i18n._x.bind(i18n);
100
104
  *
101
105
  * @see https://developer.wordpress.org/reference/functions/_n/
102
106
  *
103
- * @param {string} single The text to be used if the number is singular.
104
- * @param {string} plural The text to be used if the number is plural.
107
+ * @template {string} Single
108
+ * @template {string} Plural
109
+ *
110
+ * @param {Single} single The text to be used if the number is singular.
111
+ * @param {Plural} plural The text to be used if the number is plural.
105
112
  * @param {number} number The number to compare against to use either the
106
113
  * singular or plural form.
107
114
  * @param {string} [domain] Domain to retrieve the translated text.
108
115
  *
109
- * @return {string} The translated singular or plural form.
116
+ * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.
110
117
  */
111
118
  const _n = exports._n = i18n._n.bind(i18n);
112
119
 
@@ -116,14 +123,17 @@ const _n = exports._n = i18n._n.bind(i18n);
116
123
  *
117
124
  * @see https://developer.wordpress.org/reference/functions/_nx/
118
125
  *
119
- * @param {string} single The text to be used if the number is singular.
120
- * @param {string} plural The text to be used if the number is plural.
126
+ * @template {string} Single
127
+ * @template {string} Plural
128
+ *
129
+ * @param {Single} single The text to be used if the number is singular.
130
+ * @param {Plural} plural The text to be used if the number is plural.
121
131
  * @param {number} number The number to compare against to use either the
122
132
  * singular or plural form.
123
133
  * @param {string} context Context information for the translators.
124
134
  * @param {string} [domain] Domain to retrieve the translated text.
125
135
  *
126
- * @return {string} The translated singular or plural form.
136
+ * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.
127
137
  */
128
138
  const _nx = exports._nx = i18n._nx.bind(i18n);
129
139
 
@@ -1 +1 @@
1
- {"version":3,"names":["_createI18n","require","_hooks","i18n","createI18n","undefined","defaultHooks","_default","exports","default","getLocaleData","bind","setLocaleData","resetLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/default-i18n.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createI18n } from './create-i18n';\n\n/**\n * WordPress dependencies\n */\nimport { defaultHooks } from '@wordpress/hooks';\n\nconst i18n = createI18n( undefined, undefined, defaultHooks );\n\n/**\n * Default, singleton instance of `I18n`.\n */\nexport default i18n;\n\n/*\n * Comments in this file are duplicated from ./i18n due to\n * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722\n */\n\n/**\n * @typedef {import('./create-i18n').LocaleData} LocaleData\n * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback\n * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback\n */\n\n/**\n * Returns locale data by domain in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {string} [domain] Domain for which to get the data.\n * @return {LocaleData} Locale data.\n */\nexport const getLocaleData = i18n.getLocaleData.bind( i18n );\n\n/**\n * Merges locale data into the Tannin instance by domain. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const setLocaleData = i18n.setLocaleData.bind( i18n );\n\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 * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const resetLocaleData = i18n.resetLocaleData.bind( i18n );\n\n/**\n * Subscribes to changes of locale data\n *\n * @param {SubscribeCallback} callback Subscription callback\n * @return {UnsubscribeCallback} Unsubscribe callback\n */\nexport const subscribe = i18n.subscribe.bind( i18n );\n\n/**\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n *\n * @param {string} text Text to translate.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} Translated text.\n */\nexport const __ = i18n.__.bind( i18n );\n\n/**\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n *\n * @param {string} text Text to translate.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} Translated context string without pipe.\n */\nexport const _x = i18n._x.bind( i18n );\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 * @param {string} single The text to be used if the number is singular.\n * @param {string} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} The translated singular or plural form.\n */\nexport const _n = i18n._n.bind( i18n );\n\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 * @param {string} single The text to be used if the number is singular.\n * @param {string} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} The translated singular or plural form.\n */\nexport const _nx = i18n._nx.bind( i18n );\n\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 * @return {boolean} Whether locale is RTL.\n */\nexport const isRTL = i18n.isRTL.bind( i18n );\n\n/**\n * Check if there is a translation for a given string (in singular form).\n *\n * @param {string} single Singular form of the string to look up.\n * @param {string} [context] Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n * @return {boolean} Whether the translation exists or not.\n */\nexport const hasTranslation = i18n.hasTranslation.bind( i18n );\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAME,IAAI,GAAG,IAAAC,sBAAU,EAAEC,SAAS,EAAEA,SAAS,EAAEC,mBAAa,CAAC;;AAE7D;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeN,IAAI;AAEnB;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMO,aAAa,GAAAF,OAAA,CAAAE,aAAA,GAAGP,IAAI,CAACO,aAAa,CAACC,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,aAAa,GAAAJ,OAAA,CAAAI,aAAA,GAAGT,IAAI,CAACS,aAAa,CAACD,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMU,eAAe,GAAAL,OAAA,CAAAK,eAAA,GAAGV,IAAI,CAACU,eAAe,CAACF,IAAI,CAAER,IAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACO,MAAMW,SAAS,GAAAN,OAAA,CAAAM,SAAA,GAAGX,IAAI,CAACW,SAAS,CAACH,IAAI,CAAER,IAAK,CAAC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMY,EAAE,GAAAP,OAAA,CAAAO,EAAA,GAAGZ,IAAI,CAACY,EAAE,CAACJ,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMa,EAAE,GAAAR,OAAA,CAAAQ,EAAA,GAAGb,IAAI,CAACa,EAAE,CAACL,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMc,EAAE,GAAAT,OAAA,CAAAS,EAAA,GAAGd,IAAI,CAACc,EAAE,CAACN,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMe,GAAG,GAAAV,OAAA,CAAAU,GAAA,GAAGf,IAAI,CAACe,GAAG,CAACP,IAAI,CAAER,IAAK,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMgB,KAAK,GAAAX,OAAA,CAAAW,KAAA,GAAGhB,IAAI,CAACgB,KAAK,CAACR,IAAI,CAAER,IAAK,CAAC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMiB,cAAc,GAAAZ,OAAA,CAAAY,cAAA,GAAGjB,IAAI,CAACiB,cAAc,CAACT,IAAI,CAAER,IAAK,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_createI18n","require","_hooks","i18n","createI18n","undefined","defaultHooks","_default","exports","default","getLocaleData","bind","setLocaleData","resetLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/default-i18n.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createI18n } from './create-i18n';\n\n/**\n * WordPress dependencies\n */\nimport { defaultHooks } from '@wordpress/hooks';\n\nconst i18n = createI18n( undefined, undefined, defaultHooks );\n\n/**\n * Default, singleton instance of `I18n`.\n */\nexport default i18n;\n\n/*\n * Comments in this file are duplicated from ./i18n due to\n * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722\n */\n\n/**\n * @typedef {import('./create-i18n').LocaleData} LocaleData\n * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback\n * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback\n */\n\n/**\n * Returns locale data by domain in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {string} [domain] Domain for which to get the data.\n * @return {LocaleData} Locale data.\n */\nexport const getLocaleData = i18n.getLocaleData.bind( i18n );\n\n/**\n * Merges locale data into the Tannin instance by domain. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const setLocaleData = i18n.setLocaleData.bind( i18n );\n\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 * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const resetLocaleData = i18n.resetLocaleData.bind( i18n );\n\n/**\n * Subscribes to changes of locale data\n *\n * @param {SubscribeCallback} callback Subscription callback\n * @return {UnsubscribeCallback} Unsubscribe callback\n */\nexport const subscribe = i18n.subscribe.bind( i18n );\n\n/**\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n *\n * @template {string} Text\n *\n * @param {Text} text Text to translate.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Text >} Translated text.\n */\nexport const __ = i18n.__.bind( i18n );\n\n/**\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n *\n * @template {string} Text\n *\n * @param {Text} text Text to translate.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Text >} Translated context string without pipe.\n */\nexport const _x = i18n._x.bind( i18n );\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 * @template {string} Single\n * @template {string} Plural\n *\n * @param {Single} single The text to be used if the number is singular.\n * @param {Plural} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.\n */\nexport const _n = i18n._n.bind( i18n );\n\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 * @template {string} Single\n * @template {string} Plural\n *\n * @param {Single} single The text to be used if the number is singular.\n * @param {Plural} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.\n */\nexport const _nx = i18n._nx.bind( i18n );\n\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 * @return {boolean} Whether locale is RTL.\n */\nexport const isRTL = i18n.isRTL.bind( i18n );\n\n/**\n * Check if there is a translation for a given string (in singular form).\n *\n * @param {string} single Singular form of the string to look up.\n * @param {string} [context] Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n * @return {boolean} Whether the translation exists or not.\n */\nexport const hasTranslation = i18n.hasTranslation.bind( i18n );\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAME,IAAI,GAAG,IAAAC,sBAAU,EAAEC,SAAS,EAAEA,SAAS,EAAEC,mBAAa,CAAC;;AAE7D;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeN,IAAI;AAEnB;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMO,aAAa,GAAAF,OAAA,CAAAE,aAAA,GAAGP,IAAI,CAACO,aAAa,CAACC,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,aAAa,GAAAJ,OAAA,CAAAI,aAAA,GAAGT,IAAI,CAACS,aAAa,CAACD,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMU,eAAe,GAAAL,OAAA,CAAAK,eAAA,GAAGV,IAAI,CAACU,eAAe,CAACF,IAAI,CAAER,IAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACO,MAAMW,SAAS,GAAAN,OAAA,CAAAM,SAAA,GAAGX,IAAI,CAACW,SAAS,CAACH,IAAI,CAAER,IAAK,CAAC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMY,EAAE,GAAAP,OAAA,CAAAO,EAAA,GAAGZ,IAAI,CAACY,EAAE,CAACJ,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMa,EAAE,GAAAR,OAAA,CAAAQ,EAAA,GAAGb,IAAI,CAACa,EAAE,CAACL,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMc,EAAE,GAAAT,OAAA,CAAAS,EAAA,GAAGd,IAAI,CAACc,EAAE,CAACN,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMe,GAAG,GAAAV,OAAA,CAAAU,GAAA,GAAGf,IAAI,CAACe,GAAG,CAACP,IAAI,CAAER,IAAK,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMgB,KAAK,GAAAX,OAAA,CAAAW,KAAA,GAAGhB,IAAI,CAACgB,KAAK,CAACR,IAAI,CAAER,IAAK,CAAC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMiB,cAAc,GAAAZ,OAAA,CAAAY,cAAA,GAAGjB,IAAI,CAACiB,cAAc,CAACT,IAAI,CAAER,IAAK,CAAC","ignoreList":[]}
package/build/sprintf.js CHANGED
@@ -5,40 +5,29 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.sprintf = sprintf;
8
- var _memize = _interopRequireDefault(require("memize"));
9
- var _sprintfJs = _interopRequireDefault(require("sprintf-js"));
8
+ var _sprintf2 = _interopRequireDefault(require("@tannin/sprintf"));
10
9
  /**
11
10
  * External dependencies
12
11
  */
12
+ // Disable reason: `eslint-plugin-import` doesn't support `exports` (https://github.com/import-js/eslint-plugin-import/issues/1810)
13
+ // eslint-disable-next-line import/no-unresolved
13
14
 
14
15
  /**
15
- * Log to console, once per message; or more precisely, per referentially equal
16
- * argument set. Because Jed throws errors, we log these to the console instead
17
- * to avoid crashing the application.
18
- *
19
- * @param {...*} args Arguments to pass to `console.error`
16
+ * Internal dependencies
20
17
  */
21
- const logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line no-console
22
18
 
23
19
  /**
24
- * Returns a formatted string. If an error occurs in applying the format, the
25
- * original format string is returned.
20
+ * Returns a formatted string.
26
21
  *
27
- * @param {string} format The format of the string to generate.
28
- * @param {...*} args Arguments to apply to the format.
22
+ * @template {string} T
23
+ * @param {T | TranslatableText<T>} format The format of the string to generate.
24
+ * @param {DistributeSprintfArgs<T>} args Arguments to apply to the format.
29
25
  *
30
- * @see https://www.npmjs.com/package/sprintf-js
26
+ * @see https://www.npmjs.com/package/@tannin/sprintf
31
27
  *
32
28
  * @return {string} The formatted string.
33
29
  */
34
30
  function sprintf(format, ...args) {
35
- try {
36
- return _sprintfJs.default.sprintf(format, ...args);
37
- } catch (error) {
38
- if (error instanceof Error) {
39
- logErrorOnce('sprintf error: \n\n' + error.toString());
40
- }
41
- return format;
42
- }
31
+ return (0, _sprintf2.default)(format, ...args);
43
32
  }
44
33
  //# sourceMappingURL=sprintf.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_memize","_interopRequireDefault","require","_sprintfJs","logErrorOnce","memoize","console","error","sprintf","format","args","sprintfjs","Error","toString"],"sources":["@wordpress/i18n/src/sprintf.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\nimport sprintfjs from 'sprintf-js';\n\n/**\n * Log to console, once per message; or more precisely, per referentially equal\n * argument set. Because Jed throws errors, we log these to the console instead\n * to avoid crashing the application.\n *\n * @param {...*} args Arguments to pass to `console.error`\n */\nconst logErrorOnce = memoize( console.error ); // eslint-disable-line no-console\n\n/**\n * Returns a formatted string. If an error occurs in applying the format, the\n * original format string is returned.\n *\n * @param {string} format The format of the string to generate.\n * @param {...*} args Arguments to apply to the format.\n *\n * @see https://www.npmjs.com/package/sprintf-js\n *\n * @return {string} The formatted string.\n */\nexport function sprintf( format, ...args ) {\n\ttry {\n\t\treturn sprintfjs.sprintf( format, ...args );\n\t} catch ( error ) {\n\t\tif ( error instanceof Error ) {\n\t\t\tlogErrorOnce( 'sprintf error: \\n\\n' + error.toString() );\n\t\t}\n\t\treturn format;\n\t}\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,YAAY,GAAG,IAAAC,eAAO,EAAEC,OAAO,CAACC,KAAM,CAAC,CAAC,CAAC;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CAAEC,MAAM,EAAE,GAAGC,IAAI,EAAG;EAC1C,IAAI;IACH,OAAOC,kBAAS,CAACH,OAAO,CAAEC,MAAM,EAAE,GAAGC,IAAK,CAAC;EAC5C,CAAC,CAAC,OAAQH,KAAK,EAAG;IACjB,IAAKA,KAAK,YAAYK,KAAK,EAAG;MAC7BR,YAAY,CAAE,qBAAqB,GAAGG,KAAK,CAACM,QAAQ,CAAC,CAAE,CAAC;IACzD;IACA,OAAOJ,MAAM;EACd;AACD","ignoreList":[]}
1
+ {"version":3,"names":["_sprintf2","_interopRequireDefault","require","sprintf","format","args","_sprintf"],"sources":["@wordpress/i18n/src/sprintf.ts"],"sourcesContent":["/**\n * External dependencies\n */\n// Disable reason: `eslint-plugin-import` doesn't support `exports` (https://github.com/import-js/eslint-plugin-import/issues/1810)\n// eslint-disable-next-line import/no-unresolved\nimport _sprintf from '@tannin/sprintf';\nimport type { SprintfArgs } from '@tannin/sprintf/types';\n\n/**\n * Internal dependencies\n */\nimport type { TranslatableText } from './types';\n\ntype DistributeSprintfArgs< T extends string > = T extends any\n\t? SprintfArgs< T >\n\t: never;\n\nexport function sprintf< T extends string >(\n\tformat: T | TranslatableText< T >,\n\t...args: DistributeSprintfArgs< T >\n): string;\nexport function sprintf< T extends string >(\n\tformat: T | TranslatableText< T >,\n\targs: DistributeSprintfArgs< T >\n): string;\n\n/**\n * Returns a formatted string.\n *\n * @template {string} T\n * @param {T | TranslatableText<T>} format The format of the string to generate.\n * @param {DistributeSprintfArgs<T>} args Arguments to apply to the format.\n *\n * @see https://www.npmjs.com/package/@tannin/sprintf\n *\n * @return {string} The formatted string.\n */\nexport function sprintf< T extends string >(\n\tformat: T | TranslatableText< T >,\n\t...args: DistributeSprintfArgs< T >\n): string {\n\treturn _sprintf( format as T, ...( args as DistributeSprintfArgs< T > ) );\n}\n"],"mappings":";;;;;;;AAKA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AALA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CACtBC,MAAiC,EACjC,GAAGC,IAAgC,EAC1B;EACT,OAAO,IAAAC,iBAAQ,EAAEF,MAAM,EAAO,GAAKC,IAAqC,CAAC;AAC1E","ignoreList":[]}
package/build/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["@wordpress/i18n/src/types.ts"],"sourcesContent":["/**\n * Return type for string translation functions.\n *\n * This type should be treated as if it were `string`.\n */\nexport type TranslatableText< T extends string > = string & {\n\t/**\n\t * DO NOT USE! This property _does not exist_.\n\t * @private\n\t */\n\treadonly __translatableText: T;\n};\n"],"mappings":"","ignoreList":[]}
@@ -74,21 +74,21 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
74
74
  * Retrieve the domain to use when calling domain-specific filters.
75
75
  */
76
76
  /**
77
- * @typedef {(text: string, domain?: string) => string} __
77
+ * @typedef {<Text extends string>(text: Text, domain?: string) => import('./types').TranslatableText< Text >} __
78
78
  *
79
79
  * Retrieve the translation of text.
80
80
  *
81
81
  * @see https://developer.wordpress.org/reference/functions/__/
82
82
  */
83
83
  /**
84
- * @typedef {(text: string, context: string, domain?: string) => string} _x
84
+ * @typedef {<Text extends string>(text: Text, context: string, domain?: string) => import('./types').TranslatableText< Text >} _x
85
85
  *
86
86
  * Retrieve translated string with gettext context.
87
87
  *
88
88
  * @see https://developer.wordpress.org/reference/functions/_x/
89
89
  */
90
90
  /**
91
- * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
91
+ * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string) => import('./types').TranslatableText< Single | Plural >} _n
92
92
  *
93
93
  * Translates and retrieves the singular or plural form based on the supplied
94
94
  * number.
@@ -96,7 +96,7 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
96
96
  * @see https://developer.wordpress.org/reference/functions/_n/
97
97
  */
98
98
  /**
99
- * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
99
+ * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: string) => import('./types').TranslatableText< Single | Plural >} _nx
100
100
  *
101
101
  * Translates and retrieves the singular or plural form based on the supplied
102
102
  * number, with gettext context.
@@ -265,7 +265,7 @@ export const createI18n = (initialData, initialDomain, hooks) => {
265
265
  const __ = (text, domain) => {
266
266
  let translation = dcnpgettext(domain, undefined, text);
267
267
  if (!hooks) {
268
- return translation;
268
+ return /** @type {import('./types').TranslatableText<typeof text>} */translation;
269
269
  }
270
270
 
271
271
  /**
@@ -277,14 +277,14 @@ export const createI18n = (initialData, initialDomain, hooks) => {
277
277
  */
278
278
  translation = /** @type {string} */
279
279
  /** @type {*} */hooks.applyFilters('i18n.gettext', translation, text, domain);
280
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
280
+ return /** @type {import('./types').TranslatableText<typeof text>} */ /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
281
281
  };
282
282
 
283
283
  /** @type {_x} */
284
284
  const _x = (text, context, domain) => {
285
285
  let translation = dcnpgettext(domain, context, text);
286
286
  if (!hooks) {
287
- return translation;
287
+ return /** @type {import('./types').TranslatableText<typeof text>} */translation;
288
288
  }
289
289
 
290
290
  /**
@@ -297,14 +297,14 @@ export const createI18n = (initialData, initialDomain, hooks) => {
297
297
  */
298
298
  translation = /** @type {string} */
299
299
  /** @type {*} */hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
300
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
300
+ return /** @type {import('./types').TranslatableText<typeof text>} */ /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
301
301
  };
302
302
 
303
303
  /** @type {_n} */
304
304
  const _n = (single, plural, number, domain) => {
305
305
  let translation = dcnpgettext(domain, undefined, single, plural, number);
306
306
  if (!hooks) {
307
- return translation;
307
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */translation;
308
308
  }
309
309
 
310
310
  /**
@@ -318,14 +318,14 @@ export const createI18n = (initialData, initialDomain, hooks) => {
318
318
  */
319
319
  translation = /** @type {string} */
320
320
  /** @type {*} */hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
321
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
321
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
322
322
  };
323
323
 
324
324
  /** @type {_nx} */
325
325
  const _nx = (single, plural, number, context, domain) => {
326
326
  let translation = dcnpgettext(domain, context, single, plural, number);
327
327
  if (!hooks) {
328
- return translation;
328
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */translation;
329
329
  }
330
330
 
331
331
  /**
@@ -340,7 +340,7 @@ export const createI18n = (initialData, initialDomain, hooks) => {
340
340
  */
341
341
  translation = /** @type {string} */
342
342
  /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
343
- return /** @type {string} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
343
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
344
344
  };
345
345
 
346
346
  /** @type {IsRtl} */