@wordpress/i18n 5.26.0 → 6.0.1-next.46f643fa0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +28 -27
  3. package/build/create-i18n.js +56 -201
  4. package/build/create-i18n.js.map +1 -1
  5. package/build/default-i18n.js +41 -34
  6. package/build/default-i18n.js.map +1 -1
  7. package/build/index.js.map +1 -1
  8. package/build/sprintf.js +10 -22
  9. package/build/sprintf.js.map +1 -1
  10. package/build/types.js +6 -0
  11. package/build/types.js.map +1 -0
  12. package/build-module/create-i18n.js +56 -201
  13. package/build-module/create-i18n.js.map +1 -1
  14. package/build-module/default-i18n.js +41 -35
  15. package/build-module/default-i18n.js.map +1 -1
  16. package/build-module/index.js.map +1 -1
  17. package/build-module/sprintf.js +10 -22
  18. package/build-module/sprintf.js.map +1 -1
  19. package/build-module/types.js +2 -0
  20. package/build-module/types.js.map +1 -0
  21. package/build-types/create-i18n.d.ts +11 -115
  22. package/build-types/create-i18n.d.ts.map +1 -1
  23. package/build-types/default-i18n.d.ts +55 -47
  24. package/build-types/default-i18n.d.ts.map +1 -1
  25. package/build-types/index.d.ts +4 -3
  26. package/build-types/index.d.ts.map +1 -1
  27. package/build-types/sprintf.d.ts +4 -10
  28. package/build-types/sprintf.d.ts.map +1 -1
  29. package/build-types/types.d.ts +114 -0
  30. package/build-types/types.d.ts.map +1 -0
  31. package/package.json +4 -4
  32. package/src/create-i18n.ts +405 -0
  33. package/src/{default-i18n.js → default-i18n.ts} +47 -35
  34. package/src/index.ts +16 -0
  35. package/src/sprintf.ts +37 -0
  36. package/src/test/{create-i18n.js → create-i18n.ts} +63 -30
  37. package/src/test/{sprintf.js → sprintf.ts} +5 -10
  38. package/src/test/{subscribe-i18n.js → subscribe-i18n.ts} +3 -3
  39. package/src/types.ts +167 -0
  40. package/tsconfig.tsbuildinfo +1 -1
  41. package/src/create-i18n.js +0 -506
  42. package/src/sprintf.js +0 -36
  43. /package/src/test/{default-i18n.js → default-i18n.ts} +0 -0
