@wordpress/i18n 4.2.3 → 4.3.1

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,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.3.0 (2022-01-27)
6
+
7
+ - Add new `addLocaleData` method to merge locale data into the Tannin instance by domain.
8
+
5
9
  ## 4.2.0 (2021-07-21)
6
10
 
7
11
  ## 4.1.0 (2021-05-20)
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Gutenberg
2
2
 
3
- Copyright 2016-2021 by the contributors
3
+ Copyright 2016-2022 by the contributors
4
4
 
5
5
  **License for Contributions (on and after April 15, 2021)**
6
6
 
package/README.md CHANGED
@@ -224,4 +224,10 @@ _Returns_
224
224
 
225
225
  <!-- END TOKEN(Autogenerated API docs) -->
226
226
 
227
- <br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
227
+ ## Contributing to this package
228
+
229
+ This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
230
+
231
+ To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
232
+
233
+ <br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
@@ -50,7 +50,18 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
50
50
  /**
51
51
  * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
52
52
  *
53
- * Merges locale data into the Tannin instance by domain. Accepts data in a
53
+ * Merges locale data into the Tannin instance by domain. Note that this
54
+ * function will overwrite the domain configuration. Accepts data in a
55
+ * Jed-formatted JSON object shape.
56
+ *
57
+ * @see http://messageformat.github.io/Jed/
58
+ */
59
+
60
+ /**
61
+ * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
62
+ *
63
+ * Merges locale data into the Tannin instance by domain. Note that this
64
+ * function will also merge the domain configuration. Accepts data in a
54
65
  * Jed-formatted JSON object shape.
55
66
  *
56
67
  * @see http://messageformat.github.io/Jed/
@@ -138,7 +149,11 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
138
149
  *
139
150
  * @typedef I18n
140
151
  * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.
141
- * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Accepts data in a
152
+ * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this
153
+ * function will overwrite the domain configuration. Accepts data in a
154
+ * Jed-formatted JSON object shape.
155
+ * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this
156
+ * function will also merge the domain configuration. Accepts data in a
142
157
  * Jed-formatted JSON object shape.
143
158
  * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified
144
159
  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
@@ -190,23 +205,30 @@ const createI18n = (initialData, initialDomain, hooks) => {
190
205
  /** @type {GetLocaleData} */
191
206
 
192
207
 
193
- const getLocaleData = (domain = 'default') => tannin.data[domain];
208
+ const getLocaleData = function () {
209
+ let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
210
+ return tannin.data[domain];
211
+ };
194
212
  /**
195
213
  * @param {LocaleData} [data]
196
214
  * @param {string} [domain]
197
215
  */
198
216
 
199
217
 
