@wordpress/i18n 5.25.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"names":["Tannin","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","listeners","Set","notifyListeners","forEach","listener","subscribe","callback","add","delete","getLocaleData","domain","data","doSetLocaleData","pluralForms","setLocaleData","addLocaleData","resetLocaleData","dcnpgettext","context","single","plural","number","undefined","getFilterDomain","__","text","translation","applyFilters","_x","_n","_nx","isRTL","hasTranslation","key","result","onHookAddedOrRemoved","hookName","test","addAction"],"sources":["@wordpress/i18n/src/create-i18n.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport Tannin from 'tannin';\n\n/**\n * @typedef {Record<string,any>} LocaleData\n */\n\n/**\n * Default locale data to use for Tannin domain when not otherwise provided.\n * Assumes an English plural forms expression.\n *\n * @type {LocaleData}\n */\nconst DEFAULT_LOCALE_DATA = {\n\t'': {\n\t\t/** @param {number} n */\n\t\tplural_forms( n ) {\n\t\t\treturn n === 1 ? 0 : 1;\n\t\t},\n\t},\n};\n\n/*\n * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,\n * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.\n */\nconst I18N_HOOK_REGEXP = /^i18n\\.(n?gettext|has_translation)(_|$)/;\n\n/**\n * @typedef {(domain?: string) => LocaleData} GetLocaleData\n *\n * Returns locale data by domain in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData\n *\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/** @typedef {() => void} SubscribeCallback */\n/** @typedef {() => void} UnsubscribeCallback */\n/**\n * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe\n *\n * Subscribes to changes of locale data\n */\n/**\n * @typedef {(domain?: string) => string} GetFilterDomain\n * Retrieve the domain to use when calling domain-specific filters.\n */\n/**\n * @typedef {(text: string, domain?: string) => string} __\n *\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n */\n/**\n * @typedef {(text: string, context: string, domain?: string) => string} _x\n *\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n */\n/**\n * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n */\n/**\n * @typedef {() => boolean} IsRtl\n *\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n */\n/**\n * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation\n *\n * Check if there is a translation for a given string in singular form.\n */\n/** @typedef {import('@wordpress/hooks').Hooks} Hooks */\n\n/**\n * An i18n instance\n *\n * @typedef I18n\n * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.\n * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n * @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.\n * @property {__} __ Retrieve the translation of text.\n * @property {_x} _x Retrieve translated string with gettext context.\n * @property {_n} _n Translates and retrieves the singular or plural form based on the supplied\n * number.\n * @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n * @property {IsRtl} isRTL Check if current locale is RTL.\n * @property {HasTranslation} hasTranslation Check if there is a translation for a given string.\n */\n\n/**\n * Create an i18n instance\n *\n * @param {LocaleData} [initialData] Locale data configuration.\n * @param {string} [initialDomain] Domain for which configuration applies.\n * @param {Hooks} [hooks] Hooks implementation.\n *\n * @return {I18n} I18n instance.\n */\nexport const createI18n = ( initialData, initialDomain, hooks ) => {\n\t/**\n\t * The underlying instance of Tannin to which exported functions interface.\n\t *\n\t * @type {Tannin}\n\t */\n\tconst tannin = new Tannin( {} );\n\n\tconst listeners = new Set();\n\n\tconst notifyListeners = () => {\n\t\tlisteners.forEach( ( listener ) => listener() );\n\t};\n\n\t/**\n\t * Subscribe to changes of locale data.\n\t *\n\t * @param {SubscribeCallback} callback Subscription callback.\n\t * @return {UnsubscribeCallback} Unsubscribe callback.\n\t */\n\tconst subscribe = ( callback ) => {\n\t\tlisteners.add( callback );\n\t\treturn () => listeners.delete( callback );\n\t};\n\n\t/** @type {GetLocaleData} */\n\tconst getLocaleData = ( domain = 'default' ) => tannin.data[ domain ];\n\n\t/**\n\t * @param {LocaleData} [data]\n\t * @param {string} [domain]\n\t */\n\tconst doSetLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t};\n\n\t\t// Populate default domain configuration (supported locale date which omits\n\t\t// a plural forms expression).\n\t\ttannin.data[ domain ][ '' ] = {\n\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\t};\n\n\t/** @type {SetLocaleData} */\n\tconst setLocaleData = ( data, domain ) => {\n\t\tdoSetLocaleData( data, domain );\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {AddLocaleData} */\n\tconst addLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t\t// Populate default domain configuration (supported locale date which omits\n\t\t\t// a plural forms expression).\n\t\t\t'': {\n\t\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t\t\t...data?.[ '' ],\n\t\t\t},\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {ResetLocaleData} */\n\tconst resetLocaleData = ( data, domain ) => {\n\t\t// Reset all current Tannin locale data.\n\t\ttannin.data = {};\n\n\t\t// Reset cached plural forms functions cache.\n\t\ttannin.pluralForms = {};\n\n\t\tsetLocaleData( data, domain );\n\t};\n\n\t/**\n\t * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not\n\t * otherwise previously assigned.\n\t *\n\t * @param {string|undefined} domain Domain to retrieve the translated text.\n\t * @param {string|undefined} context Context information for the translators.\n\t * @param {string} single Text to translate if non-plural. Used as\n\t * fallback return value on a caught error.\n\t * @param {string} [plural] The text to be used if the number is\n\t * plural.\n\t * @param {number} [number] The number to compare against to use\n\t * either the singular or plural form.\n\t *\n\t * @return {string} The translated string.\n\t */\n\tconst dcnpgettext = (\n\t\tdomain = 'default',\n\t\tcontext,\n\t\tsingle,\n\t\tplural,\n\t\tnumber\n\t) => {\n\t\tif ( ! tannin.data[ domain ] ) {\n\t\t\t// Use `doSetLocaleData` to set silently, without notifying listeners.\n\t\t\tdoSetLocaleData( undefined, domain );\n\t\t}\n\n\t\treturn tannin.dcnpgettext( domain, context, single, plural, number );\n\t};\n\n\t/** @type {GetFilterDomain} */\n\tconst getFilterDomain = ( domain = 'default' ) => domain;\n\n\t/** @type {__} */\n\tconst __ = ( text, domain ) => {\n\t\tlet translation = dcnpgettext( domain, undefined, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_x} */\n\tconst _x = ( text, context, domain ) => {\n\t\tlet translation = dcnpgettext( domain, context, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation based on context information.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_n} */\n\tconst _n = ( single, plural, number, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tundefined,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_nx} */\n\tconst _nx = ( single, plural, number, context, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tcontext,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn translation;\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string with gettext context.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\n\t\treturn /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {IsRtl} */\n\tconst isRTL = () => {\n\t\treturn 'rtl' === _x( 'ltr', 'text direction' );\n\t};\n\n\t/** @type {HasTranslation} */\n\tconst hasTranslation = ( single, context, domain ) => {\n\t\tconst key = context ? context + '\\u0004' + single : single;\n\t\tlet result = !! tannin.data?.[ domain ?? 'default' ]?.[ key ];\n\t\tif ( hooks ) {\n\t\t\t/**\n\t\t\t * Filters the presence of a translation in the locale data.\n\t\t\t *\n\t\t\t * @param {boolean} hasTranslation Whether the translation is present or not..\n\t\t\t * @param {string} single The singular form of the translated text (used as key in locale data)\n\t\t\t * @param {string} context Context information for the translators.\n\t\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t\t */\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation',\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation_' + getFilterDomain( domain ),\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t};\n\n\tif ( initialData ) {\n\t\tsetLocaleData( initialData, initialDomain );\n\t}\n\n\tif ( hooks ) {\n\t\t/**\n\t\t * @param {string} hookName\n\t\t */\n\t\tconst onHookAddedOrRemoved = ( hookName ) => {\n\t\t\tif ( I18N_HOOK_REGEXP.test( hookName ) ) {\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t};\n\n\t\thooks.addAction( 'hookAdded', 'core/i18n', onHookAddedOrRemoved );\n\t\thooks.addAction( 'hookRemoved', 'core/i18n', onHookAddedOrRemoved );\n\t}\n\n\treturn {\n\t\tgetLocaleData,\n\t\tsetLocaleData,\n\t\taddLocaleData,\n\t\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAM,MAAM,QAAQ;;AAE3B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG;EAC3B,EAAE,EAAE;IACH;IACAC,YAAYA,CAAEC,CAAC,EAAG;MACjB,OAAOA,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;IACvB;EACD;AACD,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG,yCAAyC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAGA,CAAEC,WAAW,EAAEC,aAAa,EAAEC,KAAK,KAAM;EAClE;AACD;AACA;AACA;AACA;EACC,MAAMC,MAAM,GAAG,IAAIT,MAAM,CAAE,CAAC,CAAE,CAAC;EAE/B,MAAMU,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAE3B,MAAMC,eAAe,GAAGA,CAAA,KAAM;IAC7BF,SAAS,CAACG,OAAO,CAAIC,QAAQ,IAAMA,QAAQ,CAAC,CAAE,CAAC;EAChD,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;EACC,MAAMC,SAAS,GAAKC,QAAQ,IAAM;IACjCN,SAAS,CAACO,GAAG,CAAED,QAAS,CAAC;IACzB,OAAO,MAAMN,SAAS,CAACQ,MAAM,CAAEF,QAAS,CAAC;EAC1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,MAAM,EACND,OAAO,EACPR,MACD,CACA;IACF;IACA,OAAOwB,MAAM;EACd,CAAC;EAED,IAAKtC,WAAW,EAAG;IAClBkB,aAAa,CAAElB,WAAW,EAAEC,aAAc,CAAC;EAC5C;EAEA,IAAKC,KAAK,EAAG;IACZ;AACF;AACA;IACE,MAAMqC,oBAAoB,GAAKC,QAAQ,IAAM;MAC5C,IAAK1C,gBAAgB,CAAC2C,IAAI,CAAED,QAAS,CAAC,EAAG;QACxClC,eAAe,CAAC,CAAC;MAClB;IACD,CAAC;IAEDJ,KAAK,CAACwC,SAAS,CAAE,WAAW,EAAE,WAAW,EAAEH,oBAAqB,CAAC;IACjErC,KAAK,CAACwC,SAAS,CAAE,aAAa,EAAE,WAAW,EAAEH,oBAAqB,CAAC;EACpE;EAEA,OAAO;IACN1B,aAAa;IACbK,aAAa;IACbC,aAAa;IACbC,eAAe;IACfX,SAAS;IACTmB,EAAE;IACFI,EAAE;IACFC,EAAE;IACFC,GAAG;IACHC,KAAK;IACLC;EACD,CAAC;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Tannin","DEFAULT_LOCALE_DATA","plural_forms","n","I18N_HOOK_REGEXP","createI18n","initialData","initialDomain","hooks","tannin","listeners","Set","notifyListeners","forEach","listener","subscribe","callback","add","delete","getLocaleData","domain","data","doSetLocaleData","pluralForms","setLocaleData","addLocaleData","resetLocaleData","dcnpgettext","context","single","plural","number","undefined","getFilterDomain","__","text","translation","applyFilters","_x","_n","_nx","isRTL","hasTranslation","key","result","onHookAddedOrRemoved","hookName","test","addAction"],"sources":["@wordpress/i18n/src/create-i18n.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport Tannin from 'tannin';\n\n/**\n * @typedef {Record<string,any>} LocaleData\n */\n\n/**\n * Default locale data to use for Tannin domain when not otherwise provided.\n * Assumes an English plural forms expression.\n *\n * @type {LocaleData}\n */\nconst DEFAULT_LOCALE_DATA = {\n\t'': {\n\t\t/** @param {number} n */\n\t\tplural_forms( n ) {\n\t\t\treturn n === 1 ? 0 : 1;\n\t\t},\n\t},\n};\n\n/*\n * Regular expression that matches i18n hooks like `i18n.gettext`, `i18n.ngettext`,\n * `i18n.gettext_domain` or `i18n.ngettext_with_context` or `i18n.has_translation`.\n */\nconst I18N_HOOK_REGEXP = /^i18n\\.(n?gettext|has_translation)(_|$)/;\n\n/**\n * @typedef {(domain?: string) => LocaleData} GetLocaleData\n *\n * Returns locale data by domain in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData\n *\n * Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/**\n * @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData\n *\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n */\n/** @typedef {() => void} SubscribeCallback */\n/** @typedef {() => void} UnsubscribeCallback */\n/**\n * @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe\n *\n * Subscribes to changes of locale data\n */\n/**\n * @typedef {(domain?: string) => string} GetFilterDomain\n * Retrieve the domain to use when calling domain-specific filters.\n */\n/**\n * @typedef {<Text extends string>(text: Text, domain?: string) => import('./types').TranslatableText< Text >} __\n *\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n */\n/**\n * @typedef {<Text extends string>(text: Text, context: string, domain?: string) => import('./types').TranslatableText< Text >} _x\n *\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n */\n/**\n * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string) => import('./types').TranslatableText< Single | Plural >} _n\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n */\n/**\n * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: string) => import('./types').TranslatableText< Single | Plural >} _nx\n *\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n */\n/**\n * @typedef {() => boolean} IsRtl\n *\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n */\n/**\n * @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation\n *\n * Check if there is a translation for a given string in singular form.\n */\n/** @typedef {import('@wordpress/hooks').Hooks} Hooks */\n\n/**\n * An i18n instance\n *\n * @typedef I18n\n * @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.\n * @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will overwrite the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this\n * function will also merge the domain configuration. Accepts data in a\n * Jed-formatted JSON object shape.\n * @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n * @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.\n * @property {__} __ Retrieve the translation of text.\n * @property {_x} _x Retrieve translated string with gettext context.\n * @property {_n} _n Translates and retrieves the singular or plural form based on the supplied\n * number.\n * @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n * @property {IsRtl} isRTL Check if current locale is RTL.\n * @property {HasTranslation} hasTranslation Check if there is a translation for a given string.\n */\n\n/**\n * Create an i18n instance\n *\n * @param {LocaleData} [initialData] Locale data configuration.\n * @param {string} [initialDomain] Domain for which configuration applies.\n * @param {Hooks} [hooks] Hooks implementation.\n *\n * @return {I18n} I18n instance.\n */\nexport const createI18n = ( initialData, initialDomain, hooks ) => {\n\t/**\n\t * The underlying instance of Tannin to which exported functions interface.\n\t *\n\t * @type {Tannin}\n\t */\n\tconst tannin = new Tannin( {} );\n\n\tconst listeners = new Set();\n\n\tconst notifyListeners = () => {\n\t\tlisteners.forEach( ( listener ) => listener() );\n\t};\n\n\t/**\n\t * Subscribe to changes of locale data.\n\t *\n\t * @param {SubscribeCallback} callback Subscription callback.\n\t * @return {UnsubscribeCallback} Unsubscribe callback.\n\t */\n\tconst subscribe = ( callback ) => {\n\t\tlisteners.add( callback );\n\t\treturn () => listeners.delete( callback );\n\t};\n\n\t/** @type {GetLocaleData} */\n\tconst getLocaleData = ( domain = 'default' ) => tannin.data[ domain ];\n\n\t/**\n\t * @param {LocaleData} [data]\n\t * @param {string} [domain]\n\t */\n\tconst doSetLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t};\n\n\t\t// Populate default domain configuration (supported locale date which omits\n\t\t// a plural forms expression).\n\t\ttannin.data[ domain ][ '' ] = {\n\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\t};\n\n\t/** @type {SetLocaleData} */\n\tconst setLocaleData = ( data, domain ) => {\n\t\tdoSetLocaleData( data, domain );\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {AddLocaleData} */\n\tconst addLocaleData = ( data, domain = 'default' ) => {\n\t\ttannin.data[ domain ] = {\n\t\t\t...tannin.data[ domain ],\n\t\t\t...data,\n\t\t\t// Populate default domain configuration (supported locale date which omits\n\t\t\t// a plural forms expression).\n\t\t\t'': {\n\t\t\t\t...DEFAULT_LOCALE_DATA[ '' ],\n\t\t\t\t...tannin.data[ domain ]?.[ '' ],\n\t\t\t\t...data?.[ '' ],\n\t\t\t},\n\t\t};\n\n\t\t// Clean up cached plural forms functions cache as it might be updated.\n\t\tdelete tannin.pluralForms[ domain ];\n\n\t\tnotifyListeners();\n\t};\n\n\t/** @type {ResetLocaleData} */\n\tconst resetLocaleData = ( data, domain ) => {\n\t\t// Reset all current Tannin locale data.\n\t\ttannin.data = {};\n\n\t\t// Reset cached plural forms functions cache.\n\t\ttannin.pluralForms = {};\n\n\t\tsetLocaleData( data, domain );\n\t};\n\n\t/**\n\t * Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not\n\t * otherwise previously assigned.\n\t *\n\t * @param {string|undefined} domain Domain to retrieve the translated text.\n\t * @param {string|undefined} context Context information for the translators.\n\t * @param {string} single Text to translate if non-plural. Used as\n\t * fallback return value on a caught error.\n\t * @param {string} [plural] The text to be used if the number is\n\t * plural.\n\t * @param {number} [number] The number to compare against to use\n\t * either the singular or plural form.\n\t *\n\t * @return {string} The translated string.\n\t */\n\tconst dcnpgettext = (\n\t\tdomain = 'default',\n\t\tcontext,\n\t\tsingle,\n\t\tplural,\n\t\tnumber\n\t) => {\n\t\tif ( ! tannin.data[ domain ] ) {\n\t\t\t// Use `doSetLocaleData` to set silently, without notifying listeners.\n\t\t\tdoSetLocaleData( undefined, domain );\n\t\t}\n\n\t\treturn tannin.dcnpgettext( domain, context, single, plural, number );\n\t};\n\n\t/** @type {GetFilterDomain} */\n\tconst getFilterDomain = ( domain = 'default' ) => domain;\n\n\t/** @type {__} */\n\tconst __ = ( text, domain ) => {\n\t\tlet translation = dcnpgettext( domain, undefined, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn /** @type {import('./types').TranslatableText<typeof text>} */ (\n\t\t\t\ttranslation\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {import('./types').TranslatableText<typeof text>} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_x} */\n\tconst _x = ( text, context, domain ) => {\n\t\tlet translation = dcnpgettext( domain, context, text );\n\t\tif ( ! hooks ) {\n\t\t\treturn /** @type {import('./types').TranslatableText<typeof text>} */ (\n\t\t\t\ttranslation\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Filters text with its translation based on context information.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} text Text to translate.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {import('./types').TranslatableText<typeof text>} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.gettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\ttext,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_n} */\n\tconst _n = ( single, plural, number, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tundefined,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (\n\t\t\t\ttranslation\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t\treturn /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {_nx} */\n\tconst _nx = ( single, plural, number, context, domain ) => {\n\t\tlet translation = dcnpgettext(\n\t\t\tdomain,\n\t\t\tcontext,\n\t\t\tsingle,\n\t\t\tplural,\n\t\t\tnumber\n\t\t);\n\t\tif ( ! hooks ) {\n\t\t\treturn /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (\n\t\t\t\ttranslation\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Filters the singular or plural form of a string with gettext context.\n\t\t *\n\t\t * @param {string} translation Translated text.\n\t\t * @param {string} single The text to be used if the number is singular.\n\t\t * @param {string} plural The text to be used if the number is plural.\n\t\t * @param {string} number The number to compare against to use either the singular or plural form.\n\t\t * @param {string} context Context information for the translators.\n\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t */\n\t\ttranslation = /** @type {string} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context',\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\n\t\treturn /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (\n\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t'i18n.ngettext_with_context_' + getFilterDomain( domain ),\n\t\t\t\ttranslation,\n\t\t\t\tsingle,\n\t\t\t\tplural,\n\t\t\t\tnumber,\n\t\t\t\tcontext,\n\t\t\t\tdomain\n\t\t\t)\n\t\t);\n\t};\n\n\t/** @type {IsRtl} */\n\tconst isRTL = () => {\n\t\treturn 'rtl' === _x( 'ltr', 'text direction' );\n\t};\n\n\t/** @type {HasTranslation} */\n\tconst hasTranslation = ( single, context, domain ) => {\n\t\tconst key = context ? context + '\\u0004' + single : single;\n\t\tlet result = !! tannin.data?.[ domain ?? 'default' ]?.[ key ];\n\t\tif ( hooks ) {\n\t\t\t/**\n\t\t\t * Filters the presence of a translation in the locale data.\n\t\t\t *\n\t\t\t * @param {boolean} hasTranslation Whether the translation is present or not..\n\t\t\t * @param {string} single The singular form of the translated text (used as key in locale data)\n\t\t\t * @param {string} context Context information for the translators.\n\t\t\t * @param {string} domain Text domain. Unique identifier for retrieving translated strings.\n\t\t\t */\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation',\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tresult = /** @type { boolean } */ (\n\t\t\t\t/** @type {*} */ hooks.applyFilters(\n\t\t\t\t\t'i18n.has_translation_' + getFilterDomain( domain ),\n\t\t\t\t\tresult,\n\t\t\t\t\tsingle,\n\t\t\t\t\tcontext,\n\t\t\t\t\tdomain\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn result;\n\t};\n\n\tif ( initialData ) {\n\t\tsetLocaleData( initialData, initialDomain );\n\t}\n\n\tif ( hooks ) {\n\t\t/**\n\t\t * @param {string} hookName\n\t\t */\n\t\tconst onHookAddedOrRemoved = ( hookName ) => {\n\t\t\tif ( I18N_HOOK_REGEXP.test( hookName ) ) {\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t};\n\n\t\thooks.addAction( 'hookAdded', 'core/i18n', onHookAddedOrRemoved );\n\t\thooks.addAction( 'hookRemoved', 'core/i18n', onHookAddedOrRemoved );\n\t}\n\n\treturn {\n\t\tgetLocaleData,\n\t\tsetLocaleData,\n\t\taddLocaleData,\n\t\tresetLocaleData,\n\t\tsubscribe,\n\t\t__,\n\t\t_x,\n\t\t_n,\n\t\t_nx,\n\t\tisRTL,\n\t\thasTranslation,\n\t};\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAM,MAAM,QAAQ;;AAE3B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG;EAC3B,EAAE,EAAE;IACH;IACAC,YAAYA,CAAEC,CAAC,EAAG;MACjB,OAAOA,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;IACvB;EACD;AACD,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAG,yCAAyC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAGA,CAAEC,WAAW,EAAEC,aAAa,EAAEC,KAAK,KAAM;EAClE;AACD;AACA;AACA;AACA;EACC,MAAMC,MAAM,GAAG,IAAIT,MAAM,CAAE,CAAC,CAAE,CAAC;EAE/B,MAAMU,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAE3B,MAAMC,eAAe,GAAGA,CAAA,KAAM;IAC7BF,SAAS,CAACG,OAAO,CAAIC,QAAQ,IAAMA,QAAQ,CAAC,CAAE,CAAC;EAChD,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;EACC,MAAMC,SAAS,GAAKC,QAAQ,IAAM;IACjCN,SAAS,CAACO,GAAG,CAAED,QAAS,CAAC;IACzB,OAAO,MAAMN,SAAS,CAACQ,MAAM,CAAEF,QAAS,CAAC;EAC1C,CAAC;;EAED;EACA,MAAMG,aAAa,GAAGA,CAAEC,MAAM,GAAG,SAAS,KAAMX,MAAM,CAACY,IAAI,CAAED,MAAM,CAAE;;EAErE;AACD;AACA;AACA;EACC,MAAME,eAAe,GAAGA,CAAED,IAAI,EAAED,MAAM,GAAG,SAAS,KAAM;IACvDX,MAAM,CAACY,IAAI,CAAED,MAA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oB,GAAKC,QAAQ,IAAM;MAC5C,IAAK1C,gBAAgB,CAAC2C,IAAI,CAAED,QAAS,CAAC,EAAG;QACxClC,eAAe,CAAC,CAAC;MAClB;IACD,CAAC;IAEDJ,KAAK,CAACwC,SAAS,CAAE,WAAW,EAAE,WAAW,EAAEH,oBAAqB,CAAC;IACjErC,KAAK,CAACwC,SAAS,CAAE,aAAa,EAAE,WAAW,EAAEH,oBAAqB,CAAC;EACpE;EAEA,OAAO;IACN1B,aAAa;IACbK,aAAa;IACbC,aAAa;IACbC,eAAe;IACfX,SAAS;IACTmB,EAAE;IACFI,EAAE;IACFC,EAAE;IACFC,GAAG;IACHC,KAAK;IACLC;EACD,CAAC;AACF,CAAC","ignoreList":[]}
@@ -70,10 +70,12 @@ export const subscribe = i18n.subscribe.bind(i18n);
70
70
  *