@@ -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.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createI18n } from './create-i18n';\n\n/**\n * WordPress dependencies\n */\nimport { defaultHooks } from '@wordpress/hooks';\nimport {\n\tLocaleData,\n\tSubscribeCallback,\n\tTranslatableText,\n\tUnsubscribeCallback,\n} from './types';\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 * Returns locale data by domain in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param { string | undefined } [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 | undefined} [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 | undefined} [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 | undefined} domain Domain to retrieve the translated text.\n *\n * @return {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 | undefined} domain Domain to retrieve the translated text.\n *\n * @return {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 | undefined} domain Domain to retrieve the translated text.\n *\n * @return {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 * @param {Single} single The text to be used if the number is singular.\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 | undefined} [domain] Domain to retrieve the translated text.\n *\n * @return {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 *\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;AAQ/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;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;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;AACA,OAAO,MAAMY,cAAc,GAAGZ,IAAI,CAACY,cAAc,CAACT,IAAI,CAAEH,IAAK,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["sprintf","default","defaultI18n","setLocaleData","resetLocaleData","getLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/index.js"],"sourcesContent":["export { sprintf } from './sprintf';\nexport * from './create-i18n';\nexport {\n\tdefault as defaultI18n,\n\tsetLocaleData,\n\tresetLocaleData,\n\tgetLocaleData,\n\tsubscribe,\n\t__,\n\t_x,\n\t_n,\n\t_nx,\n\tisRTL,\n\thasTranslation,\n} from './default-i18n';\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,WAAW;AACnC,cAAc,eAAe;AAC7B,SACCC,OAAO,IAAIC,WAAW,EACtBC,aAAa,EACbC,eAAe,EACfC,aAAa,EACbC,SAAS,EACTC,EAAE,EACFC,EAAE,EACFC,EAAE,EACFC,GAAG,EACHC,KAAK,EACLC,cAAc,QACR,gBAAgB","ignoreList":[]}
1
+ {"version":3,"names":["sprintf","default","defaultI18n","setLocaleData","resetLocaleData","getLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/index.ts"],"sourcesContent":["export { sprintf } from './sprintf';\nexport * from './create-i18n';\nexport type * from './types';\nexport {\n\tdefault as defaultI18n,\n\tsetLocaleData,\n\tresetLocaleData,\n\tgetLocaleData,\n\tsubscribe,\n\t__,\n\t_x,\n\t_n,\n\t_nx,\n\tisRTL,\n\thasTranslation,\n} from './default-i18n';\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,WAAW;AACnC,cAAc,eAAe;AAE7B,SACCC,OAAO,IAAIC,WAAW,EACtBC,aAAa,EACbC,eAAe,EACfC,aAAa,EACbC,SAAS,EACTC,EAAE,EACFC,EAAE,EACFC,EAAE,EACFC,GAAG,EACHC,KAAK,EACLC,cAAc,QACR,gBAAgB","ignoreList":[]}
@@ -1,37 +1,25 @@
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
+ * @param format The format of the string to generate.
16
+ * @param args Arguments to apply to the format.
22
17
  *
23
- * @see https://www.npmjs.com/package/sprintf-js
18
+ * @see https://www.npmjs.com/package/@tannin/sprintf
24
19
  *
25
- * @return {string} The formatted string.
20
+ * @return The formatted string.
26
21
  */
27
22
  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
- }
23
+ return _sprintf(format, ...args);
36
24
  }