200
- const doSetLocaleData = (data, domain = 'default') => {
201
- tannin.data[domain] = { ...DEFAULT_LOCALE_DATA,
202
- ...tannin.data[domain],
218
+ const doSetLocaleData = function (data) {
219
+ var _tannin$data$domain;
220
+
221
+ let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
222
+ tannin.data[domain] = { ...tannin.data[domain],
203
223
  ...data
204
224
  }; // Populate default domain configuration (supported locale date which omits
205
225
  // a plural forms expression).
206
226
 
207
227
  tannin.data[domain][''] = { ...DEFAULT_LOCALE_DATA[''],
208
- ...tannin.data[domain]['']
209
- };
228
+ ...((_tannin$data$domain = tannin.data[domain]) === null || _tannin$data$domain === void 0 ? void 0 : _tannin$data$domain[''])
229
+ }; // Clean up cached plural forms functions cache as it might be updated.
230
+
231
+ delete tannin.pluralForms[domain];
210
232
  };
211
233
  /** @type {SetLocaleData} */
212
234
 
@@ -215,6 +237,26 @@ const createI18n = (initialData, initialDomain, hooks) => {
215
237
  doSetLocaleData(data, domain);
216
238
  notifyListeners();
217
239
  };
240
+ /** @type {AddLocaleData} */
241
+
242
+
243
+ const addLocaleData = function (data) {
244
+ var _tannin$data$domain2;
245
+
246
+ let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
247
+ tannin.data[domain] = { ...tannin.data[domain],
248
+ ...data,
249
+ // Populate default domain configuration (supported locale date which omits
250
+ // a plural forms expression).
251
+ '': { ...DEFAULT_LOCALE_DATA[''],
252
+ ...((_tannin$data$domain2 = tannin.data[domain]) === null || _tannin$data$domain2 === void 0 ? void 0 : _tannin$data$domain2['']),
253
+ ...(data === null || data === void 0 ? void 0 : data[''])
254
+ }
255
+ }; // Clean up cached plural forms functions cache as it might be updated.
256
+
257
+ delete tannin.pluralForms[domain];
258
+ notifyListeners();
259
+ };
218
260
  /** @type {ResetLocaleData} */
219
261
 
220
262
 
@@ -242,7 +284,13 @@ const createI18n = (initialData, initialDomain, hooks) => {
242
284
  */
243
285
 
244
286
 
245
- const dcnpgettext = (domain = 'default', context, single, plural, number) => {
287
+ const dcnpgettext = function () {
288
+ let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
289
+ let context = arguments.length > 1 ? arguments[1] : undefined;
290
+ let single = arguments.length > 2 ? arguments[2] : undefined;
291
+ let plural = arguments.length > 3 ? arguments[3] : undefined;
292
+ let number = arguments.length > 4 ? arguments[4] : undefined;
293
+
246
294
  if (!tannin.data[domain]) {
247
295
  // use `doSetLocaleData` to set silently, without notifying listeners
248
296
  doSetLocaleData(undefined, domain);
@@ -253,7 +301,10 @@ const createI18n = (initialData, initialDomain, hooks) => {
253
301
  /** @type {GetFilterDomain} */
254
302
 
255
303
 
256
- const getFilterDomain = (domain = 'default') => domain;
304
+ const getFilterDomain = function () {
305
+ let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
306
+ return domain;
307
+ };
257
308
  /** @type {__} */
258
309
 
259
310
 
@@ -440,6 +491,7 @@ const createI18n = (initialData, initialDomain, hooks) => {
440
491
  return {
441
492
  getLocaleData,
442
493
  setLocaleData,
494
+ addLocaleData,
443
495
  resetLocaleData,
444
496
  subscribe,
445
497
  __,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/i18n/src/create-i18n.js"],"names":["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","setLocaleData","resetLocaleData","pluralForms","dcnpgettext","context","single","plural","number","undefined","getFilterDomain","__","text","translation","applyFilters","_x","_n","_nx","isRTL","hasTranslation","key","result","onHookAddedOrRemoved","hookName","test","addAction"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,mBAAmB,GAAG;AAC3B,MAAI;AACH;AACAC,IAAAA,YAAY,CAAEC,CAAF,EAAM;AACjB,aAAOA,CAAC,KAAK,CAAN,GAAU,CAAV,GAAc,CAArB;AACA;;AAJE;AADuB,CAA5B;AASA;AACA;AACA;AACA;;AACA,MAAMC,gBAAgB,GAAG,yCAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;;AAEA;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,GAAG,CAAEC,WAAF,EAAeC,aAAf,EAA8BC,KAA9B,KAAyC;AAClE;AACD;AACA;AACA;AACA;AACC,QAAMC,MAAM,GAAG,IAAIC,eAAJ,CAAY,EAAZ,CAAf;AAEA,QAAMC,SAAS,GAAG,IAAIC,GAAJ,EAAlB;;AAEA,QAAMC,eAAe,GAAG,MAAM;AAC7BF,IAAAA,SAAS,CAACG,OAAV,CAAqBC,QAAF,IAAgBA,QAAQ,EAA3C;AACA,GAFD;AAIA;AACD;AACA;AACA;AACA;AACA;;;AACC,QAAMC,SAAS,GAAKC,QAAF,IAAgB;AACjCN,IAAAA,SAAS,CAACO,GAAV,CAAeD,QAAf;AACA,WAAO,MAAMN,SAAS,CAACQ,MAAV,CAAkBF,QAAlB,CAAb;AACA,GAHD;AAKA;;;AACA,QAAMG,aAAa,GAAG,CAAEC,MAAM,GAAG,SAAX,KAA0BZ,MAAM,CAACa,IAAP,CAAaD,MAAb,CAAhD;AAEA;AACD;AACA;AACA;;;AACC,QAAME,eAAe,GAAG,CAAED,IAAF,EAAQD,MAAM,GAAG,SAAjB,KAAgC;AACvDZ,IAAAA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AACxCjC,QAAAA,eAAe;AACf;AACD,KAJD;;AAMAL,IAAAA,KAAK,CAACwC,SAAN,CAAiB,WAAjB,EAA8B,WAA9B,EAA2CH,oBAA3C;AACArC,IAAAA,KAAK,CAACwC,SAAN,CAAiB,aAAjB,EAAgC,WAAhC,EAA6CH,oBAA7C;AACA;;AAED,SAAO;AACNzB,IAAAA,aADM;AAENI,IAAAA,aAFM;AAGNC,IAAAA,eAHM;AAINT,IAAAA,SAJM;AAKNkB,IAAAA,EALM;AAMNI,IAAAA,EANM;AAONC,IAAAA,EAPM;AAQNC,IAAAA,GARM;AASNC,IAAAA,KATM;AAUNC,IAAAA;AAVM,GAAP;AAYA,CAvUM","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. 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. 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...DEFAULT_LOCALE_DATA,\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\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 {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\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/i18n/src/create-i18n.js"],"names":["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"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,mBAAmB,GAAG;AAC3B,MAAI;AACH;AACAC,IAAAA,YAAY,CAAEC,CAAF,EAAM;AACjB,aAAOA,CAAC,KAAK,CAAN,GAAU,CAAV,GAAc,CAArB;AACA;;AAJE;AADuB,CAA5B;AASA;AACA;AACA;AACA;;AACA,MAAMC,gBAAgB,GAAG,yCAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;A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MALgB,CADlB;AAUAwB,MAAAA,MAAM;AAAG;;AACR;AAAiBrC,MAAAA,KAAK,CAAC8B,YAAN,CAChB,0BAA0BJ,eAAe,CAAEb,MAAF,CADzB,EAEhBwB,MAFgB,EAGhBf,MAHgB,EAIhBD,OAJgB,EAKhBR,MALgB,CADlB;AASA;;AACD,WAAOwB,MAAP;AACA,GAjCD;;AAmCA,MAAKvC,WAAL,EAAmB;AAClBmB,IAAAA,aAAa,CAAEnB,WAAF,EAAeC,aAAf,CAAb;AACA;;AAED,MAAKC,KAAL,EAAa;AACZ;AACF;AACA;AACE,UAAMsC,oBAAoB,GAAKC,QAAF,IAAgB;AAC5C,UAAK3C,gBAAgB,CAAC4C,IAAjB,CAAuBD,QAAvB,CAAL,EAAyC;AACxClC,QAAAA,eAAe;AACf;AACD,KAJD;;AAMAL,IAAAA,KAAK,CAACyC,SAAN,CAAiB,WAAjB,EAA8B,WAA9B,EAA2CH,oBAA3C;AACAtC,IAAAA,KAAK,CAACyC,SAAN,CAAiB,aAAjB,EAAgC,WAAhC,EAA6CH,oBAA7C;AACA;;AAED,SAAO;AACN1B,IAAAA,aADM;AAENK,IAAAA,aAFM;AAGNC,IAAAA,aAHM;AAINC,IAAAA,eAJM;AAKNX,IAAAA,SALM;AAMNmB,IAAAA,EANM;AAONI,IAAAA,EAPM;AAQNC,IAAAA,EARM;AASNC,IAAAA,GATM;AAUNC,IAAAA,KAVM;AAWNC,IAAAA;AAXM,GAAP;AAaA,CA9VM","sourcesContent":["/**\n * External dependencies\n */\nimport Tannin from 'tannin';\n\n/**\n * @typedef {Record<string,any>} LocaleData\n */\n\n/**\n * Default locale data to use for Tannin domain when not otherwise provided.\n * Assumes an English plural forms expression.\n *\n * @type {LocaleData}\n */\nconst DEFAULT_LOCALE_DATA = {\n\t'': {\n\t\t/** @param {number} n */\n\t\tplural_forms( n ) {\n\t\t\treturn n === 1 ? 0 : 1;\n\t\t},\n\t},\n};\n\n/*\n * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,\n * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.\n */\nconst I18N_HOOK_REGEXP = /^i18n\\.(n?gettext|has_translation)(_|$)/;\n\n/**\n * @typedef {(domain?: string) => LocaleData} GetLocaleData\n *\n * Returns locale data by domain in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData\n *\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/** @typedef {() => void} SubscribeCallback */\n/** @typedef {() => void} UnsubscribeCallback */\n/**\n * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe\n *\n * Subscribes to changes of locale data\n */\n/**\n * @typedef {(domain?: string) => string} GetFilterDomain\n * Retrieve the domain to use when calling domain-specific filters.\n */\n/**\n * @typedef {(text: string, domain?: string) => string} __\n *\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n */\n/**\n * @typedef {(text: string, context: string, domain?: string) => string} _x\n *\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n */\n/**\n * @typedef {() => boolean} IsRtl\n *\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n */\n/**\n * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation\n *\n * Check if there is a translation for a given string in singular form.\n */\n/** @typedef {import('@wordpress/hooks').Hooks} Hooks */\n\n/**\n * An i18n instance\n *\n * @typedef I18n\n * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.\n * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n * @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.\n * @property {__} __ Retrieve the translation of text.\n * @property {_x} _x Retrieve translated string with gettext context.\n * @property {_n} _n Translates and retrieves the singular or plural form based on the supplied\n * number.\n * @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n * @property {IsRtl} isRTL Check if current locale is RTL.\n * @property {HasTranslation} hasTranslation Check if there is a translation for a given string.\n */\n\n/**\n * Create an i18n instance\n *\n * @param {LocaleData} [initialData] Locale data configuration.\n * @param {string} [initialDomain] Domain for which configuration applies.\n * @param {Hooks} [hooks] Hooks implementation.\n *\n * @return {I18n} I18n instance.\n */\nexport const createI18n = ( initialData, initialDomain, hooks ) => {\n\t/**\n\t * The underlying instance of Tannin to which exported functions interface.\n\t *\n\t * @type {Tannin}\n\t */\n\tconst tannin = new Tannin( {} );\n\n\tconst listeners = new Set();\n\n\tconst notifyListeners = () => {\n\t\tlisteners.forEach( ( listener ) => listener() );\n\t};\n\n\t/**\n\t * Subscribe to changes of locale data.\n\t *\n\t * @param {SubscribeCallback} callback Subscription callback.\n\t * @return {UnsubscribeCallback} Unsubscribe callback.\n\t */\n\tconst subscribe = ( callback ) => {\n\t\tlisteners.add( callback );\n\t\treturn () => listeners.delete( callback );\n\t};\n\n\t/** @type {GetLocaleData} */\n\tconst getLocaleData = ( domain = 'default' ) => tannin.data[ domain ];\n\n\t/**\n\t * @param {LocaleData} [data]\n\t * @param {string} [domain]\n\t */\n\tconst doSetLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t};\n\n\t\t// Populate default domain configuration (supported locale date which omits\n\t\t// a plural forms expression).\n\t\ttannin.data[ domain ][ '' ] = {\n\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\t};\n\n\t/** @type {SetLocaleData} */\n\tconst setLocaleData = ( data, domain ) => {\n\t\tdoSetLocaleData( data, domain );\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {AddLocaleData} */\n\tconst addLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t\t// Populate default domain configuration (supported locale date which omits\n\t\t\t// a plural forms expression).\n\t\t\t'': {\n\t\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t\t\t...data?.[ '' ],\n\t\t\t},\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {ResetLocaleData} */\n\tconst resetLocaleData = ( data, domain ) => {\n\t\t// Reset all current Tannin locale data.\n\t\ttannin.data = {};\n\n\t\t// Reset cached plural forms functions cache.\n\t\ttannin.pluralForms = {};\n\n\t\tsetLocaleData( data, domain );\n\t};\n\n\t/**\n\t * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not\n\t * otherwise previously assigned.\n\t *\n\t * @param {string|undefined} domain Domain to retrieve the translated text.\n\t * @param {string|undefined} context Context information for the translators.\n\t * @param {string} single Text to translate if non-plural. Used as\n\t * fallback return value on a caught error.\n\t * @param {string} [plural] The text to be used if the number is\n\t * plural.\n\t * @param {number} [number] The number to compare against to use\n\t * either the singular or plural form.\n\t *\n\t * @return {string} The translated string.\n\t */\n\tconst dcnpgettext = (\n\t\tdomain = 'default',\n\t\tcontext,\n\t\tsingle,\n\t\tplural,\n\t\tnumber\n\t) => {\n\t\tif ( ! tannin.data[ domain ] ) {\n\t\t\t// use `doSetLocaleData` to set silently, without notifying listeners\n\t\t\tdoSetLocaleData( undefined, domain );\n\t\t}\n\n\t\treturn tannin.dcnpgettext( domain, context, single, plural, number );\n\t};\n\n\t/** @type {GetFilterDomain} */\n\tconst getFilterDomain = ( domain = 'default' ) => domain;\n\n\t/** @type {__} */\n\tconst __ = ( text, domain ) => {\n\t\tlet translation = dcnpgettext( domain, undefined, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_x} */\n\tconst _x = ( text, context, domain ) => {\n\t\tlet translation = dcnpgettext( domain, context, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation based on context information.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_n} */\n\tconst _n = ( single, plural, number, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tundefined,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_nx} */\n\tconst _nx = ( single, plural, number, context, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tcontext,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string with gettext context.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {IsRtl} */\n\tconst isRTL = () => {\n\t\treturn 'rtl' === _x( 'ltr', 'text direction' );\n\t};\n\n\t/** @type {HasTranslation} */\n\tconst hasTranslation = ( single, context, domain ) => {\n\t\tconst key = context ? context + '\\u0004' + single : single;\n\t\tlet result = !! tannin.data?.[ domain ?? 'default' ]?.[ key ];\n\t\tif ( hooks ) {\n\t\t\t/**\n\t\t\t * Filters the presence of a translation in the locale data.\n\t\t\t *\n\t\t\t * @param {boolean} hasTranslation Whether the translation is present or not..\n\t\t\t * @param {string} single The singular form of the translated text (used as key in locale data)\n\t\t\t * @param {string} context Context information for the translators.\n\t\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t\t */\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation',\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation_' + getFilterDomain( domain ),\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t};\n\n\tif ( initialData ) {\n\t\tsetLocaleData( initialData, initialDomain );\n\t}\n\n\tif ( hooks ) {\n\t\t/**\n\t\t * @param {string} hookName\n\t\t */\n\t\tconst onHookAddedOrRemoved = ( hookName ) => {\n\t\t\tif ( I18N_HOOK_REGEXP.test( hookName ) ) {\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t};\n\n\t\thooks.addAction( 'hookAdded', 'core/i18n', onHookAddedOrRemoved );\n\t\thooks.addAction( 'hookRemoved', 'core/i18n', onHookAddedOrRemoved );\n\t}\n\n\treturn {\n\t\tgetLocaleData,\n\t\tsetLocaleData,\n\t\taddLocaleData,\n\t\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.hasTranslation = exports.isRTL = exports._nx = exports._n = exports._x = exports.__ = exports.subscribe = exports.resetLocaleData = exports.setLocaleData = exports.getLocaleData = exports.default = void 0;
6
+ exports.subscribe = exports.setLocaleData = exports.resetLocaleData = exports.isRTL = exports.hasTranslation = exports.getLocaleData = exports.default = exports._x = exports._nx = exports._n = exports.__ = void 0;
7
7
 
8
8
  var _createI18n = require("./create-i18n");
9
9
 
package/build/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -19,76 +17,76 @@ var _exportNames = {
19
17
  isRTL: true,
20
18
  hasTranslation: true
21
19
  };
22
- Object.defineProperty(exports, "sprintf", {
20
+ Object.defineProperty(exports, "__", {
23
21
  enumerable: true,
24
22
  get: function () {
25
- return _sprintf.sprintf;
23
+ return _defaultI18n.__;
26
24
  }
27
25
  });
28
- Object.defineProperty(exports, "defaultI18n", {
26
+ Object.defineProperty(exports, "_n", {
29
27
  enumerable: true,
30
28
  get: function () {
31
- return _defaultI18n.default;
29
+ return _defaultI18n._n;
32
30
  }
33
31
  });
34
- Object.defineProperty(exports, "setLocaleData", {
32
+ Object.defineProperty(exports, "_nx", {
35
33
  enumerable: true,
36
34
  get: function () {
37
- return _defaultI18n.setLocaleData;
35
+ return _defaultI18n._nx;
38
36
  }
39
37
  });
40
- Object.defineProperty(exports, "resetLocaleData", {
38
+ Object.defineProperty(exports, "_x", {
41
39
  enumerable: true,
42
40
  get: function () {
43
- return _defaultI18n.resetLocaleData;
41
+ return _defaultI18n._x;
44
42
  }
45
43
  });
46
- Object.defineProperty(exports, "getLocaleData", {
44
+ Object.defineProperty(exports, "defaultI18n", {
47
45
  enumerable: true,
48
46
  get: function () {
49
- return _defaultI18n.getLocaleData;
47
+ return _defaultI18n.default;
50
48
  }
51
49
  });
52
- Object.defineProperty(exports, "subscribe", {
50
+ Object.defineProperty(exports, "getLocaleData", {
53
51
  enumerable: true,
54
52
  get: function () {
55
- return _defaultI18n.subscribe;
53
+ return _defaultI18n.getLocaleData;
56
54
  }
57
55
  });
58
- Object.defineProperty(exports, "__", {
56
+ Object.defineProperty(exports, "hasTranslation", {
59
57
  enumerable: true,
60
58
  get: function () {
61
- return _defaultI18n.__;
59
+ return _defaultI18n.hasTranslation;
62
60
  }
63
61
  });
64
- Object.defineProperty(exports, "_x", {
62
+ Object.defineProperty(exports, "isRTL", {
65
63
  enumerable: true,
66
64
  get: function () {
67
- return _defaultI18n._x;
65
+ return _defaultI18n.isRTL;
68
66
  }
69
67
  });
70
- Object.defineProperty(exports, "_n", {
68
+ Object.defineProperty(exports, "resetLocaleData", {
71
69
  enumerable: true,
72
70
  get: function () {
73
- return _defaultI18n._n;
71
+ return _defaultI18n.resetLocaleData;
74
72
  }
75
73
  });
76
- Object.defineProperty(exports, "_nx", {
74
+ Object.defineProperty(exports, "setLocaleData", {
77
75
  enumerable: true,
78
76
  get: function () {
79
- return _defaultI18n._nx;
77
+ return _defaultI18n.setLocaleData;
80
78
  }
81
79
  });
82
- Object.defineProperty(exports, "isRTL", {
80
+ Object.defineProperty(exports, "sprintf", {
83
81
  enumerable: true,
84
82
  get: function () {
85
- return _defaultI18n.isRTL;
83
+ return _sprintf.sprintf;
86
84
  }
87
85
  });
88
- Object.defineProperty(exports, "hasTranslation", {
86
+ Object.defineProperty(exports, "subscribe", {
89
87
  enumerable: true,
90
88
  get: function () {
91
- return _defaultI18n.hasTranslation;
89
+ return _defaultI18n.subscribe;
92
90
  }
93
91
  });
94
92
 
@@ -109,4 +107,8 @@ Object.keys(_createI18n).forEach(function (key) {
109
107
  });
110
108
 
111
109
  var _defaultI18n = _interopRequireWildcard(require("./default-i18n"));
110
+
111
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
112
+
113
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
112
114
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/i18n/src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA","sourcesContent":["export { sprintf } from './sprintf';\nexport * from './create-i18n';\nexport {\n\tdefault as defaultI18n,\n\tsetLocaleData,\n\tresetLocaleData,\n\tgetLocaleData,\n\tsubscribe,\n\t__,\n\t_x,\n\t_n,\n\t_nx,\n\tisRTL,\n\thasTranslation,\n} from './default-i18n';\n"]}
1
+ {"version":3,"sources":["@wordpress/i18n/src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA","sourcesContent":["export { sprintf } from './sprintf';\nexport * from './create-i18n';\nexport {\n\tdefault as defaultI18n,\n\tsetLocaleData,\n\tresetLocaleData,\n\tgetLocaleData,\n\tsubscribe,\n\t__,\n\t_x,\n\t_n,\n\t_nx,\n\tisRTL,\n\thasTranslation,\n} from './default-i18n';\n"]}
package/build/sprintf.js CHANGED
@@ -36,8 +36,12 @@ const logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line
36
36
  * @return {string} The formatted string.
37
37
  */
38
38
 
39
- function sprintf(format, ...args) {
39
+ function sprintf(format) {
40
40
  try {
41
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
42
+ args[_key - 1] = arguments[_key];
43
+ }
44
+
41
45
  return _sprintfJs.default.sprintf(format, ...args);
42
46
  } catch (error) {
43
47
  if (error instanceof Error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/i18n/src/sprintf.js"],"names":["logErrorOnce","console","error","sprintf","format","args","sprintfjs","Error","toString"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,qBAASC,OAAO,CAACC,KAAjB,CAArB,C,CAA+C;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,OAAT,CAAkBC,MAAlB,EAA0B,GAAGC,IAA7B,EAAoC;AAC1C,MAAI;AACH,WAAOC,mBAAUH,OAAV,CAAmBC,MAAnB,EAA2B,GAAGC,IAA9B,CAAP;AACA,GAFD,CAEE,OAAQH,KAAR,EAAgB;AACjB,QAAKA,KAAK,YAAYK,KAAtB,EAA8B;AAC7BP,MAAAA,YAAY,CAAE,wBAAwBE,KAAK,CAACM,QAAN,EAA1B,CAAZ;AACA;;AACD,WAAOJ,MAAP;AACA;AACD","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"]}
1
+ {"version":3,"sources":["@wordpress/i18n/src/sprintf.js"],"names":["logErrorOnce","console","error","sprintf","format","args","sprintfjs","Error","toString"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,qBAASC,OAAO,CAACC,KAAjB,CAArB,C,CAA+C;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASC,OAAT,CAAkBC,MAAlB,EAAoC;AAC1C,MAAI;AAAA,sCAD+BC,IAC/B;AAD+BA,MAAAA,IAC/B;AAAA;;AACH,WAAOC,mBAAUH,OAAV,CAAmBC,MAAnB,EAA2B,GAAGC,IAA9B,CAAP;AACA,GAFD,CAEE,OAAQH,KAAR,EAAgB;AACjB,QAAKA,KAAK,YAAYK,KAAtB,EAA8B;AAC7BP,MAAAA,YAAY,CAAE,wBAAwBE,KAAK,CAACM,QAAN,EAA1B,CAAZ;AACA;;AACD,WAAOJ,MAAP;AACA;AACD","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"]}
@@ -40,7 +40,18 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
40
40
  /**
41
41
  * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
42
42
  *
43
- * Merges locale data into the Tannin instance by domain. Accepts data in a
43
+ * Merges locale data into the Tannin instance by domain. Note that this
44
+ * function will overwrite the domain configuration. Accepts data in a
45
+ * Jed-formatted JSON object shape.
46
+ *
47
+ * @see http://messageformat.github.io/Jed/
48
+ */
49
+
50
+ /**
51
+ * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
52
+ *
53
+ * Merges locale data into the Tannin instance by domain. Note that this
54
+ * function will also merge the domain configuration. Accepts data in a
44
55
  * Jed-formatted JSON object shape.
45
56
  *
46
57
  * @see http://messageformat.github.io/Jed/
@@ -128,7 +139,11 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
128
139
  *
129
140
  * @typedef I18n
130
141
  * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.
131
- * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Accepts data in a
142
+ * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this
143
+ * function will overwrite the domain configuration. Accepts data in a
144
+ * Jed-formatted JSON object shape.
145
+ * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this
146
+ * function will also merge the domain configuration. Accepts data in a
132
147
  * Jed-formatted JSON object shape.
133
148
  * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified
134
149
  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
@@ -180,23 +195,30 @@ export const createI18n = (initialData, initialDomain, hooks) => {
180
195
  /** @type {GetLocaleData} */
181
196
 
182
197
 
183
- const getLocaleData = (domain = 'default') => tannin.data[domain];
198
+ const getLocaleData = function () {
199
+ let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
200
+ return tannin.data[domain];
201
+ };
184
202
  /**
185
203
  * @param {LocaleData} [data]
186
204
  * @param {string} [domain]
187
205
  */
188
206
 
189
207
 
190
- const doSetLocaleData = (data, domain = 'default') => {
191
- tannin.data[domain] = { ...DEFAULT_LOCALE_DATA,
192
- ...tannin.data[domain],
208
+ const doSetLocaleData = function (data) {
209
+ var _tannin$data$domain;
210
+
211
+ let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
212
+ tannin.data[domain] = { ...tannin.data[domain],
193
213
  ...data
194
214
  }; // Populate default domain configuration (supported locale date which omits
195
215
  // a plural forms expression).
196
216
 
197
217
  tannin.data[domain][''] = { ...DEFAULT_LOCALE_DATA[''],
198
- ...tannin.data[domain]['']
199
- };
218
+ ...((_tannin$data$domain = tannin.data[domain]) === null || _tannin$data$domain === void 0 ? void 0 : _tannin$data$domain[''])
219
+ }; // Clean up cached plural forms functions cache as it might be updated.
220
+
221
+ delete tannin.pluralForms[domain];
200
222
  };
201
223
  /** @type {SetLocaleData} */
202
224
 
@@ -205,6 +227,26 @@ export const createI18n = (initialData, initialDomain, hooks) => {
205
227
  doSetLocaleData(data, domain);
206
228
  notifyListeners();
207
229
  };
230
+ /** @type {AddLocaleData} */
231
+
232
+
233
+ const addLocaleData = function (data) {
234
+ var _tannin$data$domain2;
235
+
236
+ let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
237
+ tannin.data[domain] = { ...tannin.data[domain],
238
+ ...data,
239
+ // Populate default domain configuration (supported locale date which omits
240
+ // a plural forms expression).
241
+ '': { ...DEFAULT_LOCALE_DATA[''],
242
+ ...((_tannin$data$domain2 = tannin.data[domain]) === null || _tannin$data$domain2 === void 0 ? void 0 : _tannin$data$domain2['']),
243
+ ...(data === null || data === void 0 ? void 0 : data[''])
244
+ }
245
+ }; // Clean up cached plural forms functions cache as it might be updated.
246
+
247
+ delete tannin.pluralForms[domain];
248
+ notifyListeners();
249
+ };
208
250
  /** @type {ResetLocaleData} */
209
251
 
210
252
 
@@ -232,7 +274,13 @@ export const createI18n = (initialData, initialDomain, hooks) => {
232
274
  */
233
275
 
234
276
 
235
- const dcnpgettext = (domain = 'default', context, single, plural, number) => {
277
+ const dcnpgettext = function () {
278
+ let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
279
+ let context = arguments.length > 1 ? arguments[1] : undefined;
280
+ let single = arguments.length > 2 ? arguments[2] : undefined;
281
+ let plural = arguments.length > 3 ? arguments[3] : undefined;
282
+ let number = arguments.length > 4 ? arguments[4] : undefined;
283
+
236
284
  if (!tannin.data[domain]) {
237
285
  // use `doSetLocaleData` to set silently, without notifying listeners
238
286
  doSetLocaleData(undefined, domain);
@@ -243,7 +291,10 @@ export const createI18n = (initialData, initialDomain, hooks) => {
243
291
  /** @type {GetFilterDomain} */
244
292
 
245
293
 
246
- const getFilterDomain = (domain = 'default') => domain;
294
+ const getFilterDomain = function () {
295
+ let domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
296
+ return domain;
297
+ };
247
298
  /** @type {__} */
248
299
 
249
300
 
@@ -430,6 +481,7 @@ export const createI18n = (initialData, initialDomain, hooks) => {
430
481
  return {
431
482
  getLocaleData,
432
483
  setLocaleData,
484
+ addLocaleData,
433
485
  resetLocaleData,
434
486
  subscribe,
435
487
  __,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/i18n/src/create-i18n.js"],"names":["Tannin","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","listeners","Set","notifyListeners","forEach","listener","subscribe","callback","add","delete","getLocaleData","domain","data","doSetLocaleData","setLocaleData","resetLocaleData","pluralForms","dcnpgettext","context","single","plural","number","undefined","getFilterDomain","__","text","translation","applyFilters","_x","_n","_nx","isRTL","hasTranslation","key","result","onHookAddedOrRemoved","hookName","test","addAction"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,QAAnB;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAG;AAC3B,MAAI;AACH;AACAC,IAAAA,YAAY,CAAEC,CAAF,EAAM;AACjB,aAAOA,CAAC,KAAK,CAAN,GAAU,CAAV,GAAc,CAArB;AACA;;AAJE;AADuB,CAA5B;AASA;AACA;AACA;AACA;;AACA,MAAMC,gBAAgB,GAAG,yCAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;A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A,KAAK,CAACuC,SAAN,CAAiB,aAAjB,EAAgC,WAAhC,EAA6CH,oBAA7C;AACA;;AAED,SAAO;AACNzB,IAAAA,aADM;AAENI,IAAAA,aAFM;AAGNC,IAAAA,eAHM;AAINT,IAAAA,SAJM;AAKNkB,IAAAA,EALM;AAMNI,IAAAA,EANM;AAONC,IAAAA,EAPM;AAQNC,IAAAA,GARM;AASNC,IAAAA,KATM;AAUNC,IAAAA;AAVM,GAAP;AAYA,CAvUM","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. 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. 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...DEFAULT_LOCALE_DATA,\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\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 {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\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/i18n/src/create-i18n.js"],"names":["Tannin","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","listeners","Set","notifyListeners","forEach","listener","subscribe","callback","add","delete","getLocaleData","domain","data","doSetLocaleData","pluralForms","setLocaleData","addLocaleData","resetLocaleData","dcnpgettext","context","single","plural","number","undefined","getFilterDomain","__","text","translation","applyFilters","_x","_n","_nx","isRTL","hasTranslation","key","result","onHookAddedOrRemoved","hookName","test","addAction"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAP,MAAmB,QAAnB;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAG;AAC3B,MAAI;AACH;AACAC,IAAAA,YAAY,CAAEC,CAAF,EAAM;AACjB,aAAOA,CAAC,KAAK,CAAN,GAAU,CAAV,GAAc,CAArB;AACA;;AAJE;AADuB,CAA5B;AASA;AACA;AACA;AACA;;AACA,MAAMC,gBAAgB,GAAG,yCAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;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CAAEb,MAAF,CADzB,EAEhBwB,MAFgB,EAGhBf,MAHgB,EAIhBD,OAJgB,EAKhBR,MALgB,CADlB;AASA;;AACD,WAAOwB,MAAP;AACA,GAjCD;;AAmCA,MAAKtC,WAAL,EAAmB;AAClBkB,IAAAA,aAAa,CAAElB,WAAF,EAAeC,aAAf,CAAb;AACA;;AAED,MAAKC,KAAL,EAAa;AACZ;AACF;AACA;AACE,UAAMqC,oBAAoB,GAAKC,QAAF,IAAgB;AAC5C,UAAK1C,gBAAgB,CAAC2C,IAAjB,CAAuBD,QAAvB,CAAL,EAAyC;AACxClC,QAAAA,eAAe;AACf;AACD,KAJD;;AAMAJ,IAAAA,KAAK,CAACwC,SAAN,CAAiB,WAAjB,EAA8B,WAA9B,EAA2CH,oBAA3C;AACArC,IAAAA,KAAK,CAACwC,SAAN,CAAiB,aAAjB,EAAgC,WAAhC,EAA6CH,oBAA7C;AACA;;AAED,SAAO;AACN1B,IAAAA,aADM;AAENK,IAAAA,aAFM;AAGNC,IAAAA,aAHM;AAINC,IAAAA,eAJM;AAKNX,IAAAA,SALM;AAMNmB,IAAAA,EANM;AAONI,IAAAA,EAPM;AAQNC,IAAAA,EARM;AASNC,IAAAA,GATM;AAUNC,IAAAA,KAVM;AAWNC,IAAAA;AAXM,GAAP;AAaA,CA9VM","sourcesContent":["/**\n * External dependencies\n */\nimport Tannin from 'tannin';\n\n/**\n * @typedef {Record<string,any>} LocaleData\n */\n\n/**\n * Default locale data to use for Tannin domain when not otherwise provided.\n * Assumes an English plural forms expression.\n *\n * @type {LocaleData}\n */\nconst DEFAULT_LOCALE_DATA = {\n\t'': {\n\t\t/** @param {number} n */\n\t\tplural_forms( n ) {\n\t\t\treturn n === 1 ? 0 : 1;\n\t\t},\n\t},\n};\n\n/*\n * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,\n * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.\n */\nconst I18N_HOOK_REGEXP = /^i18n\\.(n?gettext|has_translation)(_|$)/;\n\n/**\n * @typedef {(domain?: string) => LocaleData} GetLocaleData\n *\n * Returns locale data by domain in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData\n *\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/** @typedef {() => void} SubscribeCallback */\n/** @typedef {() => void} UnsubscribeCallback */\n/**\n * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe\n *\n * Subscribes to changes of locale data\n */\n/**\n * @typedef {(domain?: string) => string} GetFilterDomain\n * Retrieve the domain to use when calling domain-specific filters.\n */\n/**\n * @typedef {(text: string, domain?: string) => string} __\n *\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n */\n/**\n * @typedef {(text: string, context: string, domain?: string) => string} _x\n *\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n */\n/**\n * @typedef {() => boolean} IsRtl\n *\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n */\n/**\n * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation\n *\n * Check if there is a translation for a given string in singular form.\n */\n/** @typedef {import('@wordpress/hooks').Hooks} Hooks */\n\n/**\n * An i18n instance\n *\n * @typedef I18n\n * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.\n * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n * @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.\n * @property {__} __ Retrieve the translation of text.\n * @property {_x} _x Retrieve translated string with gettext context.\n * @property {_n} _n Translates and retrieves the singular or plural form based on the supplied\n * number.\n * @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n * @property {IsRtl} isRTL Check if current locale is RTL.\n * @property {HasTranslation} hasTranslation Check if there is a translation for a given string.\n */\n\n/**\n * Create an i18n instance\n *\n * @param {LocaleData} [initialData] Locale data configuration.\n * @param {string} [initialDomain] Domain for which configuration applies.\n * @param {Hooks} [hooks] Hooks implementation.\n *\n * @return {I18n} I18n instance.\n */\nexport const createI18n = ( initialData, initialDomain, hooks ) => {\n\t/**\n\t * The underlying instance of Tannin to which exported functions interface.\n\t *\n\t * @type {Tannin}\n\t */\n\tconst tannin = new Tannin( {} );\n\n\tconst listeners = new Set();\n\n\tconst notifyListeners = () => {\n\t\tlisteners.forEach( ( listener ) => listener() );\n\t};\n\n\t/**\n\t * Subscribe to changes of locale data.\n\t *\n\t * @param {SubscribeCallback} callback Subscription callback.\n\t * @return {UnsubscribeCallback} Unsubscribe callback.\n\t */\n\tconst subscribe = ( callback ) => {\n\t\tlisteners.add( callback );\n\t\treturn () => listeners.delete( callback );\n\t};\n\n\t/** @type {GetLocaleData} */\n\tconst getLocaleData = ( domain = 'default' ) => tannin.data[ domain ];\n\n\t/**\n\t * @param {LocaleData} [data]\n\t * @param {string} [domain]\n\t */\n\tconst doSetLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t};\n\n\t\t// Populate default domain configuration (supported locale date which omits\n\t\t// a plural forms expression).\n\t\ttannin.data[ domain ][ '' ] = {\n\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\t};\n\n\t/** @type {SetLocaleData} */\n\tconst setLocaleData = ( data, domain ) => {\n\t\tdoSetLocaleData( data, domain );\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {AddLocaleData} */\n\tconst addLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t\t// Populate default domain configuration (supported locale date which omits\n\t\t\t// a plural forms expression).\n\t\t\t'': {\n\t\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t\t\t...data?.[ '' ],\n\t\t\t},\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {ResetLocaleData} */\n\tconst resetLocaleData = ( data, domain ) => {\n\t\t// Reset all current Tannin locale data.\n\t\ttannin.data = {};\n\n\t\t// Reset cached plural forms functions cache.\n\t\ttannin.pluralForms = {};\n\n\t\tsetLocaleData( data, domain );\n\t};\n\n\t/**\n\t * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not\n\t * otherwise previously assigned.\n\t *\n\t * @param {string|undefined} domain Domain to retrieve the translated text.\n\t * @param {string|undefined} context Context information for the translators.\n\t * @param {string} single Text to translate if non-plural. Used as\n\t * fallback return value on a caught error.\n\t * @param {string} [plural] The text to be used if the number is\n\t * plural.\n\t * @param {number} [number] The number to compare against to use\n\t * either the singular or plural form.\n\t *\n\t * @return {string} The translated string.\n\t */\n\tconst dcnpgettext = (\n\t\tdomain = 'default',\n\t\tcontext,\n\t\tsingle,\n\t\tplural,\n\t\tnumber\n\t) => {\n\t\tif ( ! tannin.data[ domain ] ) {\n\t\t\t// use `doSetLocaleData` to set silently, without notifying listeners\n\t\t\tdoSetLocaleData( undefined, domain );\n\t\t}\n\n\t\treturn tannin.dcnpgettext( domain, context, single, plural, number );\n\t};\n\n\t/** @type {GetFilterDomain} */\n\tconst getFilterDomain = ( domain = 'default' ) => domain;\n\n\t/** @type {__} */\n\tconst __ = ( text, domain ) => {\n\t\tlet translation = dcnpgettext( domain, undefined, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_x} */\n\tconst _x = ( text, context, domain ) => {\n\t\tlet translation = dcnpgettext( domain, context, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation based on context information.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_n} */\n\tconst _n = ( single, plural, number, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tundefined,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_nx} */\n\tconst _nx = ( single, plural, number, context, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tcontext,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string with gettext context.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {IsRtl} */\n\tconst isRTL = () => {\n\t\treturn 'rtl' === _x( 'ltr', 'text direction' );\n\t};\n\n\t/** @type {HasTranslation} */\n\tconst hasTranslation = ( single, context, domain ) => {\n\t\tconst key = context ? context + '\\u0004' + single : single;\n\t\tlet result = !! tannin.data?.[ domain ?? 'default' ]?.[ key ];\n\t\tif ( hooks ) {\n\t\t\t/**\n\t\t\t * Filters the presence of a translation in the locale data.\n\t\t\t *\n\t\t\t * @param {boolean} hasTranslation Whether the translation is present or not..\n\t\t\t * @param {string} single The singular form of the translated text (used as key in locale data)\n\t\t\t * @param {string} context Context information for the translators.\n\t\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t\t */\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation',\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation_' + getFilterDomain( domain ),\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t};\n\n\tif ( initialData ) {\n\t\tsetLocaleData( initialData, initialDomain );\n\t}\n\n\tif ( hooks ) {\n\t\t/**\n\t\t * @param {string} hookName\n\t\t */\n\t\tconst onHookAddedOrRemoved = ( hookName ) => {\n\t\t\tif ( I18N_HOOK_REGEXP.test( hookName ) ) {\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t};\n\n\t\thooks.addAction( 'hookAdded', 'core/i18n', onHookAddedOrRemoved );\n\t\thooks.addAction( 'hookRemoved', 'core/i18n', onHookAddedOrRemoved );\n\t}\n\n\treturn {\n\t\tgetLocaleData,\n\t\tsetLocaleData,\n\t\taddLocaleData,\n\t\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"]}
@@ -25,8 +25,12 @@ const logErrorOnce = memoize(console.error); // eslint-disable-line no-console
25
25
  * @return {string} The formatted string.
26
26
  */
27
27
 
28
- export function sprintf(format, ...args) {
28
+ export function sprintf(format) {
29
29
  try {
30
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
31
+ args[_key - 1] = arguments[_key];
32
+ }
33
+
30
34
  return sprintfjs.sprintf(format, ...args);
31
35
  } catch (error) {
32
36
  if (error instanceof Error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/i18n/src/sprintf.js"],"names":["memoize","sprintfjs","logErrorOnce","console","error","sprintf","format","args","Error","toString"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,QAApB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAGF,OAAO,CAAEG,OAAO,CAACC,KAAV,CAA5B,C,CAA+C;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,OAAT,CAAkBC,MAAlB,EAA0B,GAAGC,IAA7B,EAAoC;AAC1C,MAAI;AACH,WAAON,SAAS,CAACI,OAAV,CAAmBC,MAAnB,EAA2B,GAAGC,IAA9B,CAAP;AACA,GAFD,CAEE,OAAQH,KAAR,EAAgB;AACjB,QAAKA,KAAK,YAAYI,KAAtB,EAA8B;AAC7BN,MAAAA,YAAY,CAAE,wBAAwBE,KAAK,CAACK,QAAN,EAA1B,CAAZ;AACA;;AACD,WAAOH,MAAP;AACA;AACD","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"]}
1
+ {"version":3,"sources":["@wordpress/i18n/src/sprintf.js"],"names":["memoize","sprintfjs","logErrorOnce","console","error","sprintf","format","args","Error","toString"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,QAApB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAGF,OAAO,CAAEG,OAAO,CAACC,KAAV,CAA5B,C,CAA+C;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,OAAT,CAAkBC,MAAlB,EAAoC;AAC1C,MAAI;AAAA,sCAD+BC,IAC/B;AAD+BA,MAAAA,IAC/B;AAAA;;AACH,WAAON,SAAS,CAACI,OAAV,CAAmBC,MAAnB,EAA2B,GAAGC,IAA9B,CAAP;AACA,GAFD,CAEE,OAAQH,KAAR,EAAgB;AACjB,QAAKA,KAAK,YAAYI,KAAtB,EAA8B;AAC7BN,MAAAA,YAAY,CAAE,wBAAwBE,KAAK,CAACK,QAAN,EAA1B,CAAZ;AACA;;AACD,WAAOH,MAAP;AACA;AACD","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"]}
@@ -6,10 +6,17 @@ export type LocaleData = Record<string, any>;
6
6
  */
7
7
  export type GetLocaleData = (domain?: string | undefined) => LocaleData;
8
8
  /**
9
- * Merges locale data into the Tannin instance by domain. Accepts data in a
9
+ * Merges locale data into the Tannin instance by domain. Note that this
10
+ * function will overwrite the domain configuration. Accepts data in a
10
11
  * Jed-formatted JSON object shape.
11
12
  */
12
13
  export type SetLocaleData = (data?: LocaleData | undefined, domain?: string | undefined) => void;
14
+ /**
15
+ * Merges locale data into the Tannin instance by domain. Note that this
16
+ * function will also merge the domain configuration. Accepts data in a
17
+ * Jed-formatted JSON object shape.
18
+ */
19
+ export type AddLocaleData = (data?: LocaleData | undefined, domain?: string | undefined) => void;
13
20
  /**
14
21
  * Resets all current Tannin instance locale data and sets the specified
15
22
  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
@@ -66,10 +73,17 @@ export type I18n = {
66
73
  */
67
74
  getLocaleData: GetLocaleData;
68
75
  /**
69
- * Merges locale data into the Tannin instance by domain. Accepts data in a
76
+ * Merges locale data into the Tannin instance by domain. Note that this
77
+ * function will overwrite the domain configuration. Accepts data in a
70
78
  * Jed-formatted JSON object shape.
71
79
  */
72
80
  setLocaleData: SetLocaleData;
81
+ /**
82
+ * Merges locale data into the Tannin instance by domain. Note that this
83
+ * function will also merge the domain configuration. Accepts data in a
84
+ * Jed-formatted JSON object shape.
85
+ */
86
+ addLocaleData: AddLocaleData;
73
87
  /**
74
88
  * Resets all current Tannin instance locale data and sets the specified
75
89
  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
@@ -1 +1 @@
1
- {"version":3,"file":"create-i18n.d.ts","sourceRoot":"","sources":["../src/create-i18n.js"],"names":[],"mappings":"AA6IO,qLAFK,IAAI,CAyUf;yBA9cY,OAAO,MAAM,EAAC,GAAG,CAAC;;;;;6DAyBG,UAAU;;;;;4FAQS,IAAI;;;;;8FAQJ,IAAI;gCAO3C,MAAM,IAAI;kCACV,MAAM,IAAI;;;;mCAEA,iBAAiB,KAAK,mBAAmB;;;;+DAK/B,MAAM;;;;wBAIpB,MAAM,kCAAsB,MAAM;;;;wBAOlC,MAAM,WAAW,MAAM,kCAAsB,MAAM;;;;;0BAOjD,MAAM,UAAU,MAAM,UAAU,MAAM,kCAAsB,MAAM;;;;;2BAQlE,MAAM,UAAU,MAAM,UAAU,MAAM,WAAW,MAAM,kCAAsB,MAAM;;;;;;;;;oBAQ5F,MAAM,OAAO;;;;sCAUJ,MAAM,gEAAwC,OAAO;oBAI7D,OAAO,kBAAkB,EAAE,KAAK;;;;;;;;mBAMhC,aAAa;;;;;mBACb,aAAa;;;;;qBAEb,eAAe;;;;eAEf,SAAS;;;;QACT,EAAE;;;;QACF,EAAE;;;;;QACF,EAAE;;;;;SAEF,GAAG;;;;WAEH,KAAK;;;;oBACL,cAAc"}
1
+ {"version":3,"file":"create-i18n.d.ts","sourceRoot":"","sources":["../src/create-i18n.js"],"names":[],"mappings":"AA2JO,qLAFK,IAAI,CAgWf;yBAnfY,OAAO,MAAM,EAAC,GAAG,CAAC;;;;;6DAyBG,UAAU;;;;;;4FAQS,IAAI;;;;;;4FASJ,IAAI;;;;;8FASJ,IAAI;gCAO3C,MAAM,IAAI;kCACV,MAAM,IAAI;;;;mCAEA,iBAAiB,KAAK,mBAAmB;;;;+DAK/B,MAAM;;;;wBAIpB,MAAM,kCAAsB,MAAM;;;;wBAOlC,MAAM,WAAW,MAAM,kCAAsB,MAAM;;;;;0BAOjD,MAAM,UAAU,MAAM,UAAU,MAAM,kCAAsB,MAAM;;;;;2BAQlE,MAAM,UAAU,MAAM,UAAU,MAAM,WAAW,MAAM,kCAAsB,MAAM;;;;;;;;;oBAQ5F,MAAM,OAAO;;;;sCAUJ,MAAM,gEAAwC,OAAO;oBAI7D,OAAO,kBAAkB,EAAE,KAAK;;;;;;;;mBAMhC,aAAa;;;;;;mBACb,aAAa;;;;;;mBAGb,aAAa;;;;;qBAGb,eAAe;;;;eAEf,SAAS;;;;QACT,EAAE;;;;QACF,EAAE;;;;;QACF,EAAE;;;;;SAEF,GAAG;;;;WAEH,KAAK;;;;oBACL,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/i18n",
3
- "version": "4.2.3",
3
+ "version": "4.3.1",
4
4
  "description": "WordPress internationalization (i18n) library.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,8 +29,8 @@
29
29
  "pot-to-php": "./tools/pot-to-php.js"
30
30
  },
31
31
  "dependencies": {
32
- "@babel/runtime": "^7.13.10",
33
- "@wordpress/hooks": "^3.2.1",
32
+ "@babel/runtime": "^7.16.0",
33
+ "@wordpress/hooks": "^3.3.1",
34
34
  "gettext-parser": "^1.3.1",
35
35
  "lodash": "^4.17.21",
36
36
  "memize": "^1.1.0",
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "8f7f052bc04e3f4eb50f479ced14be1489b9fa79"
43
+ "gitHead": "2e4922861e49f5a090f9dc52056165092cfba163"
44
44
  }
@@ -39,7 +39,17 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
39
39
  /**
40
40
  * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
41
41
  *
42
- * Merges locale data into the Tannin instance by domain. Accepts data in a
42
+ * Merges locale data into the Tannin instance by domain. Note that this
43
+ * function will overwrite the domain configuration. Accepts data in a
44
+ * Jed-formatted JSON object shape.
45
+ *
46
+ * @see http://messageformat.github.io/Jed/
47
+ */
48
+ /**
49
+ * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
50
+ *
51
+ * Merges locale data into the Tannin instance by domain. Note that this
52
+ * function will also merge the domain configuration. Accepts data in a
43
53
  * Jed-formatted JSON object shape.
44
54
  *
45
55
  * @see http://messageformat.github.io/Jed/
@@ -115,7 +125,11 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
115
125
  *
116
126
  * @typedef I18n
117
127
  * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.
118
- * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Accepts data in a
128
+ * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this
129
+ * function will overwrite the domain configuration. Accepts data in a
130
+ * Jed-formatted JSON object shape.
131
+ * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this
132
+ * function will also merge the domain configuration. Accepts data in a
119
133
  * Jed-formatted JSON object shape.
120
134
  * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified
121
135
  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
@@ -173,7 +187,6 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
173
187
  */
174
188
  const doSetLocaleData = ( data, domain = 'default' ) => {
175
189
  tannin.data[ domain ] = {
176
- ...DEFAULT_LOCALE_DATA,
177
190
  ...tannin.data[ domain ],
178
191
  ...data,
179
192
  };
@@ -182,8 +195,11 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
182
195
  // a plural forms expression).
183
196
  tannin.data[ domain ][ '' ] = {
184
197
  ...DEFAULT_LOCALE_DATA[ '' ],
185
- ...tannin.data[ domain ][ '' ],
198
+ ...tannin.data[ domain ]?.[ '' ],
186
199
  };
200
+
201
+ // Clean up cached plural forms functions cache as it might be updated.
202
+ delete tannin.pluralForms[ domain ];
187
203
  };
188
204
 
189
205
  /** @type {SetLocaleData} */
@@ -192,6 +208,26 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
192
208
  notifyListeners();
193
209
  };
194
210
 
211
+ /** @type {AddLocaleData} */
212
+ const addLocaleData = ( data, domain = 'default' ) => {
213
+ tannin.data[ domain ] = {
214
+ ...tannin.data[ domain ],
215
+ ...data,
216
+ // Populate default domain configuration (supported locale date which omits
217
+ // a plural forms expression).
218
+ '': {
219
+ ...DEFAULT_LOCALE_DATA[ '' ],
220
+ ...tannin.data[ domain ]?.[ '' ],
221
+ ...data?.[ '' ],
222
+ },
223
+ };
224
+
225
+ // Clean up cached plural forms functions cache as it might be updated.
226
+ delete tannin.pluralForms[ domain ];
227
+
228
+ notifyListeners();
229
+ };
230
+
195
231
  /** @type {ResetLocaleData} */
196
232
  const resetLocaleData = ( data, domain ) => {
197
233
  // Reset all current Tannin locale data.
@@ -457,6 +493,7 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
457
493
  return {
458
494
  getLocaleData,
459
495
  setLocaleData,
496
+ addLocaleData,
460
497
  resetLocaleData,
461
498
  subscribe,
462
499
  __,
@@ -44,11 +44,6 @@ const additionalLocaleData = {
44
44
  };
45
45
 
46
46
  const createTestLocale = () => createI18n( localeData, 'test_domain' );
47
- const createTestLocaleWithAdditionalData = () => {
48
- const locale = createI18n( localeData, 'test_domain' );
49
- locale.setLocaleData( additionalLocaleData, 'test_domain' );
50
- return locale;
51
- };
52
47
 
53
48
  describe( 'createI18n', () => {
54
49
  test( 'instantiated with locale data', () => {
@@ -139,6 +134,12 @@ describe( 'createI18n', () => {
139
134
  } );
140
135
 
141
136
  describe( 'setLocaleData', () => {
137
+ const createTestLocaleWithAdditionalData = () => {
138
+ const locale = createI18n( localeData, 'test_domain' );
139
+ locale.setLocaleData( additionalLocaleData, 'test_domain' );
140
+ return locale;
141
+ };
142
+
142
143
  it( 'supports omitted plural forms expression', () => {
143
144
  const locale = createTestLocaleWithAdditionalData();
144
145
  locale.setLocaleData(
@@ -157,6 +158,113 @@ describe( 'createI18n', () => {
157
158
  ).toBe( '%d bananes' );
158
159
  } );
159
160
 
161
+ it( 'overwrites domain configuration', () => {
162
+ const locale = createTestLocaleWithAdditionalData();
163
+ const domain = 'test_domain';
164
+ const domainConfiguration = {
165
+ additionalData: 'This is setLocaleData',
166
+ };
167
+ locale.setLocaleData(
168
+ {
169
+ '': domainConfiguration,
170
+ },
171
+ domain
172
+ );
173
+
174
+ expect(
175
+ locale.getLocaleData( domain )[ '' ].domain
176
+ ).toBeUndefined();
177
+ expect( locale.getLocaleData( domain )[ '' ].lang ).toBeUndefined();
178
+ expect( locale.getLocaleData( domain )[ '' ].additionalData ).toBe(
179
+ domainConfiguration.additionalData
180
+ );
181
+ } );
182
+
183
+ describe( '__', () => {
184
+ it( 'existing translation still available', () => {
185
+ const locale = createTestLocaleWithAdditionalData();
186
+ expect( locale.__( 'hello', 'test_domain' ) ).toBe( 'bonjour' );
187
+ } );
188
+
189
+ it( 'new translation available.', () => {
190
+ const locale = createTestLocaleWithAdditionalData();
191
+ expect( locale.__( 'cheeseburger', 'test_domain' ) ).toBe(
192
+ 'hamburger au fromage'
193
+ );
194
+ } );
195
+ } );
196
+
197
+ describe( '_n', () => {
198
+ it( 'existing plural form still works', () => {
199
+ const locale = createTestLocaleWithAdditionalData();
200
+ expect(
201
+ locale._n( '%d banana', '%d bananas', 3, 'test_domain' )
202
+ ).toBe( '%d bananes' );
203
+ } );
204
+
205
+ it( 'new singular form was added', () => {
206
+ const locale = createTestLocaleWithAdditionalData();
207
+ expect(
208
+ locale._n( '%d cat', '%d cats', 1, 'test_domain' )
209
+ ).toBe( '%d chat' );
210
+ } );
211
+
212
+ it( 'new plural form was added', () => {
213
+ const locale = createTestLocaleWithAdditionalData();
214
+ expect(
215
+ locale._n( '%d cat', '%d cats', 3, 'test_domain' )
216
+ ).toBe( '%d chats' );
217
+ } );
218
+ } );
219
+ } );
220
+
221
+ describe( 'addLocaleData', () => {
222
+ const createTestLocaleWithAdditionalData = () => {
223
+ const locale = createI18n( localeData, 'test_domain' );
224
+ locale.addLocaleData( additionalLocaleData, 'test_domain' );
225
+ return locale;
226
+ };
227
+
228
+ it( 'supports omitted plural forms expression', () => {
229
+ const locale = createTestLocaleWithAdditionalData();
230
+ locale.addLocaleData(
231
+ {
232
+ '': {
233
+ domain: 'test_domain2',
234
+ lang: 'fr',
235
+ },
236
+
237
+ '%d banana': [ '%d banane', '%d bananes' ],
238
+ },
239
+ 'test_domain2'
240
+ );
241
+ expect(
242
+ locale._n( '%d banana', '%d bananes', 2, 'test_domain2' )
243
+ ).toBe( '%d bananes' );
244
+ } );
245
+
246
+ it( 'merges domain configuration', () => {
247
+ const locale = createTestLocaleWithAdditionalData();
248
+ const domain = 'test_domain';
249
+ const domainConfiguration = {
250
+ additionalData: 'This is addLocaleData',
251
+ };
252
+ locale.addLocaleData(
253
+ {
254
+ '': domainConfiguration,
255
+ },
256
+ domain
257
+ );
258
+
259
+ expect( locale.getLocaleData( domain )[ '' ].domain ).toBe(
260
+ domain
261
+ );
262
+ expect( locale.getLocaleData( domain )[ '' ].lang ).toBe( 'fr' );
263
+ expect( locale.getLocaleData( domain )[ '' ].additionalData ).toBe(
264
+ domainConfiguration.additionalData
265
+ );
266
+ } );
267
+
160
268
  describe( '__', () => {
161
269
  it( 'existing translation still available', () => {
162
270
  const locale = createTestLocaleWithAdditionalData();
@@ -1 +1 @@
1
- {"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/tannin/index.d.ts","../hooks/build-types/createaddhook.d.ts","../hooks/build-types/createremovehook.d.ts","../hooks/build-types/createhashook.d.ts","../hooks/build-types/createdoinghook.d.ts","../hooks/build-types/createdidhook.d.ts","../hooks/build-types/createhooks.d.ts","../hooks/build-types/index.d.ts","./src/create-i18n.js","./src/default-i18n.js","../../node_modules/memize/index.d.ts","../../node_modules/@types/sprintf-js/index.d.ts","./src/sprintf.js","./src/index.js"],"fileInfos":[{"version":"aa9fb4c70f369237c2f45f9d969c9a59e0eae9a192962eb48581fe864aa609db","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940","eb75e89d63b3b72dd9ca8b0cac801cecae5be352307c004adeaa60bc9d6df51f","2cc028cd0bdb35b1b5eb723d84666a255933fffbea607f72cbd0c7c7b4bee144",{"version":"e54c8715a4954cfdc66cd69489f2b725c09ebf37492dbd91cff0a1688b1159e8","affectsGlobalScope":true},{"version":"51b8b27c21c066bf877646e320bf6a722b80d1ade65e686923cd9d4494aef1ca","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"2c8c5ee58f30e7c944e04ab1fb5506fdbb4dd507c9efa6972cf4b91cec90c503","affectsGlobalScope":true},{"version":"2bb4b3927299434052b37851a47bf5c39764f2ba88a888a107b32262e9292b7c","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"df9c8a72ca8b0ed62f5470b41208a0587f0f73f0a7db28e5a1272cf92537518e","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"93544ca2f26a48716c1b6c5091842cad63129daac422dfa4bc52460465f22bb1","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"7435b75fdf3509622e79622dbe5091cf4b09688410ee2034e4fc17d0c99d0862","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"9f1817f7c3f02f6d56e0f403b927e90bb133f371dcebc36fa7d6d208ef6899da","affectsGlobalScope":true},{"version":"cd6efb9467a8b6338ece2e2855e37765700f2cd061ca54b01b33878cf5c7677e","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"4632665b87204bb1caa8b44d165bce0c50dfab177df5b561b345a567cabacf9a","affectsGlobalScope":true},"0d1179b6e77f3c31405e0c31f52f13bc4270555bdd3157f0bc855d5e7fe2c4cf","d02ec79cefaf292fae64b3be5a4416e64b4e420a6429fd458fac6e1bb4c7950e","27abed653f600ea0d5c86e94181beb42824e0f3f16337e2f9e7e9e9c2c392edf","d7871e0e653aa7197fee88886db5678bee6d42164c1f36e4bce9421ddfa7ca49","11ed10bdb3bcc99893570507eac8fece4840add97ee1d4f5a7fbf41cbfdea0d4","429fb571d3db07d3eaa2e74d43eb4190ece3e0de832ed564aeeaf08873e598eb","d3060e0810fc0d0dc009e6f086ef413d3c8aeaaf07da25c8d25fd4e181646acf","406d52bf33d618d846aa0d831ee004290567e328edcd4517bbff2937cc977abf","a74aa98516af06e778d41fbdc6612d88aee6b94be805e989d266eae579e24e04","6f6bd86b465d4227fc4f37a7570679781b0877a81ba5fd9ac421176423d6907f","68e39d827a3bd5054e54a433fc90c118941096eb3e9f432b28ea5f88b0fe77b1","937a701de8090ddb1963aff55d3e95866fca72b71c062794beb2a03c846886c8","9914bdc43df748f22e9565b76e7b6a4ff0a4f0b6aaf50dd75aed9ab92242a7ff","d872b31a43d0d81f13ee111873a975df10fcd9c07cfd8698356e4d9a57bc4576"],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"importsNotUsedAsValues":2,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"rootDir":"./src","strict":true,"target":99},"fileIdsList":[[52],[46,47,48,49,50,52],[46,47,48,49,50,51],[45,52],[52,53],[53,54,57],[55,56]],"referencedMap":[[46,1],[50,1],[49,1],[48,1],[51,2],[47,1],[52,3],[53,4],[54,5],[58,6],[57,7]],"exportedModulesMap":[[46,1],[50,1],[49,1],[48,1],[51,2],[47,1],[52,3],[53,4],[54,5],[58,6],[57,7]],"semanticDiagnosticsPerFile":[56,55,45,10,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,32,33,34,35,7,40,36,37,38,39,8,41,42,43,1,9,44,46,50,49,48,51,47,52,53,54,58,57]},"version":"4.4.2"}
1
+ {"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/tannin/index.d.ts","../hooks/build-types/createaddhook.d.ts","../hooks/build-types/createremovehook.d.ts","../hooks/build-types/createhashook.d.ts","../hooks/build-types/createdoinghook.d.ts","../hooks/build-types/createdidhook.d.ts","../hooks/build-types/createhooks.d.ts","../hooks/build-types/index.d.ts","./src/create-i18n.js","./src/default-i18n.js","../../node_modules/memize/index.d.ts","../../node_modules/@types/sprintf-js/index.d.ts","./src/sprintf.js","./src/index.js"],"fileInfos":[{"version":"aa9fb4c70f369237c2f45f9d969c9a59e0eae9a192962eb48581fe864aa609db","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940","eb75e89d63b3b72dd9ca8b0cac801cecae5be352307c004adeaa60bc9d6df51f","2cc028cd0bdb35b1b5eb723d84666a255933fffbea607f72cbd0c7c7b4bee144",{"version":"e54c8715a4954cfdc66cd69489f2b725c09ebf37492dbd91cff0a1688b1159e8","affectsGlobalScope":true},{"version":"51b8b27c21c066bf877646e320bf6a722b80d1ade65e686923cd9d4494aef1ca","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"2c8c5ee58f30e7c944e04ab1fb5506fdbb4dd507c9efa6972cf4b91cec90c503","affectsGlobalScope":true},{"version":"2bb4b3927299434052b37851a47bf5c39764f2ba88a888a107b32262e9292b7c","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"df9c8a72ca8b0ed62f5470b41208a0587f0f73f0a7db28e5a1272cf92537518e","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"93544ca2f26a48716c1b6c5091842cad63129daac422dfa4bc52460465f22bb1","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"7435b75fdf3509622e79622dbe5091cf4b09688410ee2034e4fc17d0c99d0862","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"9f1817f7c3f02f6d56e0f403b927e90bb133f371dcebc36fa7d6d208ef6899da","affectsGlobalScope":true},{"version":"cd6efb9467a8b6338ece2e2855e37765700f2cd061ca54b01b33878cf5c7677e","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"4632665b87204bb1caa8b44d165bce0c50dfab177df5b561b345a567cabacf9a","affectsGlobalScope":true},"0d1179b6e77f3c31405e0c31f52f13bc4270555bdd3157f0bc855d5e7fe2c4cf","d02ec79cefaf292fae64b3be5a4416e64b4e420a6429fd458fac6e1bb4c7950e","27abed653f600ea0d5c86e94181beb42824e0f3f16337e2f9e7e9e9c2c392edf","d7871e0e653aa7197fee88886db5678bee6d42164c1f36e4bce9421ddfa7ca49","11ed10bdb3bcc99893570507eac8fece4840add97ee1d4f5a7fbf41cbfdea0d4","429fb571d3db07d3eaa2e74d43eb4190ece3e0de832ed564aeeaf08873e598eb","d3060e0810fc0d0dc009e6f086ef413d3c8aeaaf07da25c8d25fd4e181646acf","406d52bf33d618d846aa0d831ee004290567e328edcd4517bbff2937cc977abf","ff4bc5dc257c7b2b8c5a5cd3623f7a5f8b7a07ad260abaae55e39dd044a0faa0","6f6bd86b465d4227fc4f37a7570679781b0877a81ba5fd9ac421176423d6907f","68e39d827a3bd5054e54a433fc90c118941096eb3e9f432b28ea5f88b0fe77b1","937a701de8090ddb1963aff55d3e95866fca72b71c062794beb2a03c846886c8","9914bdc43df748f22e9565b76e7b6a4ff0a4f0b6aaf50dd75aed9ab92242a7ff","d872b31a43d0d81f13ee111873a975df10fcd9c07cfd8698356e4d9a57bc4576"],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"importsNotUsedAsValues":2,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"rootDir":"./src","strict":true,"target":99},"fileIdsList":[[52],[46,47,48,49,50,52],[46,47,48,49,50,51],[45,52],[52,53],[53,54,57],[55,56]],"referencedMap":[[46,1],[50,1],[49,1],[48,1],[51,2],[47,1],[52,3],[53,4],[54,5],[58,6],[57,7]],"exportedModulesMap":[[46,1],[50,1],[49,1],[48,1],[51,2],[47,1],[52,3],[53,4],[54,5],[58,6],[57,7]],"semanticDiagnosticsPerFile":[56,55,45,10,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,32,33,34,35,7,40,36,37,38,39,8,41,42,43,1,9,44,46,50,49,48,51,47,52,53,54,58,57]},"version":"4.4.2"}