@wordpress/i18n 4.2.5-next.33ec3857e2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/LICENSE.md +1 -1
- package/build/create-i18n.js +45 -6
- package/build/create-i18n.js.map +1 -1
- package/build-module/create-i18n.js +45 -6
- package/build-module/create-i18n.js.map +1 -1
- package/build-types/create-i18n.d.ts +16 -2
- package/build-types/create-i18n.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/create-i18n.js +41 -4
- package/src/test/create-i18n.js +113 -5
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/LICENSE.md
CHANGED
package/build/create-i18n.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
@@ -201,16 +216,19 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
201
216
|
|
|
202
217
|
|
|
203
218
|
const doSetLocaleData = function (data) {
|
|
219
|
+
var _tannin$data$domain;
|
|
220
|
+
|
|
204
221
|
let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
|
|
205
|
-
tannin.data[domain] = { ...
|
|
206
|
-
...tannin.data[domain],
|
|
222
|
+
tannin.data[domain] = { ...tannin.data[domain],
|
|
207
223
|
...data
|
|
208
224
|
}; // Populate default domain configuration (supported locale date which omits
|
|
209
225
|
// a plural forms expression).
|
|
210
226
|
|
|
211
227
|
tannin.data[domain][''] = { ...DEFAULT_LOCALE_DATA[''],
|
|
212
|
-
...tannin.data[domain]['']
|
|
213
|
-
};
|
|
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];
|
|
214
232
|
};
|
|
215
233
|
/** @type {SetLocaleData} */
|
|
216
234
|
|
|
@@ -219,6 +237,26 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
219
237
|
doSetLocaleData(data, domain);
|
|
220
238
|
notifyListeners();
|
|
221
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
|
+
};
|
|
222
260
|
/** @type {ResetLocaleData} */
|
|
223
261
|
|
|
224
262
|
|
|
@@ -453,6 +491,7 @@ const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
453
491
|
return {
|
|
454
492
|
getLocaleData,
|
|
455
493
|
setLocaleData,
|
|
494
|
+
addLocaleData,
|
|
456
495
|
resetLocaleData,
|
|
457
496
|
subscribe,
|
|
458
497
|
__,
|
package/build/create-i18n.js.map
CHANGED
|
@@ -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,QAA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HgB,EAIhBD,OAJgB,EAKhBP,MALgB,CADlB;AAUAuB,MAAAA,MAAM;AAAG;;AACR;AAAiBpC,MAAAA,KAAK,CAAC6B,YAAN,CAChB,0BAA0BJ,eAAe,CAAEZ,MAAF,CADzB,EAEhBuB,MAFgB,EAGhBf,MAHgB,EAIhBD,OAJgB,EAKhBP,MALgB,CADlB;AASA;;AACD,WAAOuB,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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,UAAU,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,MAAM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;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"]}
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
@@ -191,16 +206,19 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
191
206
|
|
|
192
207
|
|
|
193
208
|
const doSetLocaleData = function (data) {
|
|
209
|
+
var _tannin$data$domain;
|
|
210
|
+
|
|
194
211
|
let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
|
|
195
|
-
tannin.data[domain] = { ...
|
|
196
|
-
...tannin.data[domain],
|
|
212
|
+
tannin.data[domain] = { ...tannin.data[domain],
|
|
197
213
|
...data
|
|
198
214
|
}; // Populate default domain configuration (supported locale date which omits
|
|
199
215
|
// a plural forms expression).
|
|
200
216
|
|
|
201
217
|
tannin.data[domain][''] = { ...DEFAULT_LOCALE_DATA[''],
|
|
202
|
-
...tannin.data[domain]['']
|
|
203
|
-
};
|
|
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];
|
|
204
222
|
};
|
|
205
223
|
/** @type {SetLocaleData} */
|
|
206
224
|
|
|
@@ -209,6 +227,26 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
209
227
|
doSetLocaleData(data, domain);
|
|
210
228
|
notifyListeners();
|
|
211
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
|
+
};
|
|
212
250
|
/** @type {ResetLocaleData} */
|
|
213
251
|
|
|
214
252
|
|
|
@@ -443,6 +481,7 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
443
481
|
return {
|
|
444
482
|
getLocaleData,
|
|
445
483
|
setLocaleData,
|
|
484
|
+
addLocaleData,
|
|
446
485
|
resetLocaleData,
|
|
447
486
|
subscribe,
|
|
448
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;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;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;;AACA,OAA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":["/**\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;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GAAG,CAAEC,WAAF,EAAeC,aAAf,EAA8BC,KAA9B,KAAyC;AAClE;AACD;AACA;AACA;AACA;AACC,QAAMC,MAAM,GAAG,IAAIT,MA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AC5C,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"]}
|
|
@@ -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.
|
|
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.
|
|
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":"
|
|
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.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "WordPress internationalization (i18n) library.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
|
-
"@wordpress/hooks": "^3.
|
|
33
|
+
"@wordpress/hooks": "^3.3.0",
|
|
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": "
|
|
43
|
+
"gitHead": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
|
|
44
44
|
}
|
package/src/create-i18n.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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
|
__,
|
package/src/test/create-i18n.js
CHANGED
|
@@ -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();
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -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","
|
|
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"}
|