@absolutesight/react-gettext 0.0.1 → 1.0.1
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 -48
- package/LICENSE +21 -21
- package/README.md +365 -369
- package/dist/react-gettext.js +287 -296
- package/dist/react-gettext.min.js +1 -1
- package/lib/TextDomain.js +1 -1
- package/lib/buildTextDomain.js +5 -5
- package/lib/gettext.js +37 -37
- package/lib/index.js +1 -1
- package/lib/withGettext.js +1 -1
- package/package.json +83 -81
- package/src/TextDomain.js +82 -82
- package/src/TextDomainContext.js +6 -7
- package/src/buildTextDomain.js +18 -19
- package/src/gettext.js +123 -123
- package/src/index.js +12 -12
- package/src/withGettext.js +35 -40
- package/lib/Textdomain.js +0 -70
- package/lib/TextdomainContext.js +0 -11
- package/lib/buildTextdomain.js +0 -24
package/dist/react-gettext.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
2
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
-
module.exports = factory(require("React"), require("
|
|
3
|
+
module.exports = factory(require("React"), require("hoistNonReactStatic"), require("PropTypes"));
|
|
4
4
|
else if(typeof define === 'function' && define.amd)
|
|
5
|
-
define(["React", "
|
|
5
|
+
define(["React", "hoistNonReactStatic", "PropTypes"], factory);
|
|
6
6
|
else if(typeof exports === 'object')
|
|
7
|
-
exports["ReactGettext"] = factory(require("React"), require("
|
|
7
|
+
exports["ReactGettext"] = factory(require("React"), require("hoistNonReactStatic"), require("PropTypes"));
|
|
8
8
|
else
|
|
9
|
-
root["ReactGettext"] = factory(root["React"], root["
|
|
10
|
-
})(self, (__WEBPACK_EXTERNAL_MODULE_react__,
|
|
9
|
+
root["ReactGettext"] = factory(root["React"], root["hoistNonReactStatic"], root["PropTypes"]);
|
|
10
|
+
})(self, (__WEBPACK_EXTERNAL_MODULE_react__, __WEBPACK_EXTERNAL_MODULE_hoist_non_react_statics__, __WEBPACK_EXTERNAL_MODULE_prop_types__) => {
|
|
11
11
|
return /******/ (() => { // webpackBootstrap
|
|
12
12
|
/******/ "use strict";
|
|
13
13
|
/******/ var __webpack_modules__ = ({
|
|
@@ -22,90 +22,88 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
22
22
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
23
23
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
24
24
|
/* harmony export */ });
|
|
25
|
-
/* harmony import */ var
|
|
26
|
-
/* harmony import */ var
|
|
27
|
-
/* harmony import */ var
|
|
28
|
-
/* harmony import */ var
|
|
29
|
-
/* harmony import */ var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomain);
|
|
25
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
26
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
27
|
+
/* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prop-types */ "prop-types");
|
|
28
|
+
/* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_1__);
|
|
29
|
+
/* harmony import */ var _gettext__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./gettext */ "./gettext.js");
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TextDomain extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
|
|
36
|
+
|
|
37
|
+
getChildContext() {
|
|
38
|
+
const self = this;
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
gettext: self.gettext.bind(self),
|
|
42
|
+
xgettext: self.xgettext.bind(self),
|
|
43
|
+
ngettext: self.ngettext.bind(self),
|
|
44
|
+
nxgettext: self.nxgettext.bind(self),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
gettext(message) {
|
|
49
|
+
const { translations } = this.props;
|
|
50
|
+
return (0,_gettext__WEBPACK_IMPORTED_MODULE_2__.gettext)(translations, message);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ngettext(singular, plural, n) {
|
|
54
|
+
const { translations, plural: plurality } = this.props;
|
|
55
|
+
return (0,_gettext__WEBPACK_IMPORTED_MODULE_2__.ngettext)(translations, plurality, singular, plural, n);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
xgettext(message, context) {
|
|
59
|
+
const { translations } = this.props;
|
|
60
|
+
return (0,_gettext__WEBPACK_IMPORTED_MODULE_2__.xgettext)(translations, message, context);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
nxgettext(singular, plural, n, context) {
|
|
64
|
+
const { translations, plural: plurality } = this.props;
|
|
65
|
+
return (0,_gettext__WEBPACK_IMPORTED_MODULE_2__.nxgettext)(translations, plurality, singular, plural, n, context);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
render() {
|
|
69
|
+
const { children } = this.props;
|
|
70
|
+
return children;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
TextDomain.propTypes = {
|
|
76
|
+
translations: prop_types__WEBPACK_IMPORTED_MODULE_1___default().oneOfType([
|
|
77
|
+
(prop_types__WEBPACK_IMPORTED_MODULE_1___default().func),
|
|
78
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1___default().objectOf(prop_types__WEBPACK_IMPORTED_MODULE_1___default().oneOfType([
|
|
79
|
+
(prop_types__WEBPACK_IMPORTED_MODULE_1___default().string),
|
|
80
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1___default().arrayOf((prop_types__WEBPACK_IMPORTED_MODULE_1___default().string)),
|
|
81
|
+
])),
|
|
82
|
+
]),
|
|
83
|
+
plural: prop_types__WEBPACK_IMPORTED_MODULE_1___default().oneOfType([
|
|
84
|
+
(prop_types__WEBPACK_IMPORTED_MODULE_1___default().func),
|
|
85
|
+
(prop_types__WEBPACK_IMPORTED_MODULE_1___default().string),
|
|
86
|
+
]),
|
|
87
|
+
children: prop_types__WEBPACK_IMPORTED_MODULE_1___default().oneOfType([
|
|
88
|
+
(prop_types__WEBPACK_IMPORTED_MODULE_1___default().node),
|
|
89
|
+
prop_types__WEBPACK_IMPORTED_MODULE_1___default().arrayOf((prop_types__WEBPACK_IMPORTED_MODULE_1___default().node)),
|
|
90
|
+
]),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
TextDomain.defaultProps = {
|
|
94
|
+
translations: {},
|
|
95
|
+
plural: 'n != 1',
|
|
96
|
+
children: [],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
TextDomain.childContextTypes = {
|
|
100
|
+
gettext: (prop_types__WEBPACK_IMPORTED_MODULE_1___default().func),
|
|
101
|
+
ngettext: (prop_types__WEBPACK_IMPORTED_MODULE_1___default().func),
|
|
102
|
+
xgettext: (prop_types__WEBPACK_IMPORTED_MODULE_1___default().func),
|
|
103
|
+
nxgettext: (prop_types__WEBPACK_IMPORTED_MODULE_1___default().func),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomain);
|
|
109
107
|
|
|
110
108
|
|
|
111
109
|
/***/ }),
|
|
@@ -123,13 +121,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
123
121
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
124
122
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
125
123
|
/* harmony import */ var _buildTextDomain__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./buildTextDomain */ "./buildTextDomain.js");
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const TextDomainContext = react__WEBPACK_IMPORTED_MODULE_0___default().createContext((0,_buildTextDomain__WEBPACK_IMPORTED_MODULE_1__["default"])({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomainContext);
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
const TextDomainContext = react__WEBPACK_IMPORTED_MODULE_0___default().createContext((0,_buildTextDomain__WEBPACK_IMPORTED_MODULE_1__["default"])({}, 'n != 1'));
|
|
128
|
+
|
|
129
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomainContext);
|
|
133
130
|
|
|
134
131
|
|
|
135
132
|
/***/ }),
|
|
@@ -145,25 +142,24 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
145
142
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
146
143
|
/* harmony export */ });
|
|
147
144
|
/* harmony import */ var _gettext__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./gettext */ "./gettext.js");
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* TODO: We need to add description here
|
|
152
|
-
* @param {object} translations JSON
|
|
153
|
-
* @param {any} plural TODO: No idea obout type
|
|
154
|
-
* @returns {object} JSON
|
|
155
|
-
*/
|
|
156
|
-
function buildTextDomain(translations = {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (buildTextDomain);
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* TODO: We need to add description here
|
|
149
|
+
* @param {object} translations JSON
|
|
150
|
+
* @param {any} plural TODO: No idea obout type
|
|
151
|
+
* @returns {object} JSON
|
|
152
|
+
*/
|
|
153
|
+
function buildTextDomain(translations = {}, plural = "n != 1") {
|
|
154
|
+
return {
|
|
155
|
+
gettext: _gettext__WEBPACK_IMPORTED_MODULE_0__.gettext.bind(null, translations),
|
|
156
|
+
ngettext: _gettext__WEBPACK_IMPORTED_MODULE_0__.ngettext.bind(null, translations, plural),
|
|
157
|
+
xgettext: _gettext__WEBPACK_IMPORTED_MODULE_0__.xgettext.bind(null, translations),
|
|
158
|
+
nxgettext: _gettext__WEBPACK_IMPORTED_MODULE_0__.nxgettext.bind(null, translations, plural)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (buildTextDomain);
|
|
167
163
|
|
|
168
164
|
|
|
169
165
|
/***/ }),
|
|
@@ -182,129 +178,129 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
182
178
|
/* harmony export */ nxgettext: () => (/* binding */ nxgettext),
|
|
183
179
|
/* harmony export */ xgettext: () => (/* binding */ xgettext)
|
|
184
180
|
/* harmony export */ });
|
|
185
|
-
const DELIMITER = "\u0004"; // End of Transmission (EOT)
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* TODO: We need to add description here
|
|
189
|
-
* @param {any} catalog string or function
|
|
190
|
-
* @returns {string} string or string from a function
|
|
191
|
-
*/
|
|
192
|
-
function getTranslations(catalog) {
|
|
193
|
-
return typeof catalog === "function" ? catalog() : catalog;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* TODO: We need to add description here
|
|
198
|
-
* @param {any} plural string or function
|
|
199
|
-
* @param {any} n TODO: No idea what will pass in it
|
|
200
|
-
* @returns {any} 0 if nothing
|
|
201
|
-
*/
|
|
202
|
-
function getPluralForm(plural, n) {
|
|
203
|
-
// return 0 if n is not integer
|
|
204
|
-
if (Number.isNaN(parseInt(n, 10))) {
|
|
205
|
-
return 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// if pluralForm is function, use it to get plural form index
|
|
209
|
-
if (typeof plural === "function") {
|
|
210
|
-
return plural(n);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// if pluralForm is string and contains only "n", "0-9", " ", "!=?:%+-/*><&|()"
|
|
214
|
-
// characters, then we can "eval" it to calculate plural form
|
|
215
|
-
if (typeof plural === "string" && !plural.match(/[^n0-9 !=?:%+-/*><&|()]/i)) {
|
|
216
|
-
/* eslint-disable no-new-func */
|
|
217
|
-
const calcPlural = Function("n", `return ${plural}`);
|
|
218
|
-
/* eslint-enable no-new-func */
|
|
219
|
-
return +calcPlural(n);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return 0;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* TODO: We need to add description here
|
|
227
|
-
* @param {string} catalog Catalog
|
|
228
|
-
* @param {string} message Message
|
|
229
|
-
* @returns {string} Message
|
|
230
|
-
*/
|
|
231
|
-
function gettext(catalog, message) {
|
|
232
|
-
const messages = getTranslations(catalog);
|
|
233
|
-
return Object.prototype.hasOwnProperty.call(messages, message)
|
|
234
|
-
? messages[message]
|
|
235
|
-
: message;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* TODO: WE need to add description here
|
|
240
|
-
* @param {string} catalog Catalog
|
|
241
|
-
* @param {string} plurality Plurality
|
|
242
|
-
* @param {string} singular Singular
|
|
243
|
-
* @param {string} plural Plural
|
|
244
|
-
* @param {number} n n
|
|
245
|
-
* @returns {string} Message
|
|
246
|
-
*/
|
|
247
|
-
function ngettext(catalog, plurality, singular, plural, n) {
|
|
248
|
-
const messages = getTranslations(catalog);
|
|
249
|
-
const pluralIndex = getPluralForm(plurality, n);
|
|
250
|
-
const defaultValue = n > 1 ? plural : singular;
|
|
251
|
-
|
|
252
|
-
return Object.prototype.hasOwnProperty.call(messages, singular) &&
|
|
253
|
-
Array.isArray(messages[singular]) &&
|
|
254
|
-
messages[singular].length > pluralIndex &&
|
|
255
|
-
pluralIndex >= 0
|
|
256
|
-
? messages[singular][pluralIndex]
|
|
257
|
-
: defaultValue;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* TODO: We need to add description here
|
|
262
|
-
* @param {string} catalog Catalog
|
|
263
|
-
* @param {string} message Message
|
|
264
|
-
* @param {string} context Context
|
|
265
|
-
* @returns {string} Message
|
|
266
|
-
*/
|
|
267
|
-
function xgettext(catalog, message, context) {
|
|
268
|
-
const messages = getTranslations(catalog);
|
|
269
|
-
const key = context + DELIMITER + message;
|
|
270
|
-
|
|
271
|
-
return Object.prototype.hasOwnProperty.call(messages, key)
|
|
272
|
-
? messages[key]
|
|
273
|
-
: message;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* TODO: We need to add description here
|
|
278
|
-
* @param {string} catalog Catalog
|
|
279
|
-
* @param {string} plurality Plurality
|
|
280
|
-
* @param {string} singular Singular
|
|
281
|
-
* @param {string} plural Plural
|
|
282
|
-
* @param {number} n n
|
|
283
|
-
* @param {string} context Context
|
|
284
|
-
* @returns {string} Message
|
|
285
|
-
*/
|
|
286
|
-
function nxgettext(catalog, plurality, singular, plural, n, context) {
|
|
287
|
-
const messages = getTranslations(catalog);
|
|
288
|
-
const pluralIndex = getPluralForm(plurality, n);
|
|
289
|
-
const defaultValue = n > 1 ? plural : singular;
|
|
290
|
-
const key = context + DELIMITER + singular;
|
|
291
|
-
|
|
292
|
-
return Object.prototype.hasOwnProperty.call(messages, key) &&
|
|
293
|
-
Array.isArray(messages[key]) &&
|
|
294
|
-
messages[key].length > pluralIndex &&
|
|
295
|
-
pluralIndex >= 0
|
|
296
|
-
? messages[key][pluralIndex]
|
|
297
|
-
: defaultValue;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const allDomain = {
|
|
301
|
-
gettext,
|
|
302
|
-
ngettext,
|
|
303
|
-
xgettext,
|
|
304
|
-
nxgettext
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (allDomain);
|
|
181
|
+
const DELIMITER = "\u0004"; // End of Transmission (EOT)
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* TODO: We need to add description here
|
|
185
|
+
* @param {any} catalog string or function
|
|
186
|
+
* @returns {string} string or string from a function
|
|
187
|
+
*/
|
|
188
|
+
function getTranslations(catalog) {
|
|
189
|
+
return typeof catalog === "function" ? catalog() : catalog;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* TODO: We need to add description here
|
|
194
|
+
* @param {any} plural string or function
|
|
195
|
+
* @param {any} n TODO: No idea what will pass in it
|
|
196
|
+
* @returns {any} 0 if nothing
|
|
197
|
+
*/
|
|
198
|
+
function getPluralForm(plural, n) {
|
|
199
|
+
// return 0 if n is not integer
|
|
200
|
+
if (Number.isNaN(parseInt(n, 10))) {
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// if pluralForm is function, use it to get plural form index
|
|
205
|
+
if (typeof plural === "function") {
|
|
206
|
+
return plural(n);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// if pluralForm is string and contains only "n", "0-9", " ", "!=?:%+-/*><&|()"
|
|
210
|
+
// characters, then we can "eval" it to calculate plural form
|
|
211
|
+
if (typeof plural === "string" && !plural.match(/[^n0-9 !=?:%+-/*><&|()]/i)) {
|
|
212
|
+
/* eslint-disable no-new-func */
|
|
213
|
+
const calcPlural = Function("n", `return ${plural}`);
|
|
214
|
+
/* eslint-enable no-new-func */
|
|
215
|
+
return +calcPlural(n);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* TODO: We need to add description here
|
|
223
|
+
* @param {string} catalog Catalog
|
|
224
|
+
* @param {string} message Message
|
|
225
|
+
* @returns {string} Message
|
|
226
|
+
*/
|
|
227
|
+
function gettext(catalog, message) {
|
|
228
|
+
const messages = getTranslations(catalog);
|
|
229
|
+
return Object.prototype.hasOwnProperty.call(messages, message)
|
|
230
|
+
? messages[message]
|
|
231
|
+
: message;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* TODO: WE need to add description here
|
|
236
|
+
* @param {string} catalog Catalog
|
|
237
|
+
* @param {string} plurality Plurality
|
|
238
|
+
* @param {string} singular Singular
|
|
239
|
+
* @param {string} plural Plural
|
|
240
|
+
* @param {number} n n
|
|
241
|
+
* @returns {string} Message
|
|
242
|
+
*/
|
|
243
|
+
function ngettext(catalog, plurality, singular, plural, n) {
|
|
244
|
+
const messages = getTranslations(catalog);
|
|
245
|
+
const pluralIndex = getPluralForm(plurality, n);
|
|
246
|
+
const defaultValue = n > 1 ? plural : singular;
|
|
247
|
+
|
|
248
|
+
return Object.prototype.hasOwnProperty.call(messages, singular) &&
|
|
249
|
+
Array.isArray(messages[singular]) &&
|
|
250
|
+
messages[singular].length > pluralIndex &&
|
|
251
|
+
pluralIndex >= 0
|
|
252
|
+
? messages[singular][pluralIndex]
|
|
253
|
+
: defaultValue;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* TODO: We need to add description here
|
|
258
|
+
* @param {string} catalog Catalog
|
|
259
|
+
* @param {string} message Message
|
|
260
|
+
* @param {string} context Context
|
|
261
|
+
* @returns {string} Message
|
|
262
|
+
*/
|
|
263
|
+
function xgettext(catalog, message, context) {
|
|
264
|
+
const messages = getTranslations(catalog);
|
|
265
|
+
const key = context + DELIMITER + message;
|
|
266
|
+
|
|
267
|
+
return Object.prototype.hasOwnProperty.call(messages, key)
|
|
268
|
+
? messages[key]
|
|
269
|
+
: message;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* TODO: We need to add description here
|
|
274
|
+
* @param {string} catalog Catalog
|
|
275
|
+
* @param {string} plurality Plurality
|
|
276
|
+
* @param {string} singular Singular
|
|
277
|
+
* @param {string} plural Plural
|
|
278
|
+
* @param {number} n n
|
|
279
|
+
* @param {string} context Context
|
|
280
|
+
* @returns {string} Message
|
|
281
|
+
*/
|
|
282
|
+
function nxgettext(catalog, plurality, singular, plural, n, context) {
|
|
283
|
+
const messages = getTranslations(catalog);
|
|
284
|
+
const pluralIndex = getPluralForm(plurality, n);
|
|
285
|
+
const defaultValue = n > 1 ? plural : singular;
|
|
286
|
+
const key = context + DELIMITER + singular;
|
|
287
|
+
|
|
288
|
+
return Object.prototype.hasOwnProperty.call(messages, key) &&
|
|
289
|
+
Array.isArray(messages[key]) &&
|
|
290
|
+
messages[key].length > pluralIndex &&
|
|
291
|
+
pluralIndex >= 0
|
|
292
|
+
? messages[key][pluralIndex]
|
|
293
|
+
: defaultValue;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const allDomain = {
|
|
297
|
+
gettext,
|
|
298
|
+
ngettext,
|
|
299
|
+
xgettext,
|
|
300
|
+
nxgettext
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (allDomain);
|
|
308
304
|
|
|
309
305
|
|
|
310
306
|
/***/ }),
|
|
@@ -321,49 +317,44 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
321
317
|
/* harmony export */ });
|
|
322
318
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
323
319
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
324
|
-
/* harmony import */ var
|
|
325
|
-
/* harmony import */ var
|
|
326
|
-
/* harmony import */ var
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const withGettext = (translations = {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_2___default()(WithGettext, WrappedComponent);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (withGettext);
|
|
320
|
+
/* harmony import */ var hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! hoist-non-react-statics */ "hoist-non-react-statics");
|
|
321
|
+
/* harmony import */ var hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1__);
|
|
322
|
+
/* harmony import */ var _TextDomain__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TextDomain */ "./TextDomain.js");
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
const withGettext = (translations = {}, pluralForm = 'n != 1', options = {}) => (WrappedComponent) => {
|
|
328
|
+
const args = Object.assign({ withRef: false }, options);
|
|
329
|
+
|
|
330
|
+
class WithGettext extends _TextDomain__WEBPACK_IMPORTED_MODULE_2__["default"] {
|
|
331
|
+
|
|
332
|
+
getWrappedComponent() {
|
|
333
|
+
return this.refs.wrappedComponent;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
render() {
|
|
337
|
+
const newprops = Object.assign({}, this.props);
|
|
338
|
+
if (args.withRef) {
|
|
339
|
+
newprops.ref = 'wrappedComponent';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return react__WEBPACK_IMPORTED_MODULE_0___default().createElement(WrappedComponent, newprops);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
WithGettext.defaultProps = {
|
|
348
|
+
translations,
|
|
349
|
+
plural: pluralForm,
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
WithGettext.displayName = `withGettext(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
353
|
+
|
|
354
|
+
return hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1___default()(WithGettext, WrappedComponent);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (withGettext);
|
|
367
358
|
|
|
368
359
|
|
|
369
360
|
/***/ }),
|
|
@@ -474,23 +465,23 @@ var __webpack_exports__ = {};
|
|
|
474
465
|
\******************/
|
|
475
466
|
__webpack_require__.r(__webpack_exports__);
|
|
476
467
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
477
|
-
/* harmony export */ TextDomain: () => (/* reexport safe */
|
|
478
|
-
/* harmony export */ TextDomainContext: () => (/* reexport safe */
|
|
479
|
-
/* harmony export */ buildTextDomain: () => (/* reexport safe */
|
|
468
|
+
/* harmony export */ TextDomain: () => (/* reexport safe */ _TextDomain__WEBPACK_IMPORTED_MODULE_1__["default"]),
|
|
469
|
+
/* harmony export */ TextDomainContext: () => (/* reexport safe */ _TextDomainContext__WEBPACK_IMPORTED_MODULE_2__["default"]),
|
|
470
|
+
/* harmony export */ buildTextDomain: () => (/* reexport safe */ _buildTextDomain__WEBPACK_IMPORTED_MODULE_3__["default"]),
|
|
480
471
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
481
472
|
/* harmony export */ });
|
|
482
|
-
/* harmony import */ var
|
|
483
|
-
/* harmony import */ var
|
|
484
|
-
/* harmony import */ var
|
|
485
|
-
/* harmony import */ var
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (
|
|
473
|
+
/* harmony import */ var _withGettext__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./withGettext */ "./withGettext.js");
|
|
474
|
+
/* harmony import */ var _TextDomain__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./TextDomain */ "./TextDomain.js");
|
|
475
|
+
/* harmony import */ var _TextDomainContext__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./TextDomainContext */ "./TextDomainContext.js");
|
|
476
|
+
/* harmony import */ var _buildTextDomain__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./buildTextDomain */ "./buildTextDomain.js");
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_withGettext__WEBPACK_IMPORTED_MODULE_0__["default"]);
|
|
494
485
|
|
|
495
486
|
})();
|
|
496
487
|
|