@wordpress/i18n 6.0.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.
- package/README.md +20 -19
- package/build/create-i18n.js +60 -205
- package/build/create-i18n.js.map +1 -1
- package/build/default-i18n.js +31 -34
- package/build/default-i18n.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/sprintf.js +3 -4
- package/build/sprintf.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/create-i18n.js +60 -205
- package/build-module/create-i18n.js.map +1 -1
- package/build-module/default-i18n.js +31 -35
- package/build-module/default-i18n.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/sprintf.js +3 -4
- package/build-module/sprintf.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-types/create-i18n.d.ts +11 -115
- package/build-types/create-i18n.d.ts.map +1 -1
- package/build-types/default-i18n.d.ts +45 -47
- package/build-types/default-i18n.d.ts.map +1 -1
- package/build-types/index.d.ts +4 -3
- package/build-types/index.d.ts.map +1 -1
- package/build-types/sprintf.d.ts +1 -4
- package/build-types/sprintf.d.ts.map +1 -1
- package/build-types/types.d.ts +101 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/create-i18n.ts +405 -0
- package/src/{default-i18n.js → default-i18n.ts} +37 -35
- package/src/index.ts +16 -0
- package/src/sprintf.ts +4 -10
- package/src/test/{create-i18n.js → create-i18n.ts} +63 -30
- package/src/test/{sprintf.js → sprintf.ts} +5 -1
- package/src/test/{subscribe-i18n.js → subscribe-i18n.ts} +3 -3
- package/src/types.ts +155 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/create-i18n.js +0 -514
- /package/src/test/{default-i18n.js → default-i18n.ts} +0 -0
package/build/default-i18n.js
CHANGED
|
@@ -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}
|
|
49
|
-
* @param {string}
|
|
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}
|
|
60
|
-
* @param {string}
|
|
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
|
|
|
@@ -76,10 +71,10 @@ const subscribe = exports.subscribe = i18n.subscribe.bind(i18n);
|
|
|
76
71
|
*
|
|
77
72
|
* @template {string} Text
|
|
78
73
|
*
|
|
79
|
-
* @param {Text}
|
|
80
|
-
* @param {string}
|
|
74
|
+
* @param {Text} text Text to translate.
|
|
75
|
+
* @param {string | undefined} domain Domain to retrieve the translated text.
|
|
81
76
|
*
|
|
82
|
-
* @return {
|
|
77
|
+
* @return {TranslatableText<Text>} Translated text.
|
|
83
78
|
*/
|
|
84
79
|
const __ = exports.__ = i18n.__.bind(i18n);
|
|
85
80
|
|
|
@@ -90,11 +85,11 @@ const __ = exports.__ = i18n.__.bind(i18n);
|
|
|
90
85
|
*
|
|
91
86
|
* @template {string} Text
|
|
92
87
|
*
|
|
93
|
-
* @param {Text}
|
|
94
|
-
* @param {string}
|
|
95
|
-
* @param {string}
|
|
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.
|
|
96
91
|
*
|
|
97
|
-
* @return {
|
|
92
|
+
* @return {TranslatableText<Text>} Translated context string without pipe.
|
|
98
93
|
*/
|
|
99
94
|
const _x = exports._x = i18n._x.bind(i18n);
|
|
100
95
|
|
|
@@ -107,13 +102,13 @@ const _x = exports._x = i18n._x.bind(i18n);
|
|
|
107
102
|
* @template {string} Single
|
|
108
103
|
* @template {string} Plural
|
|
109
104
|
*
|
|
110
|
-
* @param {Single}
|
|
111
|
-
* @param {Plural}
|
|
112
|
-
* @param {number}
|
|
113
|
-
*
|
|
114
|
-
* @param {string}
|
|
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.
|
|
115
110
|
*
|
|
116
|
-
* @return {
|
|
111
|
+
* @return {TranslatableText<Single | Plural>} The translated singular or plural form.
|
|
117
112
|
*/
|
|
118
113
|
const _n = exports._n = i18n._n.bind(i18n);
|
|
119
114
|
|
|
@@ -125,15 +120,16 @@ const _n = exports._n = i18n._n.bind(i18n);
|
|
|
125
120
|
*
|
|
126
121
|
* @template {string} Single
|
|
127
122
|
* @template {string} Plural
|
|
123
|
+
* @param {Single} single The text to be used if the number is singular.
|
|
128
124
|
*
|
|
129
|
-
* @param {Single}
|
|
130
|
-
* @param {Plural}
|
|
131
|
-
* @param {number}
|
|
132
|
-
*
|
|
133
|
-
* @param {string}
|
|
134
|
-
* @param {string} [domain] Domain to retrieve the translated text.
|
|
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.
|
|
135
131
|
*
|
|
136
|
-
* @return {
|
|
132
|
+
* @return {TranslatableText<Single | Plural>} The translated singular or plural form.
|
|
137
133
|
*/
|
|
138
134
|
const _nx = exports._nx = i18n._nx.bind(i18n);
|
|
139
135
|
|
|
@@ -152,9 +148,10 @@ const isRTL = exports.isRTL = i18n.isRTL.bind(i18n);
|
|
|
152
148
|
/**
|
|
153
149
|
* Check if there is a translation for a given string (in singular form).
|
|
154
150
|
*
|
|
155
|
-
* @param {string} single
|
|
156
|
-
* @param {string}
|
|
157
|
-
* @param {string}
|
|
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
|
+
*
|
|
158
155
|
* @return {boolean} Whether the translation exists or not.
|
|
159
156
|
*/
|
|
160
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.
|
|
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":[]}
|
package/build/index.js.map
CHANGED
|
@@ -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
|
@@ -19,13 +19,12 @@ var _sprintf2 = _interopRequireDefault(require("@tannin/sprintf"));
|
|
|
19
19
|
/**
|
|
20
20
|
* Returns a formatted string.
|
|
21
21
|
*
|
|
22
|
-
* @
|
|
23
|
-
* @param
|
|
24
|
-
* @param {DistributeSprintfArgs<T>} 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.
|
|
25
24
|
*
|
|
26
25
|
* @see https://www.npmjs.com/package/@tannin/sprintf
|
|
27
26
|
*
|
|
28
|
-
* @return
|
|
27
|
+
* @return The formatted string.
|
|
29
28
|
*/
|
|
30
29
|
function sprintf(format, ...args) {
|
|
31
30
|
return (0, _sprintf2.default)(format, ...args);
|
package/build/sprintf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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';\
|
|
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.map
CHANGED
|
@@ -1 +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":[]}
|
|
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,21 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
+
|
|
4
5
|
import Tannin from 'tannin';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* WordPress dependencies
|
|
8
12
|
*/
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* Default locale data to use for Tannin domain when not otherwise provided.
|
|
12
16
|
* Assumes an English plural forms expression.
|
|
13
|
-
*
|
|
14
|
-
* @type {LocaleData}
|
|
15
17
|
*/
|
|
16
18
|
const DEFAULT_LOCALE_DATA = {
|
|
17
19
|
'': {
|
|
18
|
-
/** @param {number} n */
|
|
19
20
|
plural_forms(n) {
|
|
20
21
|
return n === 1 ? 0 : 1;
|
|
21
22
|
}
|
|
@@ -28,136 +29,18 @@ const DEFAULT_LOCALE_DATA = {
|
|
|
28
29
|
*/
|
|
29
30
|
const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
|
|
30
31
|
|
|
31
|
-
/**
|
|
32
|
-
* @typedef {(domain?: string) => LocaleData} GetLocaleData
|
|
33
|
-
*
|
|
34
|
-
* Returns locale data by domain in a
|
|
35
|
-
* Jed-formatted JSON object shape.
|
|
36
|
-
*
|
|
37
|
-
* @see http://messageformat.github.io/Jed/
|
|
38
|
-
*/
|
|
39
|
-
/**
|
|
40
|
-
* @typedef {(data?: LocaleData, domain?: string) => void} SetLocaleData
|
|
41
|
-
*
|
|
42
|
-
* Merges locale data into the Tannin instance by domain. Note that this
|
|
43
|
-
* function will overwrite the domain configuration. Accepts data in a
|
|
44
|
-
* Jed-formatted JSON object shape.
|
|
45
|
-
*
|
|
46
|
-
* @see http://messageformat.github.io/Jed/
|
|
47
|
-
*/
|
|
48
|
-
/**
|
|
49
|
-
* @typedef {(data?: LocaleData, domain?: string) => void} AddLocaleData
|
|
50
|
-
*
|
|
51
|
-
* Merges locale data into the Tannin instance by domain. Note that this
|
|
52
|
-
* function will also merge the domain configuration. Accepts data in a
|
|
53
|
-
* Jed-formatted JSON object shape.
|
|
54
|
-
*
|
|
55
|
-
* @see http://messageformat.github.io/Jed/
|
|
56
|
-
*/
|
|
57
|
-
/**
|
|
58
|
-
* @typedef {(data?: LocaleData, domain?: string) => void} ResetLocaleData
|
|
59
|
-
*
|
|
60
|
-
* Resets all current Tannin instance locale data and sets the specified
|
|
61
|
-
* locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
|
|
62
|
-
*
|
|
63
|
-
* @see http://messageformat.github.io/Jed/
|
|
64
|
-
*/
|
|
65
|
-
/** @typedef {() => void} SubscribeCallback */
|
|
66
|
-
/** @typedef {() => void} UnsubscribeCallback */
|
|
67
|
-
/**
|
|
68
|
-
* @typedef {(callback: SubscribeCallback) => UnsubscribeCallback} Subscribe
|
|
69
|
-
*
|
|
70
|
-
* Subscribes to changes of locale data
|
|
71
|
-
*/
|
|
72
|
-
/**
|
|
73
|
-
* @typedef {(domain?: string) => string} GetFilterDomain
|
|
74
|
-
* Retrieve the domain to use when calling domain-specific filters.
|
|
75
|
-
*/
|
|
76
|
-
/**
|
|
77
|
-
* @typedef {<Text extends string>(text: Text, domain?: string) => import('./types').TranslatableText< Text >} __
|
|
78
|
-
*
|
|
79
|
-
* Retrieve the translation of text.
|
|
80
|
-
*
|
|
81
|
-
* @see https://developer.wordpress.org/reference/functions/__/
|
|
82
|
-
*/
|
|
83
|
-
/**
|
|
84
|
-
* @typedef {<Text extends string>(text: Text, context: string, domain?: string) => import('./types').TranslatableText< Text >} _x
|
|
85
|
-
*
|
|
86
|
-
* Retrieve translated string with gettext context.
|
|
87
|
-
*
|
|
88
|
-
* @see https://developer.wordpress.org/reference/functions/_x/
|
|
89
|
-
*/
|
|
90
|
-
/**
|
|
91
|
-
* @typedef {<Single extends string, Plural extends string>(single: Single, plural: Plural, number: number, domain?: string) => import('./types').TranslatableText< Single | Plural >} _n
|
|
92
|
-
*
|
|
93
|
-
* Translates and retrieves the singular or plural form based on the supplied
|
|
94
|
-
* number.
|
|
95
|
-
*
|
|
96
|
-
* @see https://developer.wordpress.org/reference/functions/_n/
|
|
97
|
-
*/
|
|
98
|
-
/**
|
|
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
|
-
*
|
|
101
|
-
* Translates and retrieves the singular or plural form based on the supplied
|
|
102
|
-
* number, with gettext context.
|
|
103
|
-
*
|
|
104
|
-
* @see https://developer.wordpress.org/reference/functions/_nx/
|
|
105
|
-
*/
|
|
106
|
-
/**
|
|
107
|
-
* @typedef {() => boolean} IsRtl
|
|
108
|
-
*
|
|
109
|
-
* Check if current locale is RTL.
|
|
110
|
-
*
|
|
111
|
-
* **RTL (Right To Left)** is a locale property indicating that text is written from right to left.
|
|
112
|
-
* For example, the `he` locale (for Hebrew) specifies right-to-left. Arabic (ar) is another common
|
|
113
|
-
* language written RTL. The opposite of RTL, LTR (Left To Right) is used in other languages,
|
|
114
|
-
* including English (`en`, `en-US`, `en-GB`, etc.), Spanish (`es`), and French (`fr`).
|
|
115
|
-
*/
|
|
116
|
-
/**
|
|
117
|
-
* @typedef {(single: string, context?: string, domain?: string) => boolean} HasTranslation
|
|
118
|
-
*
|
|
119
|
-
* Check if there is a translation for a given string in singular form.
|
|
120
|
-
*/
|
|
121
|
-
/** @typedef {import('@wordpress/hooks').Hooks} Hooks */
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* An i18n instance
|
|
125
|
-
*
|
|
126
|
-
* @typedef I18n
|
|
127
|
-
* @property {GetLocaleData} getLocaleData Returns locale data by domain in a Jed-formatted JSON object shape.
|
|
128
|
-
* @property {SetLocaleData} setLocaleData Merges locale data into the Tannin instance by domain. Note that this
|
|
129
|
-
* function will overwrite the domain configuration. Accepts data in a
|
|
130
|
-
* Jed-formatted JSON object shape.
|
|
131
|
-
* @property {AddLocaleData} addLocaleData Merges locale data into the Tannin instance by domain. Note that this
|
|
132
|
-
* function will also merge the domain configuration. Accepts data in a
|
|
133
|
-
* Jed-formatted JSON object shape.
|
|
134
|
-
* @property {ResetLocaleData} resetLocaleData Resets all current Tannin instance locale data and sets the specified
|
|
135
|
-
* locale data for the domain. Accepts data in a Jed-formatted JSON object shape.
|
|
136
|
-
* @property {Subscribe} subscribe Subscribes to changes of Tannin locale data.
|
|
137
|
-
* @property {__} __ Retrieve the translation of text.
|
|
138
|
-
* @property {_x} _x Retrieve translated string with gettext context.
|
|
139
|
-
* @property {_n} _n Translates and retrieves the singular or plural form based on the supplied
|
|
140
|
-
* number.
|
|
141
|
-
* @property {_nx} _nx Translates and retrieves the singular or plural form based on the supplied
|
|
142
|
-
* number, with gettext context.
|
|
143
|
-
* @property {IsRtl} isRTL Check if current locale is RTL.
|
|
144
|
-
* @property {HasTranslation} hasTranslation Check if there is a translation for a given string.
|
|
145
|
-
*/
|
|
146
|
-
|
|
147
32
|
/**
|
|
148
33
|
* Create an i18n instance
|
|
149
34
|
*
|
|
150
|
-
* @param
|
|
151
|
-
* @param
|
|
152
|
-
* @param
|
|
35
|
+
* @param [initialData] Locale data configuration.
|
|
36
|
+
* @param [initialDomain] Domain for which configuration applies.
|
|
37
|
+
* @param [hooks] Hooks implementation.
|
|
153
38
|
*
|
|
154
|
-
* @return
|
|
39
|
+
* @return I18n instance.
|
|
155
40
|
*/
|
|
156
41
|
export const createI18n = (initialData, initialDomain, hooks) => {
|
|
157
42
|
/**
|
|
158
43
|
* The underlying instance of Tannin to which exported functions interface.
|
|
159
|
-
*
|
|
160
|
-
* @type {Tannin}
|
|
161
44
|
*/
|
|
162
45
|
const tannin = new Tannin({});
|
|
163
46
|
const listeners = new Set();
|
|
@@ -168,20 +51,18 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
168
51
|
/**
|
|
169
52
|
* Subscribe to changes of locale data.
|
|
170
53
|
*
|
|
171
|
-
* @param
|
|
172
|
-
* @return
|
|
54
|
+
* @param callback Subscription callback.
|
|
55
|
+
* @return Unsubscribe callback.
|
|
173
56
|
*/
|
|
174
57
|
const subscribe = callback => {
|
|
175
58
|
listeners.add(callback);
|
|
176
59
|
return () => listeners.delete(callback);
|
|
177
60
|
};
|
|
178
|
-
|
|
179
|
-
/** @type {GetLocaleData} */
|
|
180
61
|
const getLocaleData = (domain = 'default') => tannin.data[domain];
|
|
181
62
|
|
|
182
63
|
/**
|
|
183
|
-
* @param
|
|
184
|
-
* @param
|
|
64
|
+
* @param [data]
|
|
65
|
+
* @param [domain]
|
|
185
66
|
*/
|
|
186
67
|
const doSetLocaleData = (data, domain = 'default') => {
|
|
187
68
|
tannin.data[domain] = {
|
|
@@ -199,14 +80,10 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
199
80
|
// Clean up cached plural forms functions cache as it might be updated.
|
|
200
81
|
delete tannin.pluralForms[domain];
|
|
201
82
|
};
|
|
202
|
-
|
|
203
|
-
/** @type {SetLocaleData} */
|
|
204
83
|
const setLocaleData = (data, domain) => {
|
|
205
84
|
doSetLocaleData(data, domain);
|
|
206
85
|
notifyListeners();
|
|
207
86
|
};
|
|
208
|
-
|
|
209
|
-
/** @type {AddLocaleData} */
|
|
210
87
|
const addLocaleData = (data, domain = 'default') => {
|
|
211
88
|
tannin.data[domain] = {
|
|
212
89
|
...tannin.data[domain],
|
|
@@ -224,8 +101,6 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
224
101
|
delete tannin.pluralForms[domain];
|
|
225
102
|
notifyListeners();
|
|
226
103
|
};
|
|
227
|
-
|
|
228
|
-
/** @type {ResetLocaleData} */
|
|
229
104
|
const resetLocaleData = (data, domain) => {
|
|
230
105
|
// Reset all current Tannin locale data.
|
|
231
106
|
tannin.data = {};
|
|
@@ -239,16 +114,16 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
239
114
|
* Wrapper for Tannin's `dcnpgettext`. Populates default locale data if not
|
|
240
115
|
* otherwise previously assigned.
|
|
241
116
|
*
|
|
242
|
-
* @param
|
|
243
|
-
* @param
|
|
244
|
-
* @param
|
|
245
|
-
*
|
|
246
|
-
* @param
|
|
247
|
-
*
|
|
248
|
-
* @param
|
|
249
|
-
*
|
|
117
|
+
* @param domain Domain to retrieve the translated text.
|
|
118
|
+
* @param context Context information for the translators.
|
|
119
|
+
* @param single Text to translate if non-plural. Used as
|
|
120
|
+
* fallback return value on a caught error.
|
|
121
|
+
* @param [plural] The text to be used if the number is
|
|
122
|
+
* plural.
|
|
123
|
+
* @param [number] The number to compare against to use
|
|
124
|
+
* either the singular or plural form.
|
|
250
125
|
*
|
|
251
|
-
* @return
|
|
126
|
+
* @return The translated string.
|
|
252
127
|
*/
|
|
253
128
|
const dcnpgettext = (domain = 'default', context, single, plural, number) => {
|
|
254
129
|
if (!tannin.data[domain]) {
|
|
@@ -257,98 +132,80 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
257
132
|
}
|
|
258
133
|
return tannin.dcnpgettext(domain, context, single, plural, number);
|
|
259
134
|
};
|
|
260
|
-
|
|
261
|
-
/** @type {GetFilterDomain} */
|
|
262
|
-
const getFilterDomain = (domain = 'default') => domain;
|
|
263
|
-
|
|
264
|
-
/** @type {__} */
|
|
135
|
+
const getFilterDomain = domain => domain || 'default';
|
|
265
136
|
const __ = (text, domain) => {
|
|
266
137
|
let translation = dcnpgettext(domain, undefined, text);
|
|
267
138
|
if (!hooks) {
|
|
268
|
-
return
|
|
139
|
+
return translation;
|
|
269
140
|
}
|
|
270
141
|
|
|
271
142
|
/**
|
|
272
143
|
* Filters text with its translation.
|
|
273
144
|
*
|
|
274
|
-
* @param
|
|
275
|
-
* @param
|
|
276
|
-
* @param
|
|
145
|
+
* @param translation Translated text.
|
|
146
|
+
* @param text Text to translate.
|
|
147
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
277
148
|
*/
|
|
278
|
-
translation =
|
|
279
|
-
|
|
280
|
-
return /** @type {import('./types').TranslatableText<typeof text>} */ /** @type {*} */hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
|
|
149
|
+
translation = hooks.applyFilters('i18n.gettext', translation, text, domain);
|
|
150
|
+
return hooks.applyFilters('i18n.gettext_' + getFilterDomain(domain), translation, text, domain);
|
|
281
151
|
};
|
|
282
|
-
|
|
283
|
-
/** @type {_x} */
|
|
284
152
|
const _x = (text, context, domain) => {
|
|
285
153
|
let translation = dcnpgettext(domain, context, text);
|
|
286
154
|
if (!hooks) {
|
|
287
|
-
return
|
|
155
|
+
return translation;
|
|
288
156
|
}
|
|
289
157
|
|
|
290
158
|
/**
|
|
291
159
|
* Filters text with its translation based on context information.
|
|
292
160
|
*
|
|
293
|
-
* @param
|
|
294
|
-
* @param
|
|
295
|
-
* @param
|
|
296
|
-
* @param
|
|
161
|
+
* @param translation Translated text.
|
|
162
|
+
* @param text Text to translate.
|
|
163
|
+
* @param context Context information for the translators.
|
|
164
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
297
165
|
*/
|
|
298
|
-
translation =
|
|
299
|
-
|
|
300
|
-
return /** @type {import('./types').TranslatableText<typeof text>} */ /** @type {*} */hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
|
|
166
|
+
translation = hooks.applyFilters('i18n.gettext_with_context', translation, text, context, domain);
|
|
167
|
+
return hooks.applyFilters('i18n.gettext_with_context_' + getFilterDomain(domain), translation, text, context, domain);
|
|
301
168
|
};
|
|
302
|
-
|
|
303
|
-
/** @type {_n} */
|
|
304
169
|
const _n = (single, plural, number, domain) => {
|
|
305
170
|
let translation = dcnpgettext(domain, undefined, single, plural, number);
|
|
306
171
|
if (!hooks) {
|
|
307
|
-
return
|
|
172
|
+
return translation;
|
|
308
173
|
}
|
|
309
174
|
|
|
310
175
|
/**
|
|
311
176
|
* Filters the singular or plural form of a string.
|
|
312
177
|
*
|
|
313
|
-
* @param
|
|
314
|
-
* @param
|
|
315
|
-
* @param
|
|
316
|
-
* @param
|
|
317
|
-
* @param
|
|
178
|
+
* @param translation Translated text.
|
|
179
|
+
* @param single The text to be used if the number is singular.
|
|
180
|
+
* @param plural The text to be used if the number is plural.
|
|
181
|
+
* @param number The number to compare against to use either the singular or plural form.
|
|
182
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
318
183
|
*/
|
|
319
|
-
translation =
|
|
320
|
-
|
|
321
|
-
return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
|
|
184
|
+
translation = hooks.applyFilters('i18n.ngettext', translation, single, plural, number, domain);
|
|
185
|
+
return hooks.applyFilters('i18n.ngettext_' + getFilterDomain(domain), translation, single, plural, number, domain);
|
|
322
186
|
};
|
|
323
|
-
|
|
324
|
-
/** @type {_nx} */
|
|
325
187
|
const _nx = (single, plural, number, context, domain) => {
|
|
326
188
|
let translation = dcnpgettext(domain, context, single, plural, number);
|
|
327
189
|
if (!hooks) {
|
|
328
|
-
return
|
|
190
|
+
return translation;
|
|
329
191
|
}
|
|
330
192
|
|
|
331
193
|
/**
|
|
332
194
|
* Filters the singular or plural form of a string with gettext context.
|
|
333
195
|
*
|
|
334
|
-
* @param
|
|
335
|
-
* @param
|
|
336
|
-
* @param
|
|
337
|
-
* @param
|
|
338
|
-
* @param
|
|
339
|
-
* @param
|
|
196
|
+
* @param translation Translated text.
|
|
197
|
+
* @param single The text to be used if the number is singular.
|
|
198
|
+
* @param plural The text to be used if the number is plural.
|
|
199
|
+
* @param number The number to compare against to use either the singular or plural form.
|
|
200
|
+
* @param context Context information for the translators.
|
|
201
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
340
202
|
*/
|
|
341
|
-
translation =
|
|
342
|
-
|
|
343
|
-
return /** @type {import('./types').TranslatableText<typeof single | typeof plural>} */ /** @type {*} */hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
|
|
203
|
+
translation = hooks.applyFilters('i18n.ngettext_with_context', translation, single, plural, number, context, domain);
|
|
204
|
+
return hooks.applyFilters('i18n.ngettext_with_context_' + getFilterDomain(domain), translation, single, plural, number, context, domain);
|
|
344
205
|
};
|
|
345
|
-
|
|
346
|
-
/** @type {IsRtl} */
|
|
347
206
|
const isRTL = () => {
|
|
348
207
|
return 'rtl' === _x('ltr', 'text direction');
|
|
349
208
|
};
|
|
350
|
-
|
|
351
|
-
/** @type {HasTranslation} */
|
|
352
209
|
const hasTranslation = (single, context, domain) => {
|
|
353
210
|
const key = context ? context + '\u0004' + single : single;
|
|
354
211
|
let result = !!tannin.data?.[domain !== null && domain !== void 0 ? domain : 'default']?.[key];
|
|
@@ -356,15 +213,13 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
356
213
|
/**
|
|
357
214
|
* Filters the presence of a translation in the locale data.
|
|
358
215
|
*
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
361
|
-
* @param
|
|
362
|
-
* @param
|
|
216
|
+
* @param hasTranslation Whether the translation is present or not..
|
|
217
|
+
* @param single The singular form of the translated text (used as key in locale data)
|
|
218
|
+
* @param context Context information for the translators.
|
|
219
|
+
* @param domain Text domain. Unique identifier for retrieving translated strings.
|
|
363
220
|
*/
|
|
364
|
-
result =
|
|
365
|
-
|
|
366
|
-
result = /** @type { boolean } */
|
|
367
|
-
/** @type {*} */hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
|
|
221
|
+
result = hooks.applyFilters('i18n.has_translation', result, single, context, domain);
|
|
222
|
+
result = hooks.applyFilters('i18n.has_translation_' + getFilterDomain(domain), result, single, context, domain);
|
|
368
223
|
}
|
|
369
224
|
return result;
|
|
370
225
|
};
|
|
@@ -373,7 +228,7 @@ export const createI18n = (initialData, initialDomain, hooks) => {
|
|
|
373
228
|
}
|
|
374
229
|
if (hooks) {
|
|
375
230
|
/**
|
|
376
|
-
* @param
|
|
231
|
+
* @param hookName
|
|
377
232
|
*/
|
|
378
233
|
const onHookAddedOrRemoved = hookName => {
|
|
379
234
|
if (I18N_HOOK_REGEXP.test(hookName)) {
|