71
71
  * @see https://developer.wordpress.org/reference/functions/__/
72
72
  *
73
- * @param {string} text Text to translate.
73
+ * @template {string} Text
74
+ *
75
+ * @param {Text} text Text to translate.
74
76
  * @param {string} [domain] Domain to retrieve the translated text.
75
77
  *
76
- * @return {string} Translated text.
78
+ * @return {import('./types').TranslatableText< Text >} Translated text.
77
79
  */
78
80
  export const __ = i18n.__.bind(i18n);
79
81
 
@@ -82,11 +84,13 @@ export const __ = i18n.__.bind(i18n);
82
84
  *
83
85
  * @see https://developer.wordpress.org/reference/functions/_x/
84
86
  *
85
- * @param {string} text Text to translate.
87
+ * @template {string} Text
88
+ *
89
+ * @param {Text} text Text to translate.
86
90
  * @param {string} context Context information for the translators.
87
91
  * @param {string} [domain] Domain to retrieve the translated text.
88
92
  *
89
- * @return {string} Translated context string without pipe.
93
+ * @return {import('./types').TranslatableText< Text >} Translated context string without pipe.
90
94
  */
91
95
  export const _x = i18n._x.bind(i18n);
92
96
 
@@ -96,13 +100,16 @@ export const _x = i18n._x.bind(i18n);
96
100
  *
