@absolutesight/react-gettext 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -5
- package/LICENSE +21 -21
- package/README.md +431 -365
- package/dist/react-gettext.js +267 -267
- package/dist/react-gettext.min.js +1 -0
- package/lib/TextDomain.js +63 -0
- package/lib/TextDomainContext.js +4 -0
- package/lib/Textdomain.js +69 -69
- package/lib/TextdomainContext.js +10 -10
- package/lib/buildTextDomain.js +17 -0
- package/lib/buildTextdomain.js +23 -23
- package/lib/gettext.js +102 -102
- package/lib/index.js +5 -5
- package/lib/withGettext.js +26 -26
- package/package.json +81 -84
- package/src/TextDomain.js +82 -82
- package/src/TextDomainContext.js +6 -6
- package/src/buildTextDomain.js +18 -18
- package/src/gettext.js +123 -123
- package/src/index.js +12 -12
- package/src/withGettext.js +35 -35
package/dist/react-gettext.js
CHANGED
|
@@ -55,83 +55,83 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
55
55
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
56
56
|
/* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prop-types */ "prop-types");
|
|
57
57
|
/* harmony import */ var _gettext_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./gettext.js */ "./gettext.js");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
class TextDomain extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
|
|
64
|
-
|
|
65
|
-
getChildContext() {
|
|
66
|
-
const self = this;
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
gettext: self.gettext.bind(self),
|
|
70
|
-
xgettext: self.xgettext.bind(self),
|
|
71
|
-
ngettext: self.ngettext.bind(self),
|
|
72
|
-
nxgettext: self.nxgettext.bind(self),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
gettext(message) {
|
|
77
|
-
const { translations } = this.props;
|
|
78
|
-
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.gettext)(translations, message);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
ngettext(singular, plural, n) {
|
|
82
|
-
const { translations, plural: plurality } = this.props;
|
|
83
|
-
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.ngettext)(translations, plurality, singular, plural, n);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
xgettext(message, context) {
|
|
87
|
-
const { translations } = this.props;
|
|
88
|
-
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.xgettext)(translations, message, context);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
nxgettext(singular, plural, n, context) {
|
|
92
|
-
const { translations, plural: plurality } = this.props;
|
|
93
|
-
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.nxgettext)(translations, plurality, singular, plural, n, context);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
render() {
|
|
97
|
-
const { children } = this.props;
|
|
98
|
-
return children;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
TextDomain.propTypes = {
|
|
104
|
-
translations: prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
105
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
106
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.objectOf(prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
107
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.string,
|
|
108
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.arrayOf(prop_types__WEBPACK_IMPORTED_MODULE_1__.string),
|
|
109
|
-
])),
|
|
110
|
-
]),
|
|
111
|
-
plural: prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
112
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
113
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.string,
|
|
114
|
-
]),
|
|
115
|
-
children: prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
116
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.node,
|
|
117
|
-
prop_types__WEBPACK_IMPORTED_MODULE_1__.arrayOf(prop_types__WEBPACK_IMPORTED_MODULE_1__.node),
|
|
118
|
-
]),
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
TextDomain.defaultProps = {
|
|
122
|
-
translations: {},
|
|
123
|
-
plural: 'n != 1',
|
|
124
|
-
children: [],
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
TextDomain.childContextTypes = {
|
|
128
|
-
gettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
129
|
-
ngettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
130
|
-
xgettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
131
|
-
nxgettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomain);
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class TextDomain extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
|
|
64
|
+
|
|
65
|
+
getChildContext() {
|
|
66
|
+
const self = this;
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
gettext: self.gettext.bind(self),
|
|
70
|
+
xgettext: self.xgettext.bind(self),
|
|
71
|
+
ngettext: self.ngettext.bind(self),
|
|
72
|
+
nxgettext: self.nxgettext.bind(self),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
gettext(message) {
|
|
77
|
+
const { translations } = this.props;
|
|
78
|
+
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.gettext)(translations, message);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
ngettext(singular, plural, n) {
|
|
82
|
+
const { translations, plural: plurality } = this.props;
|
|
83
|
+
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.ngettext)(translations, plurality, singular, plural, n);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
xgettext(message, context) {
|
|
87
|
+
const { translations } = this.props;
|
|
88
|
+
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.xgettext)(translations, message, context);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
nxgettext(singular, plural, n, context) {
|
|
92
|
+
const { translations, plural: plurality } = this.props;
|
|
93
|
+
return (0,_gettext_js__WEBPACK_IMPORTED_MODULE_2__.nxgettext)(translations, plurality, singular, plural, n, context);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
render() {
|
|
97
|
+
const { children } = this.props;
|
|
98
|
+
return children;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
TextDomain.propTypes = {
|
|
104
|
+
translations: prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
105
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
106
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.objectOf(prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
107
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.string,
|
|
108
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.arrayOf(prop_types__WEBPACK_IMPORTED_MODULE_1__.string),
|
|
109
|
+
])),
|
|
110
|
+
]),
|
|
111
|
+
plural: prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
112
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
113
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.string,
|
|
114
|
+
]),
|
|
115
|
+
children: prop_types__WEBPACK_IMPORTED_MODULE_1__.oneOfType([
|
|
116
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.node,
|
|
117
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1__.arrayOf(prop_types__WEBPACK_IMPORTED_MODULE_1__.node),
|
|
118
|
+
]),
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
TextDomain.defaultProps = {
|
|
122
|
+
translations: {},
|
|
123
|
+
plural: 'n != 1',
|
|
124
|
+
children: [],
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
TextDomain.childContextTypes = {
|
|
128
|
+
gettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
129
|
+
ngettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
130
|
+
xgettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
131
|
+
nxgettext: prop_types__WEBPACK_IMPORTED_MODULE_1__.func,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomain);
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
/***/ }),
|
|
@@ -148,12 +148,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
148
148
|
/* harmony export */ });
|
|
149
149
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
150
150
|
/* harmony import */ var _buildTextDomain_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./buildTextDomain.js */ "./buildTextDomain.js");
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const TextDomainContext = react__WEBPACK_IMPORTED_MODULE_0__.createContext((0,_buildTextDomain_js__WEBPACK_IMPORTED_MODULE_1__["default"])({}, 'n != 1'));
|
|
155
|
-
|
|
156
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomainContext);
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
const TextDomainContext = react__WEBPACK_IMPORTED_MODULE_0__.createContext((0,_buildTextDomain_js__WEBPACK_IMPORTED_MODULE_1__["default"])({}, 'n != 1'));
|
|
155
|
+
|
|
156
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomainContext);
|
|
157
157
|
|
|
158
158
|
|
|
159
159
|
/***/ }),
|
|
@@ -169,24 +169,24 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
169
169
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
170
170
|
/* harmony export */ });
|
|
171
171
|
/* harmony import */ var _gettext_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./gettext.js */ "./gettext.js");
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* TODO: We need to add description here
|
|
176
|
-
* @param {object} translations JSON
|
|
177
|
-
* @param {any} plural TODO: No idea obout type
|
|
178
|
-
* @returns {object} JSON
|
|
179
|
-
*/
|
|
180
|
-
function buildTextDomain(translations = {}, plural = "n != 1") {
|
|
181
|
-
return {
|
|
182
|
-
gettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.gettext.bind(null, translations),
|
|
183
|
-
ngettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.ngettext.bind(null, translations, plural),
|
|
184
|
-
xgettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.xgettext.bind(null, translations),
|
|
185
|
-
nxgettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.nxgettext.bind(null, translations, plural)
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (buildTextDomain);
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* TODO: We need to add description here
|
|
176
|
+
* @param {object} translations JSON
|
|
177
|
+
* @param {any} plural TODO: No idea obout type
|
|
178
|
+
* @returns {object} JSON
|
|
179
|
+
*/
|
|
180
|
+
function buildTextDomain(translations = {}, plural = "n != 1") {
|
|
181
|
+
return {
|
|
182
|
+
gettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.gettext.bind(null, translations),
|
|
183
|
+
ngettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.ngettext.bind(null, translations, plural),
|
|
184
|
+
xgettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.xgettext.bind(null, translations),
|
|
185
|
+
nxgettext: _gettext_js__WEBPACK_IMPORTED_MODULE_0__.nxgettext.bind(null, translations, plural)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (buildTextDomain);
|
|
190
190
|
|
|
191
191
|
|
|
192
192
|
/***/ }),
|
|
@@ -205,129 +205,129 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
205
205
|
/* harmony export */ nxgettext: () => (/* binding */ nxgettext),
|
|
206
206
|
/* harmony export */ xgettext: () => (/* binding */ xgettext)
|
|
207
207
|
/* harmony export */ });
|
|
208
|
-
const DELIMITER = "\u0004"; // End of Transmission (EOT)
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* TODO: We need to add description here
|
|
212
|
-
* @param {any} catalog string or function
|
|
213
|
-
* @returns {string} string or string from a function
|
|
214
|
-
*/
|
|
215
|
-
function getTranslations(catalog) {
|
|
216
|
-
return typeof catalog === "function" ? catalog() : catalog;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* TODO: We need to add description here
|
|
221
|
-
* @param {any} plural string or function
|
|
222
|
-
* @param {any} n TODO: No idea what will pass in it
|
|
223
|
-
* @returns {any} 0 if nothing
|
|
224
|
-
*/
|
|
225
|
-
function getPluralForm(plural, n) {
|
|
226
|
-
// return 0 if n is not integer
|
|
227
|
-
if (Number.isNaN(parseInt(n, 10))) {
|
|
228
|
-
return 0;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// if pluralForm is function, use it to get plural form index
|
|
232
|
-
if (typeof plural === "function") {
|
|
233
|
-
return plural(n);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// if pluralForm is string and contains only "n", "0-9", " ", "!=?:%+-/*><&|()"
|
|
237
|
-
// characters, then we can "eval" it to calculate plural form
|
|
238
|
-
if (typeof plural === "string" && !plural.match(/[^n0-9 !=?:%+-/*><&|()]/i)) {
|
|
239
|
-
/* eslint-disable no-new-func */
|
|
240
|
-
const calcPlural = Function("n", `return ${plural}`);
|
|
241
|
-
/* eslint-enable no-new-func */
|
|
242
|
-
return +calcPlural(n);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return 0;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* TODO: We need to add description here
|
|
250
|
-
* @param {string} catalog Catalog
|
|
251
|
-
* @param {string} message Message
|
|
252
|
-
* @returns {string} Message
|
|
253
|
-
*/
|
|
254
|
-
function gettext(catalog, message) {
|
|
255
|
-
const messages = getTranslations(catalog);
|
|
256
|
-
return Object.prototype.hasOwnProperty.call(messages, message)
|
|
257
|
-
? messages[message]
|
|
258
|
-
: message;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* TODO: WE need to add description here
|
|
263
|
-
* @param {string} catalog Catalog
|
|
264
|
-
* @param {string} plurality Plurality
|
|
265
|
-
* @param {string} singular Singular
|
|
266
|
-
* @param {string} plural Plural
|
|
267
|
-
* @param {number} n n
|
|
268
|
-
* @returns {string} Message
|
|
269
|
-
*/
|
|
270
|
-
function ngettext(catalog, plurality, singular, plural, n) {
|
|
271
|
-
const messages = getTranslations(catalog);
|
|
272
|
-
const pluralIndex = getPluralForm(plurality, n);
|
|
273
|
-
const defaultValue = n > 1 ? plural : singular;
|
|
274
|
-
|
|
275
|
-
return Object.prototype.hasOwnProperty.call(messages, singular) &&
|
|
276
|
-
Array.isArray(messages[singular]) &&
|
|
277
|
-
messages[singular].length > pluralIndex &&
|
|
278
|
-
pluralIndex >= 0
|
|
279
|
-
? messages[singular][pluralIndex]
|
|
280
|
-
: defaultValue;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* TODO: We need to add description here
|
|
285
|
-
* @param {string} catalog Catalog
|
|
286
|
-
* @param {string} message Message
|
|
287
|
-
* @param {string} context Context
|
|
288
|
-
* @returns {string} Message
|
|
289
|
-
*/
|
|
290
|
-
function xgettext(catalog, message, context) {
|
|
291
|
-
const messages = getTranslations(catalog);
|
|
292
|
-
const key = context + DELIMITER + message;
|
|
293
|
-
|
|
294
|
-
return Object.prototype.hasOwnProperty.call(messages, key)
|
|
295
|
-
? messages[key]
|
|
296
|
-
: message;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* TODO: We need to add description here
|
|
301
|
-
* @param {string} catalog Catalog
|
|
302
|
-
* @param {string} plurality Plurality
|
|
303
|
-
* @param {string} singular Singular
|
|
304
|
-
* @param {string} plural Plural
|
|
305
|
-
* @param {number} n n
|
|
306
|
-
* @param {string} context Context
|
|
307
|
-
* @returns {string} Message
|
|
308
|
-
*/
|
|
309
|
-
function nxgettext(catalog, plurality, singular, plural, n, context) {
|
|
310
|
-
const messages = getTranslations(catalog);
|
|
311
|
-
const pluralIndex = getPluralForm(plurality, n);
|
|
312
|
-
const defaultValue = n > 1 ? plural : singular;
|
|
313
|
-
const key = context + DELIMITER + singular;
|
|
314
|
-
|
|
315
|
-
return Object.prototype.hasOwnProperty.call(messages, key) &&
|
|
316
|
-
Array.isArray(messages[key]) &&
|
|
317
|
-
messages[key].length > pluralIndex &&
|
|
318
|
-
pluralIndex >= 0
|
|
319
|
-
? messages[key][pluralIndex]
|
|
320
|
-
: defaultValue;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const allDomain = {
|
|
324
|
-
gettext,
|
|
325
|
-
ngettext,
|
|
326
|
-
xgettext,
|
|
327
|
-
nxgettext
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (allDomain);
|
|
208
|
+
const DELIMITER = "\u0004"; // End of Transmission (EOT)
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* TODO: We need to add description here
|
|
212
|
+
* @param {any} catalog string or function
|
|
213
|
+
* @returns {string} string or string from a function
|
|
214
|
+
*/
|
|
215
|
+
function getTranslations(catalog) {
|
|
216
|
+
return typeof catalog === "function" ? catalog() : catalog;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* TODO: We need to add description here
|
|
221
|
+
* @param {any} plural string or function
|
|
222
|
+
* @param {any} n TODO: No idea what will pass in it
|
|
223
|
+
* @returns {any} 0 if nothing
|
|
224
|
+
*/
|
|
225
|
+
function getPluralForm(plural, n) {
|
|
226
|
+
// return 0 if n is not integer
|
|
227
|
+
if (Number.isNaN(parseInt(n, 10))) {
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// if pluralForm is function, use it to get plural form index
|
|
232
|
+
if (typeof plural === "function") {
|
|
233
|
+
return plural(n);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// if pluralForm is string and contains only "n", "0-9", " ", "!=?:%+-/*><&|()"
|
|
237
|
+
// characters, then we can "eval" it to calculate plural form
|
|
238
|
+
if (typeof plural === "string" && !plural.match(/[^n0-9 !=?:%+-/*><&|()]/i)) {
|
|
239
|
+
/* eslint-disable no-new-func */
|
|
240
|
+
const calcPlural = Function("n", `return ${plural}`);
|
|
241
|
+
/* eslint-enable no-new-func */
|
|
242
|
+
return +calcPlural(n);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return 0;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* TODO: We need to add description here
|
|
250
|
+
* @param {string} catalog Catalog
|
|
251
|
+
* @param {string} message Message
|
|
252
|
+
* @returns {string} Message
|
|
253
|
+
*/
|
|
254
|
+
function gettext(catalog, message) {
|
|
255
|
+
const messages = getTranslations(catalog);
|
|
256
|
+
return Object.prototype.hasOwnProperty.call(messages, message)
|
|
257
|
+
? messages[message]
|
|
258
|
+
: message;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* TODO: WE need to add description here
|
|
263
|
+
* @param {string} catalog Catalog
|
|
264
|
+
* @param {string} plurality Plurality
|
|
265
|
+
* @param {string} singular Singular
|
|
266
|
+
* @param {string} plural Plural
|
|
267
|
+
* @param {number} n n
|
|
268
|
+
* @returns {string} Message
|
|
269
|
+
*/
|
|
270
|
+
function ngettext(catalog, plurality, singular, plural, n) {
|
|
271
|
+
const messages = getTranslations(catalog);
|
|
272
|
+
const pluralIndex = getPluralForm(plurality, n);
|
|
273
|
+
const defaultValue = n > 1 ? plural : singular;
|
|
274
|
+
|
|
275
|
+
return Object.prototype.hasOwnProperty.call(messages, singular) &&
|
|
276
|
+
Array.isArray(messages[singular]) &&
|
|
277
|
+
messages[singular].length > pluralIndex &&
|
|
278
|
+
pluralIndex >= 0
|
|
279
|
+
? messages[singular][pluralIndex]
|
|
280
|
+
: defaultValue;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* TODO: We need to add description here
|
|
285
|
+
* @param {string} catalog Catalog
|
|
286
|
+
* @param {string} message Message
|
|
287
|
+
* @param {string} context Context
|
|
288
|
+
* @returns {string} Message
|
|
289
|
+
*/
|
|
290
|
+
function xgettext(catalog, message, context) {
|
|
291
|
+
const messages = getTranslations(catalog);
|
|
292
|
+
const key = context + DELIMITER + message;
|
|
293
|
+
|
|
294
|
+
return Object.prototype.hasOwnProperty.call(messages, key)
|
|
295
|
+
? messages[key]
|
|
296
|
+
: message;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* TODO: We need to add description here
|
|
301
|
+
* @param {string} catalog Catalog
|
|
302
|
+
* @param {string} plurality Plurality
|
|
303
|
+
* @param {string} singular Singular
|
|
304
|
+
* @param {string} plural Plural
|
|
305
|
+
* @param {number} n n
|
|
306
|
+
* @param {string} context Context
|
|
307
|
+
* @returns {string} Message
|
|
308
|
+
*/
|
|
309
|
+
function nxgettext(catalog, plurality, singular, plural, n, context) {
|
|
310
|
+
const messages = getTranslations(catalog);
|
|
311
|
+
const pluralIndex = getPluralForm(plurality, n);
|
|
312
|
+
const defaultValue = n > 1 ? plural : singular;
|
|
313
|
+
const key = context + DELIMITER + singular;
|
|
314
|
+
|
|
315
|
+
return Object.prototype.hasOwnProperty.call(messages, key) &&
|
|
316
|
+
Array.isArray(messages[key]) &&
|
|
317
|
+
messages[key].length > pluralIndex &&
|
|
318
|
+
pluralIndex >= 0
|
|
319
|
+
? messages[key][pluralIndex]
|
|
320
|
+
: defaultValue;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const allDomain = {
|
|
324
|
+
gettext,
|
|
325
|
+
ngettext,
|
|
326
|
+
xgettext,
|
|
327
|
+
nxgettext
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (allDomain);
|
|
331
331
|
|
|
332
332
|
|
|
333
333
|
/***/ }),
|
|
@@ -345,41 +345,41 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
345
345
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
346
346
|
/* harmony import */ var hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! hoist-non-react-statics */ "hoist-non-react-statics");
|
|
347
347
|
/* harmony import */ var _TextDomain_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TextDomain.js */ "./TextDomain.js");
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const withGettext = (translations = {}, pluralForm = 'n != 1', options = {}) => (WrappedComponent) => {
|
|
353
|
-
const args = Object.assign({ withRef: false }, options);
|
|
354
|
-
|
|
355
|
-
class WithGettext extends _TextDomain_js__WEBPACK_IMPORTED_MODULE_2__["default"] {
|
|
356
|
-
|
|
357
|
-
getWrappedComponent() {
|
|
358
|
-
return this.refs.wrappedComponent;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
render() {
|
|
362
|
-
const newprops = Object.assign({}, this.props);
|
|
363
|
-
if (args.withRef) {
|
|
364
|
-
newprops.ref = 'wrappedComponent';
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return react__WEBPACK_IMPORTED_MODULE_0__.createElement(WrappedComponent, newprops);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
WithGettext.defaultProps = {
|
|
373
|
-
translations,
|
|
374
|
-
plural: pluralForm,
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
WithGettext.displayName = `withGettext(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
378
|
-
|
|
379
|
-
return hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1__(WithGettext, WrappedComponent);
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (withGettext);
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
const withGettext = (translations = {}, pluralForm = 'n != 1', options = {}) => (WrappedComponent) => {
|
|
353
|
+
const args = Object.assign({ withRef: false }, options);
|
|
354
|
+
|
|
355
|
+
class WithGettext extends _TextDomain_js__WEBPACK_IMPORTED_MODULE_2__["default"] {
|
|
356
|
+
|
|
357
|
+
getWrappedComponent() {
|
|
358
|
+
return this.refs.wrappedComponent;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
render() {
|
|
362
|
+
const newprops = Object.assign({}, this.props);
|
|
363
|
+
if (args.withRef) {
|
|
364
|
+
newprops.ref = 'wrappedComponent';
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return react__WEBPACK_IMPORTED_MODULE_0__.createElement(WrappedComponent, newprops);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
WithGettext.defaultProps = {
|
|
373
|
+
translations,
|
|
374
|
+
plural: pluralForm,
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
WithGettext.displayName = `withGettext(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
378
|
+
|
|
379
|
+
return hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1__(WithGettext, WrappedComponent);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (withGettext);
|
|
383
383
|
|
|
384
384
|
|
|
385
385
|
/***/ })
|
|
@@ -457,14 +457,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
457
457
|
/* harmony import */ var _TextDomain_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TextDomain.js */ "./TextDomain.js");
|
|
458
458
|
/* harmony import */ var _TextDomainContext_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TextDomainContext.js */ "./TextDomainContext.js");
|
|
459
459
|
/* harmony import */ var _buildTextDomain_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./buildTextDomain.js */ "./buildTextDomain.js");
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_withGettext_js__WEBPACK_IMPORTED_MODULE_0__["default"]);
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_withGettext_js__WEBPACK_IMPORTED_MODULE_0__["default"]);
|
|
468
468
|
|
|
469
469
|
})();
|
|
470
470
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React"),require("hoistNonReactStatic"),require("PropTypes")):"function"==typeof define&&define.amd?define(["React","hoistNonReactStatic","PropTypes"],e):"object"==typeof exports?exports.ReactGettext=e(require("React"),require("hoistNonReactStatic"),require("PropTypes")):t.ReactGettext=e(t.React,t.hoistNonReactStatic,t.PropTypes)}(self,((t,e,n)=>(()=>{"use strict";var r={262:t=>{t.exports=n},883:e=>{e.exports=t},419:t=>{t.exports=e}},o={};function s(t){var e=o[t];if(void 0!==e)return e.exports;var n=o[t]={exports:{}};return r[t](n,n.exports,s),n.exports}s.d=(t,e)=>{for(var n in e)s.o(e,n)&&!s.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{s.r(i),s.d(i,{TextDomain:()=>x,TextDomainContext:()=>d,buildTextDomain:()=>f,default:()=>y});var t=s(883),e=s(419),n=s(262);function r(t){return"function"==typeof t?t():t}function o(t,e){return Number.isNaN(parseInt(e,10))?0:"function"==typeof t?t(e):"string"!=typeof t||t.match(/[^n0-9 !=?:%+-/*><&|()]/i)?0:+Function("n",`return ${t}`)(e)}function a(t,e){const n=r(t);return Object.prototype.hasOwnProperty.call(n,e)?n[e]:e}function p(t,e,n,s,i){const a=r(t),p=o(e,i),c=i>1?s:n;return Object.prototype.hasOwnProperty.call(a,n)&&Array.isArray(a[n])&&a[n].length>p&&p>=0?a[n][p]:c}function c(t,e,n){const o=r(t),s=n+""+e;return Object.prototype.hasOwnProperty.call(o,s)?o[s]:e}function u(t,e,n,s,i,a){const p=r(t),c=o(e,i),u=i>1?s:n,l=a+""+n;return Object.prototype.hasOwnProperty.call(p,l)&&Array.isArray(p[l])&&p[l].length>c&&c>=0?p[l][c]:u}class l extends t.Component{getChildContext(){const t=this;return{gettext:t.gettext.bind(t),xgettext:t.xgettext.bind(t),ngettext:t.ngettext.bind(t),nxgettext:t.nxgettext.bind(t)}}gettext(t){const{translations:e}=this.props;return a(e,t)}ngettext(t,e,n){const{translations:r,plural:o}=this.props;return p(r,o,t,e,n)}xgettext(t,e){const{translations:n}=this.props;return c(n,t,e)}nxgettext(t,e,n,r){const{translations:o,plural:s}=this.props;return u(o,s,t,e,n,r)}render(){const{children:t}=this.props;return t}}l.propTypes={translations:n.oneOfType([n.func,n.objectOf(n.oneOfType([n.string,n.arrayOf(n.string)]))]),plural:n.oneOfType([n.func,n.string]),children:n.oneOfType([n.node,n.arrayOf(n.node)])},l.defaultProps={translations:{},plural:"n != 1",children:[]},l.childContextTypes={gettext:n.func,ngettext:n.func,xgettext:n.func,nxgettext:n.func};const x=l,f=function(t={},e="n != 1"){return{gettext:a.bind(null,t),ngettext:p.bind(null,t,e),xgettext:c.bind(null,t),nxgettext:u.bind(null,t,e)}},d=t.createContext(f({},"n != 1")),y=(n={},r="n != 1",o={})=>s=>{const i=Object.assign({withRef:!1},o);class a extends x{getWrappedComponent(){return this.refs.wrappedComponent}render(){const e=Object.assign({},this.props);return i.withRef&&(e.ref="wrappedComponent"),t.createElement(s,e)}}return a.defaultProps={translations:n,plural:r},a.displayName=`withGettext(${s.displayName||s.name||"Component"})`,e(a,s)}})(),i})()));
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { gettext, ngettext, xgettext, nxgettext } from './gettext.js';
|
|
4
|
+
class TextDomain extends Component {
|
|
5
|
+
getChildContext() {
|
|
6
|
+
const self = this;
|
|
7
|
+
return {
|
|
8
|
+
gettext: self.gettext.bind(self),
|
|
9
|
+
xgettext: self.xgettext.bind(self),
|
|
10
|
+
ngettext: self.ngettext.bind(self),
|
|
11
|
+
nxgettext: self.nxgettext.bind(self)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
gettext(message) {
|
|
15
|
+
const {
|
|
16
|
+
translations
|
|
17
|
+
} = this.props;
|
|
18
|
+
return gettext(translations, message);
|
|
19
|
+
}
|
|
20
|
+
ngettext(singular, plural, n) {
|
|
21
|
+
const {
|
|
22
|
+
translations,
|
|
23
|
+
plural: plurality
|
|
24
|
+
} = this.props;
|
|
25
|
+
return ngettext(translations, plurality, singular, plural, n);
|
|
26
|
+
}
|
|
27
|
+
xgettext(message, context) {
|
|
28
|
+
const {
|
|
29
|
+
translations
|
|
30
|
+
} = this.props;
|
|
31
|
+
return xgettext(translations, message, context);
|
|
32
|
+
}
|
|
33
|
+
nxgettext(singular, plural, n, context) {
|
|
34
|
+
const {
|
|
35
|
+
translations,
|
|
36
|
+
plural: plurality
|
|
37
|
+
} = this.props;
|
|
38
|
+
return nxgettext(translations, plurality, singular, plural, n, context);
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
const {
|
|
42
|
+
children
|
|
43
|
+
} = this.props;
|
|
44
|
+
return children;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
TextDomain.propTypes = {
|
|
48
|
+
translations: PropTypes.oneOfType([PropTypes.func, PropTypes.objectOf(PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]))]),
|
|
49
|
+
plural: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
50
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)])
|
|
51
|
+
};
|
|
52
|
+
TextDomain.defaultProps = {
|
|
53
|
+
translations: {},
|
|
54
|
+
plural: 'n != 1',
|
|
55
|
+
children: []
|
|
56
|
+
};
|
|
57
|
+
TextDomain.childContextTypes = {
|
|
58
|
+
gettext: PropTypes.func,
|
|
59
|
+
ngettext: PropTypes.func,
|
|
60
|
+
xgettext: PropTypes.func,
|
|
61
|
+
nxgettext: PropTypes.func
|
|
62
|
+
};
|
|
63
|
+
export default TextDomain;
|