@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
@@ -24,18 +24,13 @@ var _default = exports.default = i18n;
24
24
  * Comments in this file are duplicated from ./i18n due to
25
25
  * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722
26
26
  */
27
- /**
28
- * @typedef {import('./create-i18n').LocaleData} LocaleData
29
- * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback
30
- * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback
31
- */
32
27
  /**
33
28
  * Returns locale data by domain in a Jed-formatted JSON object shape.
34
29
  *
35
30
  * @see http://messageformat.github.io/Jed/
36
31
  *
37
- * @param {string} [domain] Domain for which to get the data.
38
- * @return {LocaleData} Locale data.
32
+ * @param { string | undefined } [domain] Domain for which to get the data.
33
+ * @return { LocaleData } Locale data.
39
34
  */
40
35
  const getLocaleData = exports.getLocaleData = i18n.getLocaleData.bind(i18n);
41
36
 
@@ -45,8 +40,8 @@ const getLocaleData = exports.getLocaleData = i18n.getLocaleData.bind(i18n);
45
40
  *
46
41
  * @see http://messageformat.github.io/Jed/
47
42
  *
48
- * @param {LocaleData} [data] Locale data configuration.
49
- * @param {string} [domain] Domain for which configuration applies.
43
+ * @param {LocaleData } [data] Locale data configuration.
44
+ * @param {string | undefined} [domain] Domain for which configuration applies.
50
45
  */
51
46
  const setLocaleData = exports.setLocaleData = i18n.setLocaleData.bind(i18n);
52
47
 
@@ -56,8 +51,8 @@ const setLocaleData = exports.setLocaleData = i18n.setLocaleData.bind(i18n);
56
51
  *
57
52
  * @see http://messageformat.github.io/Jed/
58
53
  *
59
- * @param {LocaleData} [data] Locale data configuration.
60
- * @param {string} [domain] Domain for which configuration applies.
54
+ * @param {LocaleData} [data] Locale data configuration.
55
+ * @param {string | undefined} [domain] Domain for which configuration applies.
61
56
  */
62
57
  const resetLocaleData = exports.resetLocaleData = i18n.resetLocaleData.bind(i18n);
63
58
 
@@ -74,10 +69,12 @@ const subscribe = exports.subscribe = i18n.subscribe.bind(i18n);
74
69
  *
75
70
  * @see https://developer.wordpress.org/reference/functions/__/
76
71
  *
77
- * @param {string} text Text to translate.
78
- * @param {string} [domain] Domain to retrieve the translated text.
72
+ * @template {string} Text
79
73
  *
80
- * @return {string} Translated text.
74
+ * @param {Text} text Text to translate.
75
+ * @param {string | undefined} domain Domain to retrieve the translated text.
76
+ *
77
+ * @return {TranslatableText<Text>} Translated text.
81
78
  */
82
79
  const __ = exports.__ = i18n.__.bind(i18n);
83
80
 
@@ -86,11 +83,13 @@ const __ = exports.__ = i18n.__.bind(i18n);
86
83
  *
87
84
  * @see https://developer.wordpress.org/reference/functions/_x/
88
85
  *
89
- * @param {string} text Text to translate.
90
- * @param {string} context Context information for the translators.
91
- * @param {string} [domain] Domain to retrieve the translated text.
86
+ * @template {string} Text
87
+ *
88
+ * @param {Text} text Text to translate.
89
+ * @param {string} context Context information for the translators.
90
+ * @param {string | undefined} domain Domain to retrieve the translated text.
92
91
  *
93
- * @return {string} Translated context string without pipe.
92
+ * @return {TranslatableText<Text>} Translated context string without pipe.
94
93
  */
95
94
  const _x = exports._x = i18n._x.bind(i18n);
96
95
 
@@ -100,13 +99,16 @@ const _x = exports._x = i18n._x.bind(i18n);
100
99
  *
101
100
  * @see https://developer.wordpress.org/reference/functions/_n/
102
101
  *
103
- * @param {string} single The text to be used if the number is singular.
104
- * @param {string} plural The text to be used if the number is plural.
105
- * @param {number} number The number to compare against to use either the
106
- * singular or plural form.
107
- * @param {string} [domain] Domain to retrieve the translated text.
102
+ * @template {string} Single
103
+ * @template {string} Plural
108
104
  *
109
- * @return {string} The translated singular or plural form.
105
+ * @param {Single} single The text to be used if the number is singular.
106
+ * @param {Plural} plural The text to be used if the number is plural.
107
+ * @param {number} number The number to compare against to use either the
108
+ * singular or plural form.
109
+ * @param {string | undefined} domain Domain to retrieve the translated text.
110
+ *
111
+ * @return {TranslatableText<Single | Plural>} The translated singular or plural form.
110
112
  */