97
101
  * @see https://developer.wordpress.org/reference/functions/_n/
98
102
  *
99
- * @param {string} single The text to be used if the number is singular.
100
- * @param {string} plural The text to be used if the number is plural.
103
+ * @template {string} Single
104
+ * @template {string} Plural
105
+ *
106
+ * @param {Single} single The text to be used if the number is singular.
107
+ * @param {Plural} plural The text to be used if the number is plural.
101
108
  * @param {number} number The number to compare against to use either the
102
109
  * singular or plural form.
103
110
  * @param {string} [domain] Domain to retrieve the translated text.
104
111
  *
105
- * @return {string} The translated singular or plural form.
112
+ * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.
106
113
  */
107
114
  export const _n = i18n._n.bind(i18n);
108
115
 
@@ -112,14 +119,17 @@ export const _n = i18n._n.bind(i18n);
112
119
  *
113
120
  * @see https://developer.wordpress.org/reference/functions/_nx/
114
121
  *
115
- * @param {string} single The text to be used if the number is singular.
116
- * @param {string} plural The text to be used if the number is plural.
122
+ * @template {string} Single
123
+ * @template {string} Plural
124
+ *
125
+ * @param {Single} single The text to be used if the number is singular.
126
+ * @param {Plural} plural The text to be used if the number is plural.
117
127
  * @param {number} number The number to compare against to use either the