37
25
  //# 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';\n\n/**\n * Internal dependencies\n */\nimport type { DistributeSprintfArgs, TranslatableText } from './types';\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 * @param 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/@tannin/sprintf\n *\n * @return 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;;AAEtC;AACA;AACA;;AAYA;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 * External dependencies\n */\nimport type sprintf from '@tannin/sprintf';\nimport { type TanninDomainMetadata } from 'tannin';\n\n/**\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\n/**\n * Type to extends TanninDomainMetadata to support additional properties.\n */\nexport type I18nDomainMetadata< TextDomain extends string > =\n\tTanninDomainMetadata & {\n\t\tdomain?: TextDomain;\n\t\t[ key: string ]: unknown;\n\t};\n\n/**\n * Locale data is a record of domain names to their metadata or translations.\n */\nexport type LocaleData< TextDomain extends string = string > = Record<\n\tstring,\n\tI18nDomainMetadata< TextDomain > | string[]\n>;\n\nexport type SubscribeCallback = () => void;\nexport type UnsubscribeCallback = () => void;\n\n/**\n * Retrieve the domain to use when calling domain-specific filters.\n */\nexport type getFilterDomain = ( domain?: string ) => string;\n\n/**\n * An i18n instance\n */\nexport interface I18n< TextDomain extends string = string > {\n\t/**\n\t * Returns locale data by domain in a\n\t * Jed-formatted JSON object shape.\n\t *\n\t * @see http://messageformat.github.io/Jed/\n\t */\n\tgetLocaleData: ( domain?: TextDomain ) => LocaleData< TextDomain >;\n\n\t/**\n\t * Merges locale data into the Tannin instance by domain. Note that this\n\t * function will overwrite the domain configuration. Accepts data in a\n\t * Jed-formatted JSON object shape.\n\t *\n\t * @see http://messageformat.github.io/Jed/\n\t */\n\tsetLocaleData: (\n\t\tdata?: LocaleData< TextDomain >,\n\t\tdomain?: TextDomain\n\t) => void;\n\n\t/**\n\t * Merges locale data into the Tannin instance by domain. Note that this\n\t * function will also merge the domain configuration. Accepts data in a\n\t * Jed-formatted JSON object shape.\n\t *\n\t * @see http://messageformat.github.io/Jed/\n\t */\n\taddLocaleData: (\n\t\tdata?: LocaleData< TextDomain >,\n\t\tdomain?: TextDomain\n\t) => void;\n\n\t/**\n\t * Resets all current Tannin instance locale data and sets the specified\n\t * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n\t *\n\t * @see http://messageformat.github.io/Jed/\n\t */\n\tresetLocaleData: (\n\t\tdata?: LocaleData< TextDomain >,\n\t\tdomain?: TextDomain\n\t) => void;\n\n\t/**\n\t * Subscribes to changes of locale data\n\t */\n\tsubscribe: ( callback: SubscribeCallback ) => UnsubscribeCallback;\n\n\t/**\n\t * Retrieve the translation of text.\n\t *\n\t * @see https://developer.wordpress.org/reference/functions/__/\n\t */\n\t__: < Text extends string >(\n\t\ttext: Text,\n\t\tdomain?: TextDomain\n\t) => TranslatableText< Text >;\n\n\t/**\n\t * Retrieve translated string with gettext context.\n\t *\n\t * @see https://developer.wordpress.org/reference/functions/_x/\n\t */\n\t_x: < Text extends string >(\n\t\ttext: Text,\n\t\tcontext: string,\n\t\tdomain?: TextDomain\n\t) => TranslatableText< Text >;\n\n\t/**\n\t * Translates and retrieves the singular or plural form based on the supplied\n\t * number.\n\t *\n\t * @see https://developer.wordpress.org/reference/functions/_n/\n\t */\n\t_n: < Single extends string, Plural extends string >(\n\t\tsingle: Single,\n\t\tplural: Plural,\n\t\tnumber: number,\n\t\tdomain?: TextDomain\n\t) => TranslatableText< Single | Plural >;\n\n\t/**\n\t * Translates and retrieves the singular or plural form based on the supplied\n\t * number, with gettext context.\n\t *\n\t * @see https://developer.wordpress.org/reference/functions/_nx/\n\t */\n\t_nx: < Single extends string, Plural extends string >(\n\t\tsingle: Single,\n\t\tplural: Plural,\n\t\tnumber: number,\n\t\tcontext: string,\n\t\tdomain?: TextDomain\n\t) => TranslatableText< Single | Plural >;\n\n\t/**\n\t * Check if current locale is RTL.\n\t *\n\t * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n\t * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n\t * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n\t * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n\t */\n\tisRTL: () => boolean;\n\n\t/**\n\t * Check if there is a translation for a given string in singular form.\n\t */\n\thasTranslation: (\n\t\tsingle: string,\n\t\tcontext?: string,\n\t\tdomain?: TextDomain\n\t) => boolean;\n}\n\nexport type DistributeSprintfArgs< T extends string > = T extends any\n\t? Parameters< typeof sprintf< T > >[ 1 ]\n\t: never;\n"],"mappings":"","ignoreList":[]}
@@ -1,123 +1,19 @@
1
- export function createI18n(initialData?: LocaleData, initialDomain?: string, hooks?: Hooks): I18n;
2
- export type LocaleData = Record<string, any>;
3
1
  /**
4
- * Returns locale data by domain in a
5
- * Jed-formatted JSON object shape.
2
+ * Internal dependencies
6
3
  */
7
- export type GetLocaleData = (domain?: string) => LocaleData;
4
+ import type { I18n, LocaleData } from './types';
8
5
  /**
9
- * Merges locale data into the Tannin instance by domain. Note that this
10
- * function will overwrite the domain configuration. Accepts data in a
11
- * Jed-formatted JSON object shape.
6
+ * WordPress dependencies
12
7
  */