111
113
  const _n = exports._n = i18n._n.bind(i18n);
112
114
 
@@ -116,14 +118,18 @@ const _n = exports._n = i18n._n.bind(i18n);
116
118
  *
117
119
  * @see https://developer.wordpress.org/reference/functions/_nx/
118
120
  *
119
- * @param {string} single The text to be used if the number is singular.
120
- * @param {string} plural The text to be used if the number is plural.
121
- * @param {number} number The number to compare against to use either the
122
- * singular or plural form.
123
- * @param {string} context Context information for the translators.
124
- * @param {string} [domain] Domain to retrieve the translated text.
121
+ * @template {string} Single
122
+ * @template {string} Plural
123
+ * @param {Single} single The text to be used if the number is singular.
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.
127
+ * @param {number} number The number to compare against to use either the
128
+ * singular or plural form.
129
+ * @param {string} context Context information for the translators.
130
+ * @param {string | undefined} [domain] Domain to retrieve the translated text.
125
131
  *
126
- * @return {string} The translated singular or plural form.
132
+ * @return {TranslatableText<Single | Plural>} The translated singular or plural form.
127
133
  */
128
134
  const _nx = exports._nx = i18n._nx.bind(i18n);
129
135
 
@@ -142,9 +148,10 @@ const isRTL = exports.isRTL = i18n.isRTL.bind(i18n);
142
148
  /**
143
149
  * Check if there is a translation for a given string (in singular form).
144
150
  *
145
- * @param {string} single Singular form of the string to look up.
146
- * @param {string} [context] Context information for the translators.
147
- * @param {string} [domain] Domain to retrieve the translated text.
151
+ * @param {string} single Singular form of the string to look up.
152
+ * @param {string} context Context information for the translators.
153
+ * @param {string} domain Domain to retrieve the translated text.
154
+ *
148
155
  * @return {boolean} Whether the translation exists or not.
149
156
  */
150
157
  const hasTranslation = exports.hasTranslation = i18n.hasTranslation.bind(i18n);