118
128
  * singular or plural form.
119
129
  * @param {string} context Context information for the translators.
120
130
  * @param {string} [domain] Domain to retrieve the translated text.
121
131
  *
122
- * @return {string} The translated singular or plural form.
132
+ * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.
123
133
  */
124
134
  export const _nx = i18n._nx.bind(i18n);
125
135
 
@@ -1 +1 @@
1
- {"version":3,"names":["createI18n","defaultHooks","i18n","undefined","getLocaleData","bind","setLocaleData","resetLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/default-i18n.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createI18n } from './create-i18n';\n\n/**\n * WordPress dependencies\n */\nimport { defaultHooks } from '@wordpress/hooks';\n\nconst i18n = createI18n( undefined, undefined, defaultHooks );\n\n/**\n * Default, singleton instance of `I18n`.\n */\nexport default i18n;\n\n/*\n * Comments in this file are duplicated from ./i18n due to\n * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722\n */\n\n/**\n * @typedef {import('./create-i18n').LocaleData} LocaleData\n * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback\n * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback\n */\n\n/**\n * Returns locale data by domain in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {string} [domain] Domain for which to get the data.\n * @return {LocaleData} Locale data.\n */\nexport const getLocaleData = i18n.getLocaleData.bind( i18n );\n\n/**\n * Merges locale data into the Tannin instance by domain. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const setLocaleData = i18n.setLocaleData.bind( i18n );\n\n/**\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const resetLocaleData = i18n.resetLocaleData.bind( i18n );\n\n/**\n * Subscribes to changes of locale data\n *\n * @param {SubscribeCallback} callback Subscription callback\n * @return {UnsubscribeCallback} Unsubscribe callback\n */\nexport const subscribe = i18n.subscribe.bind( i18n );\n\n/**\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n *\n * @param {string} text Text to translate.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} Translated text.\n */\nexport const __ = i18n.__.bind( i18n );\n\n/**\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n *\n * @param {string} text Text to translate.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} Translated context string without pipe.\n */\nexport const _x = i18n._x.bind( i18n );\n\n/**\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n *\n * @param {string} single The text to be used if the number is singular.\n * @param {string} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} The translated singular or plural form.\n */\nexport const _n = i18n._n.bind( i18n );\n\n/**\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n *\n * @param {string} single The text to be used if the number is singular.\n * @param {string} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} The translated singular or plural form.\n */\nexport const _nx = i18n._nx.bind( i18n );\n\n/**\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n *\n * @return {boolean} Whether locale is RTL.\n */\nexport const isRTL = i18n.isRTL.bind( i18n );\n\n/**\n * Check if there is a translation for a given string (in singular form).\n *\n * @param {string} single Singular form of the string to look up.\n * @param {string} [context] Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n * @return {boolean} Whether the translation exists or not.\n */\nexport const hasTranslation = i18n.hasTranslation.bind( i18n );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,eAAe;;AAE1C;AACA;AACA;AACA,SAASC,YAAY,QAAQ,kBAAkB;AAE/C,MAAMC,IAAI,GAAGF,UAAU,CAAEG,SAAS,EAAEA,SAAS,EAAEF,YAAa,CAAC;;AAE7D;AACA;AACA;AACA,eAAeC,IAAI;;AAEnB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,aAAa,GAAGF,IAAI,CAACE,aAAa,CAACC,IAAI,CAAEH,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,aAAa,GAAGJ,IAAI,CAACI,aAAa,CAACD,IAAI,CAAEH,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMK,eAAe,GAAGL,IAAI,CAACK,eAAe,CAACF,IAAI,CAAEH,IAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,SAAS,GAAGN,IAAI,CAACM,SAAS,CAACH,IAAI,CAAEH,IAAK,CAAC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMO,EAAE,GAAGP,IAAI,CAACO,EAAE,CAACJ,IAAI,CAAEH,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMQ,EAAE,GAAGR,IAAI,CAACQ,EAAE,CAACL,IAAI,CAAEH,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMS,EAAE,GAAGT,IAAI,CAACS,EAAE,CAACN,IAAI,CAAEH,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMU,GAAG,GAAGV,IAAI,CAACU,GAAG,CAACP,IAAI,CAAEH,IAAK,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMW,KAAK,GAAGX,IAAI,CAACW,KAAK,CAACR,IAAI,CAAEH,IAAK,CAAC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMY,cAAc,GAAGZ,IAAI,CAACY,cAAc,CAACT,IAAI,CAAEH,IAAK,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createI18n","defaultHooks","i18n","undefined","getLocaleData","bind","setLocaleData","resetLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/default-i18n.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createI18n } from './create-i18n';\n\n/**\n * WordPress dependencies\n */\nimport { defaultHooks } from '@wordpress/hooks';\n\nconst i18n = createI18n( undefined, undefined, defaultHooks );\n\n/**\n * Default, singleton instance of `I18n`.\n */\nexport default i18n;\n\n/*\n * Comments in this file are duplicated from ./i18n due to\n * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722\n */\n\n/**\n * @typedef {import('./create-i18n').LocaleData} LocaleData\n * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback\n * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback\n */\n\n/**\n * Returns locale data by domain in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {string} [domain] Domain for which to get the data.\n * @return {LocaleData} Locale data.\n */\nexport const getLocaleData = i18n.getLocaleData.bind( i18n );\n\n/**\n * Merges locale data into the Tannin instance by domain. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const setLocaleData = i18n.setLocaleData.bind( i18n );\n\n/**\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const resetLocaleData = i18n.resetLocaleData.bind( i18n );\n\n/**\n * Subscribes to changes of locale data\n *\n * @param {SubscribeCallback} callback Subscription callback\n * @return {UnsubscribeCallback} Unsubscribe callback\n */\nexport const subscribe = i18n.subscribe.bind( i18n );\n\n/**\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n *\n * @template {string} Text\n *\n * @param {Text} text Text to translate.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Text >} Translated text.\n */\nexport const __ = i18n.__.bind( i18n );\n\n/**\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n *\n * @template {string} Text\n *\n * @param {Text} text Text to translate.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Text >} Translated context string without pipe.\n */\nexport const _x = i18n._x.bind( i18n );\n\n/**\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n *\n * @template {string} Single\n * @template {string} Plural\n *\n * @param {Single} single The text to be used if the number is singular.\n * @param {Plural} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.\n */\nexport const _n = i18n._n.bind( i18n );\n\n/**\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n *\n * @template {string} Single\n * @template {string} Plural\n *\n * @param {Single} single The text to be used if the number is singular.\n * @param {Plural} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.\n */\nexport const _nx = i18n._nx.bind( i18n );\n\n/**\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n *\n * @return {boolean} Whether locale is RTL.\n */\nexport const isRTL = i18n.isRTL.bind( i18n );\n\n/**\n * Check if there is a translation for a given string (in singular form).\n *\n * @param {string} single Singular form of the string to look up.\n * @param {string} [context] Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n * @return {boolean} Whether the translation exists or not.\n */\nexport const hasTranslation = i18n.hasTranslation.bind( i18n );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,eAAe;;AAE1C;AACA;AACA;AACA,SAASC,YAAY,QAAQ,kBAAkB;AAE/C,MAAMC,IAAI,GAAGF,UAAU,CAAEG,SAAS,EAAEA,SAAS,EAAEF,YAAa,CAAC;;AAE7D;AACA;AACA;AACA,eAAeC,IAAI;;AAEnB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,aAAa,GAAGF,IAAI,CAACE,aAAa,CAACC,IAAI,CAAEH,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,aAAa,GAAGJ,IAAI,CAACI,aAAa,CAACD,IAAI,CAAEH,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMK,eAAe,GAAGL,IAAI,CAACK,eAAe,CAACF,IAAI,CAAEH,IAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,SAAS,GAAGN,IAAI,CAACM,SAAS,CAACH,IAAI,CAAEH,IAAK,CAAC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMO,EAAE,GAAGP,IAAI,CAACO,EAAE,CAACJ,IAAI,CAAEH,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMQ,EAAE,GAAGR,IAAI,CAACQ,EAAE,CAACL,IAAI,CAAEH,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMS,EAAE,GAAGT,IAAI,CAACS,EAAE,CAACN,IAAI,CAAEH,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMU,GAAG,GAAGV,IAAI,CAACU,GAAG,CAACP,IAAI,CAAEH,IAAK,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMW,KAAK,GAAGX,IAAI,CAACW,KAAK,CAACR,IAAI,CAAEH,IAAK,CAAC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMY,cAAc,GAAGZ,IAAI,CAACY,cAAc,CAACT,IAAI,CAAEH,IAAK,CAAC","ignoreList":[]}
@@ -1,37 +1,26 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import memoize from 'memize';
5
- import sprintfjs from 'sprintf-js';
4
+ // Disable reason: `eslint-plugin-import` doesn't support `exports` (https://github.com/import-js/eslint-plugin-import/issues/1810)
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import _sprintf from '@tannin/sprintf';
6
7
 
7
8
  /**
8
- * Log to console, once per message; or more precisely, per referentially equal
9
- * argument set. Because Jed throws errors, we log these to the console instead
10
- * to avoid crashing the application.
11
- *
12
- * @param {...*} args Arguments to pass to `console.error`
9
+ * Internal dependencies
13
10
  */
14
- const logErrorOnce = memoize(console.error); // eslint-disable-line no-console
15
11
 
16
12
  /**
17
- * Returns a formatted string. If an error occurs in applying the format, the
18
- * original format string is returned.
13
+ * Returns a formatted string.
19
14
  *
20
- * @param {string} format The format of the string to generate.
21
- * @param {...*} args Arguments to apply to the format.
15
+ * @template {string} T
16
+ * @param {T | TranslatableText<T>} format The format of the string to generate.
17
+ * @param {DistributeSprintfArgs<T>} args Arguments to apply to the format.
22
18
  *
23
- * @see https://www.npmjs.com/package/sprintf-js
19
+ * @see https://www.npmjs.com/package/@tannin/sprintf
24
20
  *
25
21
  * @return {string} The formatted string.
26
22
  */
27
23
  export function sprintf(format, ...args) {
28
- try {
29
- return sprintfjs.sprintf(format, ...args);
30
- } catch (error) {
31
- if (error instanceof Error) {
32
- logErrorOnce('sprintf error: \n\n' + error.toString());
33
- }
34
- return format;
35
- }
24
+ return _sprintf(format, ...args);
36
25
  }
37
26
  //# sourceMappingURL=sprintf.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["memoize","sprintfjs","logErrorOnce","console","error","sprintf","format","args","Error","toString"],"sources":["@wordpress/i18n/src/sprintf.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\nimport sprintfjs from 'sprintf-js';\n\n/**\n * Log to console, once per message; or more precisely, per referentially equal\n * argument set. Because Jed throws errors, we log these to the console instead\n * to avoid crashing the application.\n *\n * @param {...*} args Arguments to pass to `console.error`\n */\nconst logErrorOnce = memoize( console.error ); // eslint-disable-line no-console\n\n/**\n * Returns a formatted string. If an error occurs in applying the format, the\n * original format string is returned.\n *\n * @param {string} format The format of the string to generate.\n * @param {...*} args Arguments to apply to the format.\n *\n * @see https://www.npmjs.com/package/sprintf-js\n *\n * @return {string} The formatted string.\n */\nexport function sprintf( format, ...args ) {\n\ttry {\n\t\treturn sprintfjs.sprintf( format, ...args );\n\t} catch ( error ) {\n\t\tif ( error instanceof Error ) {\n\t\t\tlogErrorOnce( 'sprintf error: \\n\\n' + error.toString() );\n\t\t}\n\t\treturn format;\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,QAAQ;AAC5B,OAAOC,SAAS,MAAM,YAAY;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAGF,OAAO,CAAEG,OAAO,CAACC,KAAM,CAAC,CAAC,CAAC;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAAEC,MAAM,EAAE,GAAGC,IAAI,EAAG;EAC1C,IAAI;IACH,OAAON,SAAS,CAACI,OAAO,CAAEC,MAAM,EAAE,GAAGC,IAAK,CAAC;EAC5C,CAAC,CAAC,OAAQH,KAAK,EAAG;IACjB,IAAKA,KAAK,YAAYI,KAAK,EAAG;MAC7BN,YAAY,CAAE,qBAAqB,GAAGE,KAAK,CAACK,QAAQ,CAAC,CAAE,CAAC;IACzD;IACA,OAAOH,MAAM;EACd;AACD","ignoreList":[]}
1
+ {"version":3,"names":["_sprintf","sprintf","format","args"],"sources":["@wordpress/i18n/src/sprintf.ts"],"sourcesContent":["/**\n * External dependencies\n */\n// Disable reason: `eslint-plugin-import` doesn't support `exports` (https://github.com/import-js/eslint-plugin-import/issues/1810)\n// eslint-disable-next-line import/no-unresolved\nimport _sprintf from '@tannin/sprintf';\nimport type { SprintfArgs } from '@tannin/sprintf/types';\n\n/**\n * Internal dependencies\n */\nimport type { TranslatableText } from './types';\n\ntype DistributeSprintfArgs< T extends string > = T extends any\n\t? SprintfArgs< T >\n\t: never;\n\nexport function sprintf< T extends string >(\n\tformat: T | TranslatableText< T >,\n\t...args: DistributeSprintfArgs< T >\n): string;\nexport function sprintf< T extends string >(\n\tformat: T | TranslatableText< T >,\n\targs: DistributeSprintfArgs< T >\n): string;\n\n/**\n * Returns a formatted string.\n *\n * @template {string} T\n * @param {T | TranslatableText<T>} format The format of the string to generate.\n * @param {DistributeSprintfArgs<T>} args Arguments to apply to the format.\n *\n * @see https://www.npmjs.com/package/@tannin/sprintf\n *\n * @return {string} The formatted string.\n */\nexport function sprintf< T extends string >(\n\tformat: T | TranslatableText< T >,\n\t...args: DistributeSprintfArgs< T >\n): string {\n\treturn _sprintf( format as T, ...( args as DistributeSprintfArgs< T > ) );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,iBAAiB;;AAGtC;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CACtBC,MAAiC,EACjC,GAAGC,IAAgC,EAC1B;EACT,OAAOH,QAAQ,CAAEE,MAAM,EAAO,GAAKC,IAAqC,CAAC;AAC1E","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["@wordpress/i18n/src/types.ts"],"sourcesContent":["/**\n * Return type for string translation functions.\n *\n * This type should be treated as if it were `string`.\n */\nexport type TranslatableText< T extends string > = string & {\n\t/**\n\t * DO NOT USE! This property _does not exist_.\n\t * @private\n\t */\n\treadonly __translatableText: T;\n};\n"],"mappings":"","ignoreList":[]}
@@ -35,21 +35,21 @@ export type GetFilterDomain = (domain?: string) => string;
35
35
  /**
36
36
  * Retrieve the translation of text.
37
37
  */
38
- export type __ = (text: string, domain?: string) => string;
38
+ export type __ = <Text extends string>(text: Text, domain?: string) => import("./types").TranslatableText<Text>;
39
39
  /**
40
40
  * Retrieve translated string with gettext context.
41
41
  */
42
- export type _x = (text: string, context: string, domain?: string) => string;
42
+ export type _x = <Text extends string>(text: Text, context: string, domain?: string) => import("./types").TranslatableText<Text>;
43
43
  /**
44
44
  * Translates and retrieves the singular or plural form based on the supplied
45
45
  * number.
46
46
  */
47
- export type _n = (single: string, plural: string, number: number, domain?: string) => string;
47
+ export type _n = <Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string) => import("./types").TranslatableText<Single | Plural>;
48
48
  /**
49
49
  * Translates and retrieves the singular or plural form based on the supplied
50
50
  * number, with gettext context.
51
51
  */
52
- export type _nx = (single: string, plural: string, number: number, context: string, domain?: string) => string;
52
+ export type _nx = <Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: string) => import("./types").TranslatableText<Single | Plural>;
53
53
  /**
54
54
  * Check if current locale is RTL.
55
55
  *
@@ -1 +1 @@
1
- {"version":3,"file":"create-i18n.d.ts","sourceRoot":"","sources":["../src/create-i18n.js"],"names":[],"mappings":"AA2JO,yCANI,UAAU,kBACV,MAAM,UACN,KAAK,GAEJ,IAAI,CAgWf;yBAnfY,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC;;;;;4BAyBlB,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,UAAU;;;;;;4BAQ/B,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI;;;;;;4BAS5C,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI;;;;;8BAS5C,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI;gCAO3C,MAAM,IAAI;kCACV,MAAM,IAAI;;;;wBAEX,CAAC,QAAQ,EAAE,iBAAiB,KAAK,mBAAmB;;;;8BAKpD,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM;;;;iBAI3B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM;;;;iBAOzC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM;;;;;iBAO1D,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM;;;;;kBAQ3E,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM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AAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,SAAS,EAAE,gBAAgB,CAAE,IAAI,CAAE;;;;;iBAOjH,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,SAAS,EAAE,gBAAgB,CAAE,MAAM,GAAG,MAAM,CAAE;;;;;kBAQxK,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,SAAS,EAAE,gBAAgB,CAAE,MAAM,GAAG,MAAM,CAAE;;;;;;;;;oBAQzL,MAAM,OAAO;;;;6BAUb,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,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"}
@@ -45,10 +45,12 @@ export const subscribe: import("./create-i18n").Subscribe;
45
45
  *
46
46
  * @see https://developer.wordpress.org/reference/functions/__/
47
47
  *
48
- * @param {string} text Text to translate.
48
+ * @template {string} Text
49
+ *
50
+ * @param {Text} text Text to translate.
49
51
  * @param {string} [domain] Domain to retrieve the translated text.
50
52
  *
51
- * @return {string} Translated text.
53
+ * @return {import('./types').TranslatableText< Text >} Translated text.
52
54
  */
53
55
  export const __: import("./create-i18n").__;
54
56
  /**
@@ -56,11 +58,13 @@ export const __: import("./create-i18n").__;
56
58
  *
57
59
  * @see https://developer.wordpress.org/reference/functions/_x/
58
60
  *
59
- * @param {string} text Text to translate.
61
+ * @template {string} Text
62
+ *
63
+ * @param {Text} text Text to translate.
60
64
  * @param {string} context Context information for the translators.
61
65
  * @param {string} [domain] Domain to retrieve the translated text.
62
66
  *
63
- * @return {string} Translated context string without pipe.
67
+ * @return {import('./types').TranslatableText< Text >} Translated context string without pipe.
64
68
  */
65
69
  export const _x: import("./create-i18n")._x;
66
70
  /**
@@ -69,13 +73,16 @@ export const _x: import("./create-i18n")._x;
69
73
  *
70
74
  * @see https://developer.wordpress.org/reference/functions/_n/
71
75
  *
72
- * @param {string} single The text to be used if the number is singular.
73
- * @param {string} plural The text to be used if the number is plural.
76
+ * @template {string} Single
77
+ * @template {string} Plural
78
+ *
79
+ * @param {Single} single The text to be used if the number is singular.
80
+ * @param {Plural} plural The text to be used if the number is plural.
74
81
  * @param {number} number The number to compare against to use either the
75
82
  * singular or plural form.
76
83
  * @param {string} [domain] Domain to retrieve the translated text.
77
84
  *
78
- * @return {string} The translated singular or plural form.
85
+ * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.
79
86
  */
80
87
  export const _n: import("./create-i18n")._n;
81
88
  /**
@@ -84,14 +91,17 @@ export const _n: import("./create-i18n")._n;
84
91
  *
85
92
  * @see https://developer.wordpress.org/reference/functions/_nx/
86
93
  *
87
- * @param {string} single The text to be used if the number is singular.
88
- * @param {string} plural The text to be used if the number is plural.
94
+ * @template {string} Single
95
+ * @template {string} Plural
96
+ *
97
+ * @param {Single} single The text to be used if the number is singular.
98
+ * @param {Plural} plural The text to be used if the number is plural.
89
99
  * @param {number} number The number to compare against to use either the
90
100
  * singular or plural form.
91
101
  * @param {string} context Context information for the translators.
92
102
  * @param {string} [domain] Domain to retrieve the translated text.
93
103
  *
94
- * @return {string} The translated singular or plural form.
104
+ * @return {import('./types').TranslatableText< Single | Plural >} The translated singular or plural form.
95
105
  */
96
106
  export const _nx: import("./create-i18n")._nx;
97
107
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"default-i18n.d.ts","sourceRoot":"","sources":["../src/default-i18n.js"],"names":[],"mappings":";AAsBA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,kEAA6D;AAE7D;;;;;;;;GAQG;AACH,kEAA6D;AAE7D;;;;;;;;GAQG;AACH,sEAAiE;AAEjE;;;;;GAKG;AACH,0DAAqD;AAErD;;;;;;;;;GASG;AACH,4CAAuC;AAEvC;;;;;;;;;;GAUG;AACH,4CAAuC;AAEvC;;;;;;;;;;;;;GAaG;AACH,4CAAuC;AAEvC;;;;;;;;;;;;;;GAcG;AACH,8CAAyC;AAEzC;;;;;;;;;GASG;AACH,kDAA6C;AAE7C;;;;;;;GAOG;AACH,oEAA+D;yBA3HlD,OAAO,eAAe,EAAE,UAAU;gCAClC,OAAO,eAAe,EAAE,iBAAiB;kCACzC,OAAO,eAAe,EAAE,mBAAmB;AAfxD,iDAA8D"}
1
+ {"version":3,"file":"default-i18n.d.ts","sourceRoot":"","sources":["../src/default-i18n.js"],"names":[],"mappings":";AAsBA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,kEAA6D;AAE7D;;;;;;;;GAQG;AACH,kEAA6D;AAE7D;;;;;;;;GAQG;AACH,sEAAiE;AAEjE;;;;;GAKG;AACH,0DAAqD;AAErD;;;;;;;;;;;GAWG;AACH,4CAAuC;AAEvC;;;;;;;;;;;;GAYG;AACH,4CAAuC;AAEvC;;;;;;;;;;;;;;;;GAgBG;AACH,4CAAuC;AAEvC;;;;;;;;;;;;;;;;;GAiBG;AACH,8CAAyC;AAEzC;;;;;;;;;GASG;AACH,kDAA6C;AAE7C;;;;;;;GAOG;AACH,oEAA+D;yBArIlD,OAAO,eAAe,EAAE,UAAU;gCAClC,OAAO,eAAe,EAAE,iBAAiB;kCACzC,OAAO,eAAe,EAAE,mBAAmB;AAfxD,iDAA8D"}
@@ -1,13 +1,10 @@
1
+ import type { SprintfArgs } from '@tannin/sprintf/types';
1
2
  /**
2
- * Returns a formatted string. If an error occurs in applying the format, the
3
- * original format string is returned.
4
- *
5
- * @param {string} format The format of the string to generate.
6
- * @param {...*} args Arguments to apply to the format.
7
- *
8
- * @see https://www.npmjs.com/package/sprintf-js
9
- *
10
- * @return {string} The formatted string.
3
+ * Internal dependencies
11
4
  */