13
- export type SetLocaleData = (data?: LocaleData, domain?: string) => void;
8
+ import type { Hooks } from '@wordpress/hooks';
14
9
  /**
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, domain?: string) => void;
20
- /**
21
- * Resets all current Tannin instance locale data and sets the specified
22
- * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
23
- */
24
- export type ResetLocaleData = (data?: LocaleData, domain?: string) => void;
25
- export type SubscribeCallback = () => void;
26
- export type UnsubscribeCallback = () => void;
27
- /**
28
- * Subscribes to changes of locale data
29
- */
30
- export type Subscribe = (callback: SubscribeCallback) => UnsubscribeCallback;
31
- /**
32
- * Retrieve the domain to use when calling domain-specific filters.
33
- */
34
- export type GetFilterDomain = (domain?: string) => string;
35
- /**
36
- * Retrieve the translation of text.
37
- */
38
- export type __ = (text: string, domain?: string) => string;
39
- /**
40
- * Retrieve translated string with gettext context.
41
- */
42
- export type _x = (text: string, context: string, domain?: string) => string;
43
- /**
44
- * Translates and retrieves the singular or plural form based on the supplied
45
- * number.
46
- */
47
- export type _n = (single: string, plural: string, number: number, domain?: string) => string;
48
- /**
49
- * Translates and retrieves the singular or plural form based on the supplied
50
- * number, with gettext context.
51
- */
52
- export type _nx = (single: string, plural: string, number: number, context: string, domain?: string) => string;
53
- /**
54
- * Check if current locale is RTL.
10
+ * Create an i18n instance
55
11
  *
56
- * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
57
- * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
58
- * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
59
- * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
60
- */
61
- export type IsRtl = () => boolean;
62
- /**
63
- * Check if there is a translation for a given string in singular form.
64
- */
65
- export type HasTranslation = (single: string, context?: string, domain?: string) => boolean;
66
- export type Hooks = import("@wordpress/hooks").Hooks;
67
- /**
68
- * An i18n instance
12
+ * @param [initialData] Locale data configuration.
13
+ * @param [initialDomain] Domain for which configuration applies.
14
+ * @param [hooks] Hooks implementation.
15
+ *
16
+ * @return I18n instance.
69
17
  */
70
- export type I18n = {
71
- /**
72
- * Returns locale data by domain in a Jed-formatted JSON object shape.
73
- */
74
- getLocaleData: GetLocaleData;
75
- /**
76
- * Merges locale data into the Tannin instance by domain. Note that this
77
- * function will overwrite the domain configuration. Accepts data in a
78
- * Jed-formatted JSON object shape.
79
- */
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;
87
- /**
88
- * Resets all current Tannin instance locale data and sets the specified
89
- * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
90
- */
91
- resetLocaleData: ResetLocaleData;
92
- /**
93
- * Subscribes to changes of Tannin locale data.
94
- */
95
- subscribe: Subscribe;
96
- /**
97
- * Retrieve the translation of text.
98
- */
99
- __: __;
100
- /**
101
- * Retrieve translated string with gettext context.
102
- */
103
- _x: _x;
104
- /**
105
- * Translates and retrieves the singular or plural form based on the supplied
106
- * number.
107
- */
108
- _n: _n;
109
- /**
110
- * Translates and retrieves the singular or plural form based on the supplied
111
- * number, with gettext context.
112
- */
113
- _nx: _nx;
114
- /**
115
- * Check if current locale is RTL.
116
- */
117
- isRTL: IsRtl;
118
- /**
119
- * Check if there is a translation for a given string.
120
- */
121
- hasTranslation: HasTranslation;
122
- };
18
+ export declare const createI18n: <TextDomain extends string>(initialData?: LocaleData<TextDomain>, initialDomain?: TextDomain, hooks?: Hooks) => I18n<TextDomain>;
123
19
  //# sourceMappingURL=create-i18n.d.ts.map