@@ -1 +1 @@
1
- {"version":3,"names":["_createI18n","require","_hooks","i18n","createI18n","undefined","defaultHooks","_default","exports","default","getLocaleData","bind","setLocaleData","resetLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/default-i18n.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { createI18n } from './create-i18n';\n\n/**\n * WordPress dependencies\n */\nimport { defaultHooks } from '@wordpress/hooks';\n\nconst i18n = createI18n( undefined, undefined, defaultHooks );\n\n/**\n * Default, singleton instance of `I18n`.\n */\nexport default i18n;\n\n/*\n * Comments in this file are duplicated from ./i18n due to\n * https://github.com/WordPress/gutenberg/pull/20318#issuecomment-590837722\n */\n\n/**\n * @typedef {import('./create-i18n').LocaleData} LocaleData\n * @typedef {import('./create-i18n').SubscribeCallback} SubscribeCallback\n * @typedef {import('./create-i18n').UnsubscribeCallback} UnsubscribeCallback\n */\n\n/**\n * Returns locale data by domain in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {string} [domain] Domain for which to get the data.\n * @return {LocaleData} Locale data.\n */\nexport const getLocaleData = i18n.getLocaleData.bind( i18n );\n\n/**\n * Merges locale data into the Tannin instance by domain. Accepts data in a\n * Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const setLocaleData = i18n.setLocaleData.bind( i18n );\n\n/**\n * Resets all current Tannin instance locale data and sets the specified\n * locale data for the domain. Accepts data in a Jed-formatted JSON object shape.\n *\n * @see http://messageformat.github.io/Jed/\n *\n * @param {LocaleData} [data] Locale data configuration.\n * @param {string} [domain] Domain for which configuration applies.\n */\nexport const resetLocaleData = i18n.resetLocaleData.bind( i18n );\n\n/**\n * Subscribes to changes of locale data\n *\n * @param {SubscribeCallback} callback Subscription callback\n * @return {UnsubscribeCallback} Unsubscribe callback\n */\nexport const subscribe = i18n.subscribe.bind( i18n );\n\n/**\n * Retrieve the translation of text.\n *\n * @see https://developer.wordpress.org/reference/functions/__/\n *\n * @param {string} text Text to translate.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} Translated text.\n */\nexport const __ = i18n.__.bind( i18n );\n\n/**\n * Retrieve translated string with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_x/\n *\n * @param {string} text Text to translate.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} Translated context string without pipe.\n */\nexport const _x = i18n._x.bind( i18n );\n\n/**\n * Translates and retrieves the singular or plural form based on the supplied\n * number.\n *\n * @see https://developer.wordpress.org/reference/functions/_n/\n *\n * @param {string} single The text to be used if the number is singular.\n * @param {string} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} The translated singular or plural form.\n */\nexport const _n = i18n._n.bind( i18n );\n\n/**\n * Translates and retrieves the singular or plural form based on the supplied\n * number, with gettext context.\n *\n * @see https://developer.wordpress.org/reference/functions/_nx/\n *\n * @param {string} single The text to be used if the number is singular.\n * @param {string} plural The text to be used if the number is plural.\n * @param {number} number The number to compare against to use either the\n * singular or plural form.\n * @param {string} context Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n *\n * @return {string} The translated singular or plural form.\n */\nexport const _nx = i18n._nx.bind( i18n );\n\n/**\n * Check if current locale is RTL.\n *\n * **RTL (Right To Left)** is a locale property indicating that text is written from right to left.\n * For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common\n * language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,\n * including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).\n *\n * @return {boolean} Whether locale is RTL.\n */\nexport const isRTL = i18n.isRTL.bind( i18n );\n\n/**\n * Check if there is a translation for a given string (in singular form).\n *\n * @param {string} single Singular form of the string to look up.\n * @param {string} [context] Context information for the translators.\n * @param {string} [domain] Domain to retrieve the translated text.\n * @return {boolean} Whether the translation exists or not.\n */\nexport const hasTranslation = i18n.hasTranslation.bind( i18n );\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAME,IAAI,GAAG,IAAAC,sBAAU,EAAEC,SAAS,EAAEA,SAAS,EAAEC,mBAAa,CAAC;;AAE7D;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeN,IAAI;AAEnB;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMO,aAAa,GAAAF,OAAA,CAAAE,aAAA,GAAGP,IAAI,CAACO,aAAa,CAACC,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,aAAa,GAAAJ,OAAA,CAAAI,aAAA,GAAGT,IAAI,CAACS,aAAa,CAACD,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMU,eAAe,GAAAL,OAAA,CAAAK,eAAA,GAAGV,IAAI,CAACU,eAAe,CAACF,IAAI,CAAER,IAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACO,MAAMW,SAAS,GAAAN,OAAA,CAAAM,SAAA,GAAGX,IAAI,CAACW,SAAS,CAACH,IAAI,CAAER,IAAK,CAAC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMY,EAAE,GAAAP,OAAA,CAAAO,EAAA,GAAGZ,IAAI,CAACY,EAAE,CAACJ,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMa,EAAE,GAAAR,OAAA,CAAAQ,EAAA,GAAGb,IAAI,CAACa,EAAE,CAACL,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMc,EAAE,GAAAT,OAAA,CAAAS,EAAA,GAAGd,IAAI,CAACc,EAAE,CAACN,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMe,GAAG,GAAAV,OAAA,CAAAU,GAAA,GAAGf,IAAI,CAACe,GAAG,CAACP,IAAI,CAAER,IAAK,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMgB,KAAK,GAAAX,OAAA,CAAAW,KAAA,GAAGhB,IAAI,CAACgB,KAAK,CAACR,IAAI,CAAER,IAAK,CAAC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMiB,cAAc,GAAAZ,OAAA,CAAAY,cAAA,GAAGjB,IAAI,CAACiB,cAAc,CAACT,IAAI,CAAER,IAAK,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_createI18n","require","_hooks","i18n","createI18n","undefined","defaultHooks","_default","exports","default","getLocaleData","bind","setLocaleData","resetLocaleData","subscribe","__","_x","_n","_nx","isRTL","hasTranslation"],"sources":["@wordpress/i18n/src/default-i18n.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":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AASA,MAAME,IAAI,GAAG,IAAAC,sBAAU,EAAEC,SAAS,EAAEA,SAAS,EAAEC,mBAAa,CAAC;;AAE7D;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeN,IAAI;AAEnB;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMO,aAAa,GAAAF,OAAA,CAAAE,aAAA,GAAGP,IAAI,CAACO,aAAa,CAACC,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,aAAa,GAAAJ,OAAA,CAAAI,aAAA,GAAGT,IAAI,CAACS,aAAa,CAACD,IAAI,CAAER,IAAK,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMU,eAAe,GAAAL,OAAA,CAAAK,eAAA,GAAGV,IAAI,CAACU,eAAe,CAACF,IAAI,CAAER,IAAK,CAAC;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACO,MAAMW,SAAS,GAAAN,OAAA,CAAAM,SAAA,GAAGX,IAAI,CAACW,SAAS,CAACH,IAAI,CAAER,IAAK,CAAC;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMY,EAAE,GAAAP,OAAA,CAAAO,EAAA,GAAGZ,IAAI,CAACY,EAAE,CAACJ,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMa,EAAE,GAAAR,OAAA,CAAAQ,EAAA,GAAGb,IAAI,CAACa,EAAE,CAACL,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMc,EAAE,GAAAT,OAAA,CAAAS,EAAA,GAAGd,IAAI,CAACc,EAAE,CAACN,IAAI,CAAER,IAAK,CAAC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMe,GAAG,GAAAV,OAAA,CAAAU,GAAA,GAAGf,IAAI,CAACe,GAAG,CAACP,IAAI,CAAER,IAAK,CAAC;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMgB,KAAK,GAAAX,OAAA,CAAAW,KAAA,GAAGhB,IAAI,CAACgB,KAAK,CAACR,IAAI,CAAER,IAAK,CAAC;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMiB,cAAc,GAAAZ,OAAA,CAAAY,cAAA,GAAGjB,IAAI,CAACiB,cAAc,CAACT,IAAI,CAAER,IAAK,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["_sprintf","require","_createI18n","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_defaultI18n","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set"],"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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,WAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,WAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,WAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,YAAA,GAAAC,uBAAA,CAAAf,OAAA;AAYwB,SAAAgB,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAP,GAAA,CAAAI,CAAA,OAAAO,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAxB,MAAA,CAAAS,cAAA,IAAAT,MAAA,CAAAyB,wBAAA,WAAAC,CAAA,IAAAX,CAAA,oBAAAW,CAAA,OAAArB,cAAA,CAAAC,IAAA,CAAAS,CAAA,EAAAW,CAAA,SAAAC,CAAA,GAAAH,CAAA,GAAAxB,MAAA,CAAAyB,wBAAA,CAAAV,CAAA,EAAAW,CAAA,UAAAC,CAAA,KAAAA,CAAA,CAAAhB,GAAA,IAAAgB,CAAA,CAAAC,GAAA,IAAA5B,MAAA,CAAAS,cAAA,CAAAa,CAAA,EAAAI,CAAA,EAAAC,CAAA,IAAAL,CAAA,CAAAI,CAAA,IAAAX,CAAA,CAAAW,CAAA,YAAAJ,CAAA,CAAAF,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAU,GAAA,CAAAb,CAAA,EAAAO,CAAA,GAAAA,CAAA","ignoreList":[]}
1
+ {"version":3,"names":["_sprintf","require","_createI18n","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_defaultI18n","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set"],"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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,WAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,WAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,WAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,YAAA,GAAAC,uBAAA,CAAAf,OAAA;AAYwB,SAAAgB,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAP,GAAA,CAAAI,CAAA,OAAAO,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAxB,MAAA,CAAAS,cAAA,IAAAT,MAAA,CAAAyB,wBAAA,WAAAC,CAAA,IAAAX,CAAA,oBAAAW,CAAA,OAAArB,cAAA,CAAAC,IAAA,CAAAS,CAAA,EAAAW,CAAA,SAAAC,CAAA,GAAAH,CAAA,GAAAxB,MAAA,CAAAyB,wBAAA,CAAAV,CAAA,EAAAW,CAAA,UAAAC,CAAA,KAAAA,CAAA,CAAAhB,GAAA,IAAAgB,CAAA,CAAAC,GAAA,IAAA5B,MAAA,CAAAS,cAAA,CAAAa,CAAA,EAAAI,CAAA,EAAAC,CAAA,IAAAL,CAAA,CAAAI,CAAA,IAAAX,CAAA,CAAAW,CAAA,YAAAJ,CAAA,CAAAF,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAU,GAAA,CAAAb,CAAA,EAAAO,CAAA,GAAAA,CAAA","ignoreList":[]}AA,GAAAA,CAAA","ignoreList":[]}
package/build/sprintf.js CHANGED
@@ -5,40 +5,28 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.sprintf = sprintf;
8
- var _memize = _interopRequireDefault(require("memize"));
9
- var _sprintfJs = _interopRequireDefault(require("sprintf-js"));
8
+ var _sprintf2 = _interopRequireDefault(require("@tannin/sprintf"));
10
9
  /**
11
10
  * External dependencies
12
11
  */
12
+ // Disable reason: `eslint-plugin-import` doesn't support `exports` (https://github.com/import-js/eslint-plugin-import/issues/1810)
13
+ // eslint-disable-next-line import/no-unresolved
13
14
 
14
15
  /**
15
- * Log to console, once per message; or more precisely, per referentially equal
16
- * argument set. Because Jed throws errors, we log these to the console instead
17
- * to avoid crashing the application.
18
- *
19
- * @param {...*} args Arguments to pass to `console.error`
16
+ * Internal dependencies
20
17
  */
21
- const logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line no-console
22
18
 
23
19
  /**
24
- * Returns a formatted string. If an error occurs in applying the format, the
25
- * original format string is returned.
20
+ * Returns a formatted string.
26
21
  *
27
- * @param {string} format The format of the string to generate.
28
- * @param {...*} args Arguments to apply to the format.
22
+ * @param format The format of the string to generate.
23
+ * @param args Arguments to apply to the format.
29
24
  *
30
- * @see https://www.npmjs.com/package/sprintf-js
25
+ * @see https://www.npmjs.com/package/@tannin/sprintf
31
26
  *
32
- * @return {string} The formatted string.
27
+ * @return The formatted string.
33
28
  */
34
29
  function sprintf(format, ...args) {
35
- try {
36
- return _sprintfJs.default.sprintf(format, ...args);
37
- } catch (error) {
38
- if (error instanceof Error) {
39
- logErrorOnce('sprintf error: \n\n' + error.toString());
40
- }
41
- return format;
42
- }
30
+ return (0, _sprintf2.default)(format, ...args);
43
31
  }
44
32
  //# sourceMappingURL=sprintf.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_memize","_interopRequireDefault","require","_sprintfJs","logErrorOnce","memoize","console","error","sprintf","format","args","sprintfjs","Error","toString"],"sources":["@wordpress/i18n/src/sprintf.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\nimport sprintfjs from 'sprintf-js';\n\n/**\n * Log to console, once per message; or more precisely, per referentially equal\n * argument set. Because Jed throws errors, we log these to the console instead\n * to avoid crashing the application.\n *\n * @param {...*} args Arguments to pass to `console.error`\n */\nconst logErrorOnce = memoize( console.error ); // eslint-disable-line no-console\n\n/**\n * Returns a formatted string. If an error occurs in applying the format, the\n * original format string is returned.\n *\n * @param {string} format The format of the string to generate.\n * @param {...*} args Arguments to apply to the format.\n *\n * @see https://www.npmjs.com/package/sprintf-js\n *\n * @return {string} The formatted string.\n */\nexport function sprintf( format, ...args ) {\n\ttry {\n\t\treturn sprintfjs.sprintf( format, ...args );\n\t} catch ( error ) {\n\t\tif ( error instanceof Error ) {\n\t\t\tlogErrorOnce( 'sprintf error: \\n\\n' + error.toString() );\n\t\t}\n\t\treturn format;\n\t}\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,YAAY,GAAG,IAAAC,eAAO,EAAEC,OAAO,CAACC,KAAM,CAAC,CAAC,CAAC;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CAAEC,MAAM,EAAE,GAAGC,IAAI,EAAG;EAC1C,IAAI;IACH,OAAOC,kBAAS,CAACH,OAAO,CAAEC,MAAM,EAAE,GAAGC,IAAK,CAAC;EAC5C,CAAC,CAAC,OAAQH,KAAK,EAAG;IACjB,IAAKA,KAAK,YAAYK,KAAK,EAAG;MAC7BR,YAAY,CAAE,qBAAqB,GAAGG,KAAK,CAACM,QAAQ,CAAC,CAAE,CAAC;IACzD;IACA,OAAOJ,MAAM;EACd;AACD","ignoreList":[]}
1
+ {"version":3,"names":["_sprintf2","_interopRequireDefault","require","sprintf","format","args","_sprintf"],"sources":["@wordpress/i18n/src/sprintf.ts"],"sourcesContent":["/**\n * External dependencies\n */\n// Disable reason: `eslint-plugin-import` doesn't support `exports` (https://github.com/import-js/eslint-plugin-import/issues/1810)\n// eslint-disable-next-line import/no-unresolved\nimport _sprintf from '@tannin/sprintf';\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":";;;;;;;AAKA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AALA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,OAAOA,CACtBC,MAAiC,EACjC,GAAGC,IAAgC,EAC1B;EACT,OAAO,IAAAC,iBAAQ,EAAEF,MAAM,EAAO,GAAKC,IAAqC,CAAC;AAC1E","ignoreList":[]}
package/build/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["@wordpress/i18n/src/types.ts"],"sourcesContent":["/**\n * 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":[]}