12
- export function sprintf(format: string, ...args: any[]): string;
5
+ import type { TranslatableText } from './types';
6
+ type DistributeSprintfArgs<T extends string> = T extends any ? SprintfArgs<T> : never;
7
+ export declare function sprintf<T extends string>(format: T | TranslatableText<T>, ...args: DistributeSprintfArgs<T>): string;
8
+ export declare function sprintf<T extends string>(format: T | TranslatableText<T>, args: DistributeSprintfArgs<T>): string;
9
+ export {};
13
10
  //# sourceMappingURL=sprintf.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sprintf.d.ts","sourceRoot":"","sources":["../src/sprintf.js"],"names":[],"mappings":"AAeA;;;;;;;;;;GAUG;AACH,gCAPW,MAAM,WACH,GAAC,EAAA,GAIH,MAAM,CAWjB"}
1
+ {"version":3,"file":"sprintf.d.ts","sourceRoot":"","sources":["../src/sprintf.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;GAEG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,KAAK,qBAAqB,CAAE,CAAC,SAAS,MAAM,IAAK,CAAC,SAAS,GAAG,GAC3D,WAAW,CAAE,CAAC,CAAE,GAChB,KAAK,CAAC;AAET,wBAAgB,OAAO,CAAE,CAAC,SAAS,MAAM,EACxC,MAAM,EAAE,CAAC,GAAG,gBAAgB,CAAE,CAAC,CAAE,EACjC,GAAG,IAAI,EAAE,qBAAqB,CAAE,CAAC,CAAE,GACjC,MAAM,CAAC;AACV,wBAAgB,OAAO,CAAE,CAAC,SAAS,MAAM,EACxC,MAAM,EAAE,CAAC,GAAG,gBAAgB,CAAE,CAAC,CAAE,EACjC,IAAI,EAAE,qBAAqB,CAAE,CAAC,CAAE,GAC9B,MAAM,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Return type for string translation functions.
3
+ *
4
+ * This type should be treated as if it were `string`.
5
+ */
6
+ export type TranslatableText<T extends string> = string & {
7
+ /**
8
+ * DO NOT USE! This property _does not exist_.
9
+ * @private
10
+ */
11
+ readonly __translatableText: T;
12
+ };
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAE,CAAC,SAAS,MAAM,IAAK,MAAM,GAAG;IAC3D;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAC/B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/i18n",
3
- "version": "5.25.0",
3
+ "version": "6.0.0",
4
4
  "description": "WordPress internationalization (i18n) library.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,14 +32,14 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/runtime": "7.25.7",
35
- "@wordpress/hooks": "^4.25.0",
35
+ "@tannin/sprintf": "^1.3.1",
36
+ "@wordpress/hooks": "^4.27.0",
36
37
  "gettext-parser": "^1.3.1",
37
38
  "memize": "^2.1.0",
38
- "sprintf-js": "^1.1.1",
39
39
  "tannin": "^1.2.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "d1acd76ffff33ab01f0a948d2f51e5e45c95158d"
44
+ "gitHead": "abe06a6f2aef8d03c30ea9d5b3e133f041e523b1"
45
45
  }
@@ -74,21 +74,21 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
74
74
  * Retrieve the domain to use when calling domain-specific filters.
75
75
  */
76
76
  /**
77
- * @typedef {(text: string, domain?: string) => string} __
77
+ * @typedef {<Text extends string>(text: Text, domain?: string) => import('./types').TranslatableText< Text >} __
78
78
  *
79
79
  * Retrieve the translation of text.
80
80
  *
81
81
  * @see https://developer.wordpress.org/reference/functions/__/
82
82
  */
83
83
  /**
84
- * @typedef {(text: string, context: string, domain?: string) => string} _x
84
+ * @typedef {<Text extends string>(text: Text, context: string, domain?: string) => import('./types').TranslatableText< Text >} _x
85
85
  *
86
86
  * Retrieve translated string with gettext context.
87
87
  *
88
88
  * @see https://developer.wordpress.org/reference/functions/_x/
89
89
  */
90
90
  /**
91
- * @typedef {(single: string, plural: string, number: number, domain?: string) => string} _n
91
+ * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string) => import('./types').TranslatableText< Single | Plural >} _n
92
92
  *
93
93
  * Translates and retrieves the singular or plural form based on the supplied
94
94
  * number.
@@ -96,7 +96,7 @@ const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
96
96
  * @see https://developer.wordpress.org/reference/functions/_n/
97
97
  */
98
98
  /**
99
- * @typedef {(single: string, plural: string, number: number, context: string, domain?: string) => string} _nx
99
+ * @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: string) => import('./types').TranslatableText< Single | Plural >} _nx
100
100
  *
101
101
  * Translates and retrieves the singular or plural form based on the supplied
102
102
  * number, with gettext context.
@@ -276,7 +276,9 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
276
276
  const __ = ( text, domain ) => {
277
277
  let translation = dcnpgettext( domain, undefined, text );
278
278
  if ( ! hooks ) {
279
- return translation;
279
+ return /** @type {import('./types').TranslatableText<typeof text>} */ (
280
+ translation
281
+ );
280
282
  }