@@ -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,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;;;eAEf,SAAS;;;;QACT,EAAE;;;;QACF,EAAE;;;;;QACF,EAAE;;;;;SAEF,GAAG;;;;WAEH,KAAK;;;;oBACL,cAAc"}
1
+ {"version":3,"file":"create-i18n.d.ts","sourceRoot":"","sources":["../src/create-i18n.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAEX,IAAI,EACJ,UAAU,EAIV,MAAM,SAAS,CAAC;AACjB;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAmB9C;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GAAK,UAAU,SAAS,MAAM,gBACtC,UAAU,CAAE,UAAU,CAAE,kBACtB,UAAU,UAClB,KAAK,KACX,IAAI,CAAE,UAAU,CAiWlB,CAAC"}
@@ -1,99 +1,110 @@
1
- export default i18n;
1
+ import { LocaleData, SubscribeCallback, TranslatableText, UnsubscribeCallback } from './types';
2
+ declare const i18n: import("./types").I18n<string>;
2
3
  /**
3
- * @typedef {import('./create-i18n').LocaleData} LocaleData
4
- * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback
5
- * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback
4
+ * Default, singleton instance of `I18n`.
6
5
  */
6
+ export default i18n;
7
7
  /**
8
8
  * Returns locale data by domain in a Jed-formatted JSON object shape.
9
9
  *
10
10
  * @see http://messageformat.github.io/Jed/
11
11
  *
12
- * @param {string} [domain] Domain for which to get the data.
13
- * @return {LocaleData} Locale data.
12
+ * @param { string | undefined } [domain] Domain for which to get the data.
13
+ * @return { LocaleData } Locale data.
14
14
  */
15
- export const getLocaleData: import("./create-i18n").GetLocaleData;
15
+ export declare const getLocaleData: (domain?: string | undefined) => LocaleData<string>;
16
16
  /**
17
17
  * Merges locale data into the Tannin instance by domain. Accepts data in a
18
18
  * Jed-formatted JSON object shape.
19
19
  *
20
20
  * @see http://messageformat.github.io/Jed/
21
21
  *
22
- * @param {LocaleData} [data] Locale data configuration.
23
- * @param {string} [domain] Domain for which configuration applies.
22
+ * @param {LocaleData } [data] Locale data configuration.
23
+ * @param {string | undefined} [domain] Domain for which configuration applies.
24
24
  */
25
- export const setLocaleData: import("./create-i18n").SetLocaleData;
25
+ export declare const setLocaleData: (data?: LocaleData<string> | undefined, domain?: string | undefined) => void;
26
26
  /**
27
27
  * Resets all current Tannin instance locale data and sets the specified
28
28
  * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
29
29
  *
30
30
  * @see http://messageformat.github.io/Jed/
31
31
  *
32
- * @param {LocaleData} [data] Locale data configuration.
33
- * @param {string} [domain] Domain for which configuration applies.
32
+ * @param {LocaleData} [data] Locale data configuration.
33
+ * @param {string | undefined} [domain] Domain for which configuration applies.
34
34
  */
35
- export const resetLocaleData: import("./create-i18n").ResetLocaleData;
35
+ export declare const resetLocaleData: (data?: LocaleData<string> | undefined, domain?: string | undefined) => void;
36
36
  /**
37
37
  * Subscribes to changes of locale data
38
38
  *
39
39
  * @param {SubscribeCallback} callback Subscription callback
40
40
  * @return {UnsubscribeCallback} Unsubscribe callback
41
41
  */
42
- export const subscribe: import("./create-i18n").Subscribe;
42
+ export declare const subscribe: (callback: SubscribeCallback) => UnsubscribeCallback;
43
43
  /**
44
44
  * Retrieve the translation of text.
45
45
  *
46
46
  * @see https://developer.wordpress.org/reference/functions/__/
47
47
  *
48
- * @param {string} text Text to translate.
49
- * @param {string} [domain] Domain to retrieve the translated text.
48
+ * @template {string} Text
50
49
  *
51
- * @return {string} Translated text.
50
+ * @param {Text} text Text to translate.
51
+ * @param {string | undefined} domain Domain to retrieve the translated text.
52
+ *
53
+ * @return {TranslatableText<Text>} Translated text.
52
54
  */
53
- export const __: import("./create-i18n").__;
55
+ export declare const __: <Text extends string>(text: Text, domain?: string | undefined) => TranslatableText<Text>;
54
56
  /**
55
57
  * Retrieve translated string with gettext context.
56
58
  *
57
59
  * @see https://developer.wordpress.org/reference/functions/_x/
58
60
  *
59
- * @param {string} text Text to translate.
60
- * @param {string} context Context information for the translators.
61
- * @param {string} [domain] Domain to retrieve the translated text.
61
+ * @template {string} Text
62
+ *
63
+ * @param {Text} text Text to translate.
64
+ * @param {string} context Context information for the translators.
65
+ * @param {string | undefined} domain Domain to retrieve the translated text.
62
66
  *
63
- * @return {string} Translated context string without pipe.
67
+ * @return {TranslatableText<Text>} Translated context string without pipe.
64
68
  */
65
- export const _x: import("./create-i18n")._x;
69
+ export declare const _x: <Text extends string>(text: Text, context: string, domain?: string | undefined) => TranslatableText<Text>;
66
70
  /**
67
71
  * Translates and retrieves the singular or plural form based on the supplied
68
72
  * number.
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.
74
- * @param {number} number The number to compare against to use either the
75
- * singular or plural form.
76
- * @param {string} [domain] Domain to retrieve the translated text.
76
+ * @template {string} Single
77
+ * @template {string} Plural
77
78
  *
78
- * @return {string} The translated singular or plural form.
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.
81
+ * @param {number} number The number to compare against to use either the
82
+ * singular or plural form.
83
+ * @param {string | undefined} domain Domain to retrieve the translated text.
84
+ *
85
+ * @return {TranslatableText<Single | Plural>} The translated singular or plural form.
79
86
  */
80
- export const _n: import("./create-i18n")._n;
87
+ export declare const _n: <Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string | undefined) => TranslatableText<Single | Plural>;
81
88
  /**
82
89
  * Translates and retrieves the singular or plural form based on the supplied
83
90
  * number, with gettext context.
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.
89
- * @param {number} number The number to compare against to use either the
90
- * singular or plural form.
91
- * @param {string} context Context information for the translators.
92
- * @param {string} [domain] Domain to retrieve the translated text.
94
+ * @template {string} Single
95
+ * @template {string} Plural
96
+ * @param {Single} single The text to be used if the number is singular.
97
+ *
98
+ * @param {Single} single The text to be used if the number is singular.
99
+ * @param {Plural} plural The text to be used if the number is plural.
100
+ * @param {number} number The number to compare against to use either the
101
+ * singular or plural form.
102
+ * @param {string} context Context information for the translators.
103
+ * @param {string | undefined} [domain] Domain to retrieve the translated text.
93
104
  *
94
- * @return {string} The translated singular or plural form.
105
+ * @return {TranslatableText<Single | Plural>} The translated singular or plural form.
95
106
  */
96
- export const _nx: import("./create-i18n")._nx;
107
+ export declare const _nx: <Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: string | undefined) => TranslatableText<Single | Plural>;
97
108
  /**
98
109
  * Check if current locale is RTL.
99
110
  *
@@ -104,18 +115,15 @@ export const _nx: import("./create-i18n")._nx;
104
115
  *
105
116
  * @return {boolean} Whether locale is RTL.
106
117
  */
107
- export const isRTL: import("./create-i18n").IsRtl;
118
+ export declare const isRTL: () => boolean;
108
119
  /**
109
120
  * Check if there is a translation for a given string (in singular form).
110
121
  *
111
- * @param {string} single Singular form of the string to look up.
112
- * @param {string} [context] Context information for the translators.
113
- * @param {string} [domain] Domain to retrieve the translated text.
122
+ * @param {string} single Singular form of the string to look up.
123
+ * @param {string} context Context information for the translators.
124
+ * @param {string} domain Domain to retrieve the translated text.
125
+ *
114
126
  * @return {boolean} Whether the translation exists or not.
115
127
  */
116
- export const hasTranslation: import("./create-i18n").HasTranslation;
117
- export type LocaleData = import("./create-i18n").LocaleData;
118
- export type SubscribeCallback = import("./create-i18n").SubscribeCallback;
119
- export type UnsubscribeCallback = import("./create-i18n").UnsubscribeCallback;
120
- declare const i18n: import("./create-i18n").I18n;
128
+ export declare const hasTranslation: (single: string, context?: string, domain?: string | undefined) => boolean;
121
129
  //# sourceMappingURL=default-i18n.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"default-i18n.d.ts","sourceRoot":"","sources":["../src/default-i18n.js"],"names":[],"mappings":";AAsBA;;;;GAIG;AAEH;;;;;;;GAOG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,KAAK,eAA0B,CAAC;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,4EAAmC,CAAC"}