281
283
 
282
284
  /**
@@ -294,7 +296,7 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
294
296
  domain
295
297
  )
296
298
  );
297
- return /** @type {string} */ (
299
+ return /** @type {import('./types').TranslatableText<typeof text>} */ (
298
300
  /** @type {*} */ hooks.applyFilters(
299
301
  'i18n.gettext_' + getFilterDomain( domain ),
300
302
  translation,
@@ -308,7 +310,9 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
308
310
  const _x = ( text, context, domain ) => {
309
311
  let translation = dcnpgettext( domain, context, text );
310
312
  if ( ! hooks ) {
311
- return translation;
313
+ return /** @type {import('./types').TranslatableText<typeof text>} */ (
314
+ translation
315
+ );
312
316
  }
313
317
 
314
318
  /**
@@ -328,7 +332,7 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
328
332
  domain
329
333
  )
330
334
  );
331
- return /** @type {string} */ (
335
+ return /** @type {import('./types').TranslatableText<typeof text>} */ (
332
336
  /** @type {*} */ hooks.applyFilters(
333
337
  'i18n.gettext_with_context_' + getFilterDomain( domain ),
334
338
  translation,
@@ -349,7 +353,9 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
349
353
  number
350
354
  );
351
355
  if ( ! hooks ) {
352
- return translation;
356
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (
357
+ translation
358
+ );
353
359
  }
354
360
 
355
361
  /**
@@ -371,7 +377,7 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
371
377
  domain
372
378
  )
373
379
  );
374
- return /** @type {string} */ (
380
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (
375
381
  /** @type {*} */ hooks.applyFilters(
376
382
  'i18n.ngettext_' + getFilterDomain( domain ),
377
383
  translation,
@@ -393,7 +399,9 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
393
399
  number
394
400
  );
395
401
  if ( ! hooks ) {
396
- return translation;
402
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (
403
+ translation
404
+ );
397
405
  }
398
406
 
399
407
  /**
@@ -418,7 +426,7 @@ export const createI18n = ( initialData, initialDomain, hooks ) => {
418
426
  )
419
427
  );
420
428
 
421
- return /** @type {string} */ (
429
+ return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ (
422
430
  /** @type {*} */ hooks.applyFilters(
423
431
  'i18n.ngettext_with_context_' + getFilterDomain( domain ),
424
432
  translation,