@@ -1,4 +1,5 @@
1
- export { sprintf } from "./sprintf";
2
- export * from "./create-i18n";
3
- export { default as defaultI18n, setLocaleData, resetLocaleData, getLocaleData, subscribe, __, _x, _n, _nx, isRTL, hasTranslation } from "./default-i18n";
1
+ export { sprintf } from './sprintf';
2
+ export * from './create-i18n';
3
+ export type * from './types';
4
+ export { default as defaultI18n, setLocaleData, resetLocaleData, getLocaleData, subscribe, __, _x, _n, _nx, isRTL, hasTranslation, } from './default-i18n';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,mBAAmB,SAAS,CAAC;AAC7B,OAAO,EACN,OAAO,IAAI,WAAW,EACtB,aAAa,EACb,eAAe,EACf,aAAa,EACb,SAAS,EACT,EAAE,EACF,EAAE,EACF,EAAE,EACF,GAAG,EACH,KAAK,EACL,cAAc,GACd,MAAM,gBAAgB,CAAC"}
@@ -1,13 +1,7 @@
1
1
  /**
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.
2
+ * Internal dependencies
11
3
  */
12
- export function sprintf(format: string, ...args: any[]): string;
4
+ import type { DistributeSprintfArgs, TranslatableText } from './types';
5
+ export declare function sprintf<T extends string>(format: T | TranslatableText<T>, ...args: DistributeSprintfArgs<T>): string;
6
+ export declare function sprintf<T extends string>(format: T | TranslatableText<T>, args: DistributeSprintfArgs<T>): string;
13
7
  //# 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":"AAOA;;GAEG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEvE,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,114 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type sprintf from '@tannin/sprintf';
5
+ import { type TanninDomainMetadata } from 'tannin';
6
+ /**
7
+ * Return type for string translation functions.
8
+ *
9
+ * This type should be treated as if it were `string`.
10
+ */
11
+ export type TranslatableText<T extends string> = string & {
12
+ /**
13
+ * DO NOT USE! This property _does not exist_.
14
+ * @private
15
+ */
16
+ readonly __translatableText: T;
17
+ };
18
+ /**
19
+ * Type to extends TanninDomainMetadata to support additional properties.
20
+ */
21
+ export type I18nDomainMetadata<TextDomain extends string> = TanninDomainMetadata & {
22
+ domain?: TextDomain;
23
+ [key: string]: unknown;
24
+ };
25
+ /**
26
+ * Locale data is a record of domain names to their metadata or translations.
27
+ */
28
+ export type LocaleData<TextDomain extends string = string> = Record<string, I18nDomainMetadata<TextDomain> | string[]>;
29
+ export type SubscribeCallback = () => void;
30
+ export type UnsubscribeCallback = () => void;
31
+ /**
32
+ * Retrieve the domain to use when calling domain-specific filters.
33
+ */
34
+ export type getFilterDomain = (domain?: string) => string;
35
+ /**
36
+ * An i18n instance
37
+ */
38
+ export interface I18n<TextDomain extends string = string> {
39
+ /**
40
+ * Returns locale data by domain in a
41
+ * Jed-formatted JSON object shape.
42
+ *
43
+ * @see http://messageformat.github.io/Jed/
44
+ */
45
+ getLocaleData: (domain?: TextDomain) => LocaleData<TextDomain>;
46
+ /**
47
+ * Merges locale data into the Tannin instance by domain. Note that this
48
+ * function will overwrite the domain configuration. Accepts data in a
49
+ * Jed-formatted JSON object shape.
50
+ *
51
+ * @see http://messageformat.github.io/Jed/
52
+ */
53
+ setLocaleData: (data?: LocaleData<TextDomain>, domain?: TextDomain) => void;
54
+ /**
55
+ * Merges locale data into the Tannin instance by domain. Note that this
56
+ * function will also merge the domain configuration. Accepts data in a
57
+ * Jed-formatted JSON object shape.
58
+ *
59
+ * @see http://messageformat.github.io/Jed/
60
+ */
61
+ addLocaleData: (data?: LocaleData<TextDomain>, domain?: TextDomain) => void;
62
+ /**
63
+ * Resets all current Tannin instance locale data and sets the specified
64
+ * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
65
+ *
66
+ * @see http://messageformat.github.io/Jed/
67
+ */
68
+ resetLocaleData: (data?: LocaleData<TextDomain>, domain?: TextDomain) => void;
69
+ /**
70
+ * Subscribes to changes of locale data
71
+ */
72
+ subscribe: (callback: SubscribeCallback) => UnsubscribeCallback;
73
+ /**
74
+ * Retrieve the translation of text.
75
+ *
76
+ * @see https://developer.wordpress.org/reference/functions/__/
77
+ */
78
+ __: <Text extends string>(text: Text, domain?: TextDomain) => TranslatableText<Text>;
79
+ /**
80
+ * Retrieve translated string with gettext context.
81
+ *
82
+ * @see https://developer.wordpress.org/reference/functions/_x/
83
+ */
84
+ _x: <Text extends string>(text: Text, context: string, domain?: TextDomain) => TranslatableText<Text>;
85
+ /**
86
+ * Translates and retrieves the singular or plural form based on the supplied
87
+ * number.
88
+ *
89
+ * @see https://developer.wordpress.org/reference/functions/_n/
90
+ */
91
+ _n: <Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: TextDomain) => TranslatableText<Single | Plural>;
92
+ /**
93
+ * Translates and retrieves the singular or plural form based on the supplied
94
+ * number, with gettext context.
95
+ *
96
+ * @see https://developer.wordpress.org/reference/functions/_nx/
97
+ */
98
+ _nx: <Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, context: string, domain?: TextDomain) => TranslatableText<Single | Plural>;
99
+ /**
100
+ * Check if current locale is RTL.
101
+ *
102
+ * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
103
+ * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
104
+ * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
105
+ * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
106
+ */
107
+ isRTL: () => boolean;
108
+ /**
109
+ * Check if there is a translation for a given string in singular form.
110
+ */
111
+ hasTranslation: (single: string, context?: string, domain?: TextDomain) => boolean;
112
+ }
113
+ export type DistributeSprintfArgs<T extends string> = T extends any ? Parameters<typeof sprintf<T>>[1] : never;
114
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAE,CAAC,SAAS,MAAM,IAAK,MAAM,GAAG;IAC3D;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAE,UAAU,SAAS,MAAM,I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