@absolutesight/react-gettext 0.0.1 → 1.0.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/CHANGELOG.md +1 -44
- package/LICENSE +1 -1
- package/README.md +16 -20
- package/dist/react-gettext.js +95 -104
- package/dist/react-gettext.min.js +1 -1
- package/lib/TextDomain.js +1 -1
- package/lib/Textdomain.js +5 -5
- package/lib/TextdomainContext.js +3 -3
- package/lib/buildTextdomain.js +2 -2
- package/lib/index.js +1 -1
- package/lib/withGettext.js +1 -1
- package/package.json +6 -4
- package/src/TextDomain.js +57 -57
- package/src/TextDomainContext.js +1 -2
- package/src/buildTextDomain.js +1 -2
- package/src/index.js +4 -4
- package/src/withGettext.js +21 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,48 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## v1.0.
|
|
3
|
+
## v1.0.0 (2024-02-06)
|
|
4
4
|
|
|
5
5
|
- Updated dependencies to the latest versions.
|
|
6
|
-
|
|
7
|
-
## v1.0.1 (2019-11-21)
|
|
8
|
-
|
|
9
|
-
- Fixed babel-preset-env browser targets.
|
|
10
|
-
- Updated dependencies to the latest versions.
|
|
11
|
-
|
|
12
|
-
## v1.0.0 (2019-07-15)
|
|
13
|
-
|
|
14
|
-
- Implemented TextDomainContext context that adheres the current version of Context APIs.
|
|
15
|
-
- Reworked Poedit example project to use new API.
|
|
16
|
-
|
|
17
|
-
## v0.4.0 (2017-08-17)
|
|
18
|
-
|
|
19
|
-
**Implemented enhancements:**
|
|
20
|
-
|
|
21
|
-
- Implemented ability to get wrapped component.
|
|
22
|
-
|
|
23
|
-
## v0.3.3 (2017-08-12)
|
|
24
|
-
|
|
25
|
-
**Implemented enhancements:**
|
|
26
|
-
|
|
27
|
-
- Updated dev dependencies to use latest versions.
|
|
28
|
-
- Updated hoist-non-react-statics peer dependency to support version 2+.
|
|
29
|
-
|
|
30
|
-
## v0.3.2 (2017-08-04)
|
|
31
|
-
|
|
32
|
-
**Implemented enhancements:**
|
|
33
|
-
|
|
34
|
-
- Added a sample application which shows how to use Poedit and React/React-Router conjunction to make translatable applications.
|
|
35
|
-
- Added ability to import TextDomain component directly.
|
|
36
|
-
|
|
37
|
-
## v0.3.1 (2017-06-28)
|
|
38
|
-
|
|
39
|
-
**Fixed issues:**
|
|
40
|
-
|
|
41
|
-
- Fixed warning which happened when children prop was a node.
|
|
42
|
-
|
|
43
|
-
## v0.3.0 (2017-06-26)
|
|
44
|
-
|
|
45
|
-
**Implemented enhancements:**
|
|
46
|
-
|
|
47
|
-
- Added nxgettext function which allows to translate plural strings with context.
|
|
48
|
-
- Extracted HOC into a separate component and updated it to inherit from that standalone component.
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
# react-gettext 1.0.
|
|
2
|
-
|
|
3
|
-
[](https://badge.fury.io/js/react-gettext) [](https://travis-ci.org/eugene-manuilov/react-gettext)
|
|
1
|
+
# @absolutesight/react-gettext 1.0.0
|
|
4
2
|
|
|
5
3
|
A tiny React library that helps to implement internalization in your application using gettext functions. It uses [React Context API](https://reactjs.org/docs/context.html) to expose gettext functions to children components.
|
|
6
4
|
|
|
@@ -9,7 +7,7 @@ A tiny React library that helps to implement internalization in your application
|
|
|
9
7
|
> **Note:** This library requires **React 16.3 or later**
|
|
10
8
|
|
|
11
9
|
```
|
|
12
|
-
npm i react react-gettext
|
|
10
|
+
npm i react @absolutesight/react-gettext
|
|
13
11
|
```
|
|
14
12
|
|
|
15
13
|
## Usage
|
|
@@ -45,19 +43,19 @@ The next step is to pass translations and plural form function for the current l
|
|
|
45
43
|
|
|
46
44
|
```javascript
|
|
47
45
|
import React, { Component } from 'react';
|
|
48
|
-
import { TextDomainContext, buildTextDomain } from 'react-gettext';
|
|
46
|
+
import { TextDomainContext, buildTextDomain } from '@absolutesight/react-gettext';
|
|
49
47
|
|
|
50
48
|
class MyApp extends Component {
|
|
51
49
|
|
|
52
50
|
constructor(props) {
|
|
53
51
|
super(props);
|
|
54
|
-
this.state = {
|
|
52
|
+
this.state = { textDomain: buildTextDomain(...) };
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
render() {
|
|
58
56
|
return (
|
|
59
57
|
<div>
|
|
60
|
-
<TextDomainContext.Provider value={this.state.
|
|
58
|
+
<TextDomainContext.Provider value={this.state.textDomain}>
|
|
61
59
|
<ComponentA />
|
|
62
60
|
...
|
|
63
61
|
</TextDomainContext>
|
|
@@ -74,7 +72,7 @@ Finally, the last step is to update your descendant components to consume these
|
|
|
74
72
|
|
|
75
73
|
```javascript
|
|
76
74
|
import React, { Component } from "react";
|
|
77
|
-
import { TextDomainContext } from "react-gettext";
|
|
75
|
+
import { TextDomainContext } from "@absolutesight/react-gettext";
|
|
78
76
|
|
|
79
77
|
class ComponentA extends Component {
|
|
80
78
|
render() {
|
|
@@ -121,12 +119,12 @@ export default class Header extends Component {
|
|
|
121
119
|
}
|
|
122
120
|
```
|
|
123
121
|
|
|
124
|
-
To make it translatable, you need to update your `app.js` file to use TextDomainContext provider and build
|
|
122
|
+
To make it translatable, you need to update your `app.js` file to use TextDomainContext provider and build textDomain using messages list and plural form function:
|
|
125
123
|
|
|
126
124
|
```diff
|
|
127
125
|
// app.js
|
|
128
126
|
import React, { Component } from 'react';
|
|
129
|
-
+ import { TextDomainContext, buildTextDomain } from 'react-gettext';
|
|
127
|
+
+ import { TextDomainContext, buildTextDomain } from '@absolutesight/react-gettext';
|
|
130
128
|
import Header from './Header';
|
|
131
129
|
import Footer from './Footer';
|
|
132
130
|
|
|
@@ -135,7 +133,7 @@ To make it translatable, you need to update your `app.js` file to use TextDomain
|
|
|
135
133
|
+ constructor(props) {
|
|
136
134
|
+ super(props);
|
|
137
135
|
+ this.state = {
|
|
138
|
-
+
|
|
136
|
+
+ textDomain: buildTextDomain(
|
|
139
137
|
+ {
|
|
140
138
|
+ 'Welcome to my application!': 'Bienvenido a mi aplicación!',
|
|
141
139
|
+ // ...
|
|
@@ -148,7 +146,7 @@ To make it translatable, you need to update your `app.js` file to use TextDomain
|
|
|
148
146
|
render() {
|
|
149
147
|
return (
|
|
150
148
|
<div id="app">
|
|
151
|
-
+ <TextDomainContext.Provider value={this.state.
|
|
149
|
+
+ <TextDomainContext.Provider value={this.state.textDomain}>
|
|
152
150
|
<Header />
|
|
153
151
|
...
|
|
154
152
|
<Footer />
|
|
@@ -164,7 +162,7 @@ After doing it you can start using `gettext`, `ngettext`, `xgettext` and `nxgett
|
|
|
164
162
|
```diff
|
|
165
163
|
// Header.js
|
|
166
164
|
import React, { Component } from 'react';
|
|
167
|
-
+ import { TextDomainContext } from 'react-gettext';
|
|
165
|
+
+ import { TextDomainContext } from 'absolutesight/react-gettext';
|
|
168
166
|
|
|
169
167
|
export default class Header extends Component {
|
|
170
168
|
|
|
@@ -181,8 +179,6 @@ After doing it you can start using `gettext`, `ngettext`, `xgettext` and `nxgett
|
|
|
181
179
|
+ Header.contextType = TextDomainContext;
|
|
182
180
|
```
|
|
183
181
|
|
|
184
|
-
Check a [sample](https://github.com/eugene-manuilov/react-gettext/tree/master/examples/poedit) application to see how it works.
|
|
185
|
-
|
|
186
182
|
## Documentation
|
|
187
183
|
|
|
188
184
|
### buildTextDomain(translations, pluralForm)
|
|
@@ -193,9 +189,9 @@ Builds gettext APIs for TextDomainContext provider that will work with provided
|
|
|
193
189
|
- **pluralForm**: a function that determines a plural form or a stringular reresentation of it.
|
|
194
190
|
|
|
195
191
|
```javascript
|
|
196
|
-
const api = buildTextDomain({...}, n => n == 1 ? 0 : 1);
|
|
192
|
+
const api = buildTextDomain( { ... }, n => n == 1 ? 0 : 1 );
|
|
197
193
|
// or
|
|
198
|
-
const api = buildTextDomain({...}, 'n == 1 ? 0 : 1');
|
|
194
|
+
const api = buildTextDomain( { ... }, 'n == 1 ? 0 : 1' );
|
|
199
195
|
```
|
|
200
196
|
|
|
201
197
|
### gettext(message)
|
|
@@ -269,7 +265,7 @@ The proper way to use this library is described in the [Usage](#usage) section,
|
|
|
269
265
|
|
|
270
266
|
### withGettext(translations, pluralForms, options)
|
|
271
267
|
|
|
272
|
-
Higher-order function which is exported by default from
|
|
268
|
+
Higher-order function which is exported by default from `@absolutesight/react-gettext` package. It accepts two arguments and returns function to create higher-order component.
|
|
273
269
|
|
|
274
270
|
- **translations**: a hash object or a function which returns hash object where keys are original messages and values are translated messages.
|
|
275
271
|
- **pluralForms**: a string to calculate plural form (used by [Gettext PO](http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html?id=l10n/pluralforms)) or a function which accepts a number and calculates a plural form number. Pay attentions that plural forms are zero-based what means to get 1st plural form it should return 0, to get 2nd - 1, and so on.
|
|
@@ -325,7 +321,7 @@ const HOC = withGettext()(App);
|
|
|
325
321
|
ReactDOM.render(<HOC translations={getTranslations} plural={getPluralForms}>...</HOC>, ...);
|
|
326
322
|
```
|
|
327
323
|
|
|
328
|
-
One more alternative is to not create HOC, but use TextDomain component directly. You can import it using `import {
|
|
324
|
+
One more alternative is to not create HOC, but use TextDomain component directly. You can import it using `import { Textdomain } from '@absolutesight/react-gettext'` and use it as a regular component which will provide context functions to translate your messages. Just don't forget to pass `translations` and `plural` props to this component when you render it.
|
|
329
325
|
|
|
330
326
|
## Poedit
|
|
331
327
|
|
|
@@ -362,7 +358,7 @@ If you prefer using npm scripts, then you can add the following command to your
|
|
|
362
358
|
|
|
363
359
|
## Contribute
|
|
364
360
|
|
|
365
|
-
|
|
361
|
+
I will provide this information later
|
|
366
362
|
|
|
367
363
|
## License
|
|
368
364
|
|
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,87 +22,85 @@ __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
|
|
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
30
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
class TextDomain extends react__WEBPACK_IMPORTED_MODULE_0__.Component {
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
getChildContext() {
|
|
38
|
+
const self = this;
|
|
37
39
|
|
|
38
|
-
|
|
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
|
+
}
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
nxgettext: self.nxgettext.bind(self),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
+
gettext(message) {
|
|
49
|
+
const { translations } = this.props;
|
|
50
|
+
return (0,_gettext__WEBPACK_IMPORTED_MODULE_2__.gettext)(translations, message);
|
|
51
|
+
}
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
ngettext(singular, plural, n) {
|
|
55
|
-
const { translations, plural: plurality } = this.props;
|
|
56
|
-
return (0,_gettext__WEBPACK_IMPORTED_MODULE_0__.ngettext)(translations, plurality, singular, plural, n);
|
|
57
|
-
}
|
|
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
|
+
}
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
xgettext(message, context) {
|
|
59
|
+
const { translations } = this.props;
|
|
60
|
+
return (0,_gettext__WEBPACK_IMPORTED_MODULE_2__.xgettext)(translations, message, context);
|
|
61
|
+
}
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
}
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
render() {
|
|
69
|
+
const { children } = this.props;
|
|
70
|
+
return children;
|
|
71
|
+
}
|
|
73
72
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
TextDomain.propTypes = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
]),
|
|
92
91
|
};
|
|
93
92
|
|
|
94
93
|
TextDomain.defaultProps = {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
children: [],
|
|
94
|
+
translations: {},
|
|
95
|
+
plural: 'n != 1',
|
|
96
|
+
children: [],
|
|
99
97
|
};
|
|
100
98
|
|
|
101
99
|
TextDomain.childContextTypes = {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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),
|
|
106
104
|
};
|
|
107
105
|
|
|
108
106
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomain);
|
|
@@ -126,8 +124,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
126
124
|
|
|
127
125
|
|
|
128
126
|
|
|
129
|
-
const TextDomainContext = react__WEBPACK_IMPORTED_MODULE_0___default().createContext((0,_buildTextDomain__WEBPACK_IMPORTED_MODULE_1__["default"])({
|
|
130
|
-
}, 'n != 1'));
|
|
127
|
+
const TextDomainContext = react__WEBPACK_IMPORTED_MODULE_0___default().createContext((0,_buildTextDomain__WEBPACK_IMPORTED_MODULE_1__["default"])({}, 'n != 1'));
|
|
131
128
|
|
|
132
129
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (TextDomainContext);
|
|
133
130
|
|
|
@@ -153,8 +150,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
153
150
|
* @param {any} plural TODO: No idea obout type
|
|
154
151
|
* @returns {object} JSON
|
|
155
152
|
*/
|
|
156
|
-
function buildTextDomain(translations = {
|
|
157
|
-
}, plural = "n != 1") {
|
|
153
|
+
function buildTextDomain(translations = {}, plural = "n != 1") {
|
|
158
154
|
return {
|
|
159
155
|
gettext: _gettext__WEBPACK_IMPORTED_MODULE_0__.gettext.bind(null, translations),
|
|
160
156
|
ngettext: _gettext__WEBPACK_IMPORTED_MODULE_0__.ngettext.bind(null, translations, plural),
|
|
@@ -321,46 +317,41 @@ __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
|
|
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");
|
|
327
323
|
|
|
328
324
|
|
|
329
325
|
|
|
330
326
|
|
|
331
|
-
const withGettext = (translations = {
|
|
332
|
-
|
|
333
|
-
}) => (WrappedComponent) => {
|
|
334
|
-
const args = Object.assign({
|
|
335
|
-
withRef: false
|
|
336
|
-
}, options);
|
|
327
|
+
const withGettext = (translations = {}, pluralForm = 'n != 1', options = {}) => (WrappedComponent) => {
|
|
328
|
+
const args = Object.assign({ withRef: false }, options);
|
|
337
329
|
|
|
338
|
-
|
|
330
|
+
class WithGettext extends _TextDomain__WEBPACK_IMPORTED_MODULE_2__["default"] {
|
|
339
331
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
332
|
+
getWrappedComponent() {
|
|
333
|
+
return this.refs.wrappedComponent;
|
|
334
|
+
}
|
|
343
335
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
336
|
+
render() {
|
|
337
|
+
const newprops = Object.assign({}, this.props);
|
|
338
|
+
if (args.withRef) {
|
|
339
|
+
newprops.ref = 'wrappedComponent';
|
|
340
|
+
}
|
|
350
341
|
|
|
351
|
-
|
|
352
|
-
|
|
342
|
+
return react__WEBPACK_IMPORTED_MODULE_0___default().createElement(WrappedComponent, newprops);
|
|
343
|
+
}
|
|
353
344
|
|
|
354
|
-
|
|
345
|
+
}
|
|
355
346
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
347
|
+
WithGettext.defaultProps = {
|
|
348
|
+
translations,
|
|
349
|
+
plural: pluralForm,
|
|
350
|
+
};
|
|
360
351
|
|
|
361
|
-
|
|
352
|
+
WithGettext.displayName = `withGettext(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
362
353
|
|
|
363
|
-
|
|
354
|
+
return hoist_non_react_statics__WEBPACK_IMPORTED_MODULE_1___default()(WithGettext, WrappedComponent);
|
|
364
355
|
};
|
|
365
356
|
|
|
366
357
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (withGettext);
|
|
@@ -474,15 +465,15 @@ 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
|
|
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");
|
|
486
477
|
|
|
487
478
|
|
|
488
479
|
|
|
@@ -490,7 +481,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
490
481
|
|
|
491
482
|
|
|
492
483
|
|
|
493
|
-
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (
|
|
484
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_withGettext__WEBPACK_IMPORTED_MODULE_0__["default"]);
|
|
494
485
|
|
|
495
486
|
})();
|
|
496
487
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React"),require("
|
|
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={552:t=>{t.exports=n},624:e=>{e.exports=t},42: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.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return s.d(e,{a:e}),e},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 a={};return(()=>{s.r(a),s.d(a,{TextDomain:()=>y,TextDomainContext:()=>b,buildTextDomain:()=>g,default:()=>h});var t=s(624),e=s.n(t),n=s(42),r=s.n(n),o=s(552),i=s.n(o);function p(t){return"function"==typeof t?t():t}function c(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 u(t,e){const n=p(t);return Object.prototype.hasOwnProperty.call(n,e)?n[e]:e}function l(t,e,n,r,o){const s=p(t),a=c(e,o),i=o>1?r:n;return Object.prototype.hasOwnProperty.call(s,n)&&Array.isArray(s[n])&&s[n].length>a&&a>=0?s[n][a]:i}function x(t,e,n){const r=p(t),o=n+""+e;return Object.prototype.hasOwnProperty.call(r,o)?r[o]:e}function f(t,e,n,r,o,s){const a=p(t),i=c(e,o),u=o>1?r:n,l=s+""+n;return Object.prototype.hasOwnProperty.call(a,l)&&Array.isArray(a[l])&&a[l].length>i&&i>=0?a[l][i]:u}class d 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 u(e,t)}ngettext(t,e,n){const{translations:r,plural:o}=this.props;return l(r,o,t,e,n)}xgettext(t,e){const{translations:n}=this.props;return x(n,t,e)}nxgettext(t,e,n,r){const{translations:o,plural:s}=this.props;return f(o,s,t,e,n,r)}render(){const{children:t}=this.props;return t}}d.propTypes={translations:i().oneOfType([i().func,i().objectOf(i().oneOfType([i().string,i().arrayOf(i().string)]))]),plural:i().oneOfType([i().func,i().string]),children:i().oneOfType([i().node,i().arrayOf(i().node)])},d.defaultProps={translations:{},plural:"n != 1",children:[]},d.childContextTypes={gettext:i().func,ngettext:i().func,xgettext:i().func,nxgettext:i().func};const y=d,g=function(t={},e="n != 1"){return{gettext:u.bind(null,t),ngettext:l.bind(null,t,e),xgettext:x.bind(null,t),nxgettext:f.bind(null,t,e)}},b=e().createContext(g({},"n != 1")),h=(t={},n="n != 1",o={})=>s=>{const a=Object.assign({withRef:!1},o);class i extends y{getWrappedComponent(){return this.refs.wrappedComponent}render(){const t=Object.assign({},this.props);return a.withRef&&(t.ref="wrappedComponent"),e().createElement(s,t)}}return i.defaultProps={translations:t,plural:n},i.displayName=`withGettext(${s.displayName||s.name||"Component"})`,r()(i,s)}})(),a})()));
|
package/lib/TextDomain.js
CHANGED
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _gettext = require("./gettext");
|
|
8
7
|
var _react = require("react");
|
|
9
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _gettext = require("./gettext");
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
class TextDomain extends _react.Component {
|
|
12
12
|
getChildContext() {
|
package/lib/Textdomain.js
CHANGED
|
@@ -8,7 +8,7 @@ var _react = require("react");
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _gettext = require("./gettext");
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
class
|
|
11
|
+
class TextDomain extends _react.Component {
|
|
12
12
|
getChildContext() {
|
|
13
13
|
const self = this;
|
|
14
14
|
return {
|
|
@@ -51,20 +51,20 @@ class Textdomain extends _react.Component {
|
|
|
51
51
|
return children;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
TextDomain.propTypes = {
|
|
55
55
|
translations: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]))]),
|
|
56
56
|
plural: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
|
|
57
57
|
children: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.arrayOf(_propTypes.default.node)])
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
TextDomain.defaultProps = {
|
|
60
60
|
translations: {},
|
|
61
61
|
plural: 'n != 1',
|
|
62
62
|
children: []
|
|
63
63
|
};
|
|
64
|
-
|
|
64
|
+
TextDomain.childContextTypes = {
|
|
65
65
|
gettext: _propTypes.default.func,
|
|
66
66
|
ngettext: _propTypes.default.func,
|
|
67
67
|
xgettext: _propTypes.default.func,
|
|
68
68
|
nxgettext: _propTypes.default.func
|
|
69
69
|
};
|
|
70
|
-
var _default = exports.default =
|
|
70
|
+
var _default = exports.default = TextDomain;
|
package/lib/TextdomainContext.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var
|
|
8
|
+
var _buildTextDomain = _interopRequireDefault(require("./buildTextDomain"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
const
|
|
11
|
-
var _default = exports.default =
|
|
10
|
+
const TextDomainContext = /*#__PURE__*/_react.default.createContext((0, _buildTextDomain.default)({}, 'n != 1'));
|
|
11
|
+
var _default = exports.default = TextDomainContext;
|
package/lib/buildTextdomain.js
CHANGED
|
@@ -11,7 +11,7 @@ var _gettext = require("./gettext");
|
|
|
11
11
|
* @param {any} plural TODO: No idea obout type
|
|
12
12
|
* @returns {object} JSON
|
|
13
13
|
*/
|
|
14
|
-
function
|
|
14
|
+
function buildTextDomain() {
|
|
15
15
|
let translations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
16
|
let plural = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "n != 1";
|
|
17
17
|
return {
|
|
@@ -21,4 +21,4 @@ function buildTextdomain() {
|
|
|
21
21
|
nxgettext: _gettext.nxgettext.bind(null, translations, plural)
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
var _default = exports.default =
|
|
24
|
+
var _default = exports.default = buildTextDomain;
|
package/lib/index.js
CHANGED
|
@@ -22,9 +22,9 @@ Object.defineProperty(exports, "buildTextDomain", {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
exports.default = void 0;
|
|
25
|
+
var _withGettext = _interopRequireDefault(require("./withGettext"));
|
|
25
26
|
var _TextDomain = _interopRequireDefault(require("./TextDomain"));
|
|
26
27
|
var _TextDomainContext = _interopRequireDefault(require("./TextDomainContext"));
|
|
27
28
|
var _buildTextDomain = _interopRequireDefault(require("./buildTextDomain"));
|
|
28
|
-
var _withGettext = _interopRequireDefault(require("./withGettext"));
|
|
29
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
30
|
var _default = exports.default = _withGettext.default;
|
package/lib/withGettext.js
CHANGED
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _TextDomain = _interopRequireDefault(require("./TextDomain"));
|
|
9
8
|
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
9
|
+
var _TextDomain = _interopRequireDefault(require("./TextDomain"));
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
const withGettext = function () {
|
|
12
12
|
let translations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
"bugs": {
|
|
8
8
|
"url": "https://absolutesight.com"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.0
|
|
11
|
-
"main": "
|
|
10
|
+
"version": "1.0.0",
|
|
11
|
+
"main": "src/index.js",
|
|
12
12
|
"files": [
|
|
13
13
|
"*.md",
|
|
14
14
|
"dist",
|
|
@@ -26,10 +26,13 @@
|
|
|
26
26
|
"url": "git@github.com:eugene-manuilov/react-gettext.git"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
+
"build:win": "npm run build:commonjs:win & npm run build:umd & npm run build:umd:min:win",
|
|
29
30
|
"build": "npm run build:commonjs & npm run build:umd & npm run build:umd:min",
|
|
30
31
|
"build:commonjs": "mkdir -p lib && babel ./src -d lib",
|
|
32
|
+
"build:commonjs:win": "rmdir lib /s /q && mkdir lib && babel ./src -d lib",
|
|
31
33
|
"build:umd": "webpack --output-filename=react-gettext.js",
|
|
32
34
|
"build:umd:min": "NODE_ENV=production webpack --output-filename=react-gettext.min.js",
|
|
35
|
+
"build:umd:min:win": "set NODE_ENV=production webpack --output-filename=react-gettext.min.js",
|
|
33
36
|
"test": "BABEL_ENV=test jest",
|
|
34
37
|
"prepublish": "npm run build",
|
|
35
38
|
"lint": "eslint src --fix --max-warnings=0"
|
|
@@ -46,7 +49,6 @@
|
|
|
46
49
|
"eslint": "^8.56.0",
|
|
47
50
|
"eslint-config-react-app": "^7.0.1",
|
|
48
51
|
"eslint-plugin-import": "^2.29.1",
|
|
49
|
-
"eslint-plugin-jsdoc": "^48.0.4",
|
|
50
52
|
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
51
53
|
"eslint-plugin-react": "^7.33.2",
|
|
52
54
|
"eslint-webpack-plugin": "^4.0.1",
|
|
@@ -62,7 +64,7 @@
|
|
|
62
64
|
"webpack-cli": "^5.1.4"
|
|
63
65
|
},
|
|
64
66
|
"dependencies": {
|
|
65
|
-
"hoist-non-react-statics": "^
|
|
67
|
+
"hoist-non-react-statics": "^3.3.2"
|
|
66
68
|
},
|
|
67
69
|
"peerDependencies": {
|
|
68
70
|
"hoist-non-react-statics": "^1.2.0 || ^2.0.0-0 || ^3.0.0-0",
|
package/src/TextDomain.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import {gettext,
|
|
2
|
-
ngettext,
|
|
3
|
-
nxgettext,
|
|
4
|
-
xgettext,} from './gettext';
|
|
5
1
|
import { Component } from 'react';
|
|
6
2
|
import PropTypes from 'prop-types';
|
|
7
3
|
|
|
8
|
-
|
|
4
|
+
import {
|
|
5
|
+
gettext,
|
|
6
|
+
ngettext,
|
|
7
|
+
xgettext,
|
|
8
|
+
nxgettext,
|
|
9
|
+
} from './gettext';
|
|
9
10
|
|
|
10
11
|
class TextDomain extends Component {
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
getChildContext() {
|
|
14
|
+
const self = this;
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
return {
|
|
17
|
+
gettext: self.gettext.bind(self),
|
|
18
|
+
xgettext: self.xgettext.bind(self),
|
|
19
|
+
ngettext: self.ngettext.bind(self),
|
|
20
|
+
nxgettext: self.nxgettext.bind(self),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
gettext(message) {
|
|
25
|
+
const { translations } = this.props;
|
|
26
|
+
return gettext(translations, message);
|
|
27
|
+
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
ngettext(singular, plural, n) {
|
|
30
|
+
const { translations, plural: plurality } = this.props;
|
|
31
|
+
return ngettext(translations, plurality, singular, plural, n);
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
xgettext(message, context) {
|
|
35
|
+
const { translations } = this.props;
|
|
36
|
+
return xgettext(translations, message, context);
|
|
37
|
+
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
nxgettext(singular, plural, n, context) {
|
|
40
|
+
const { translations, plural: plurality } = this.props;
|
|
41
|
+
return nxgettext(translations, plurality, singular, plural, n, context);
|
|
42
|
+
}
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
render() {
|
|
45
|
+
const { children } = this.props;
|
|
46
|
+
return children;
|
|
47
|
+
}
|
|
47
48
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
TextDomain.propTypes = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
translations: PropTypes.oneOfType([
|
|
53
|
+
PropTypes.func,
|
|
54
|
+
PropTypes.objectOf(PropTypes.oneOfType([
|
|
55
|
+
PropTypes.string,
|
|
56
|
+
PropTypes.arrayOf(PropTypes.string),
|
|
57
|
+
])),
|
|
58
|
+
]),
|
|
59
|
+
plural: PropTypes.oneOfType([
|
|
60
|
+
PropTypes.func,
|
|
61
|
+
PropTypes.string,
|
|
62
|
+
]),
|
|
63
|
+
children: PropTypes.oneOfType([
|
|
64
|
+
PropTypes.node,
|
|
65
|
+
PropTypes.arrayOf(PropTypes.node),
|
|
66
|
+
]),
|
|
66
67
|
};
|
|
67
68
|
|
|
68
69
|
TextDomain.defaultProps = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
children: [],
|
|
70
|
+
translations: {},
|
|
71
|
+
plural: 'n != 1',
|
|
72
|
+
children: [],
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
TextDomain.childContextTypes = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
gettext: PropTypes.func,
|
|
77
|
+
ngettext: PropTypes.func,
|
|
78
|
+
xgettext: PropTypes.func,
|
|
79
|
+
nxgettext: PropTypes.func,
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
export default TextDomain;
|
package/src/TextDomainContext.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import buildTextDomain from './buildTextDomain';
|
|
3
3
|
|
|
4
|
-
const TextDomainContext = React.createContext(buildTextDomain({
|
|
5
|
-
}, 'n != 1'));
|
|
4
|
+
const TextDomainContext = React.createContext(buildTextDomain({}, 'n != 1'));
|
|
6
5
|
|
|
7
6
|
export default TextDomainContext;
|
package/src/buildTextDomain.js
CHANGED
|
@@ -6,8 +6,7 @@ import { gettext, ngettext, nxgettext, xgettext } from "./gettext";
|
|
|
6
6
|
* @param {any} plural TODO: No idea obout type
|
|
7
7
|
* @returns {object} JSON
|
|
8
8
|
*/
|
|
9
|
-
function buildTextDomain(translations = {
|
|
10
|
-
}, plural = "n != 1") {
|
|
9
|
+
function buildTextDomain(translations = {}, plural = "n != 1") {
|
|
11
10
|
return {
|
|
12
11
|
gettext: gettext.bind(null, translations),
|
|
13
12
|
ngettext: ngettext.bind(null, translations, plural),
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import withGettext from './withGettext';
|
|
1
2
|
import TextDomain from './TextDomain';
|
|
2
3
|
import TextDomainContext from './TextDomainContext';
|
|
3
4
|
import buildTextDomain from './buildTextDomain';
|
|
4
|
-
import withGettext from './withGettext';
|
|
5
5
|
|
|
6
6
|
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
TextDomain,
|
|
8
|
+
TextDomainContext,
|
|
9
|
+
buildTextDomain,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export default withGettext;
|
package/src/withGettext.js
CHANGED
|
@@ -1,40 +1,35 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import TextDomain from './TextDomain';
|
|
3
2
|
import hoistNonReactStatic from 'hoist-non-react-statics';
|
|
3
|
+
import TextDomain from './TextDomain';
|
|
4
4
|
|
|
5
|
-
const withGettext = (translations = {
|
|
6
|
-
|
|
7
|
-
}) => (WrappedComponent) => {
|
|
8
|
-
const args = Object.assign({
|
|
9
|
-
withRef: false
|
|
10
|
-
}, options);
|
|
5
|
+
const withGettext = (translations = {}, pluralForm = 'n != 1', options = {}) => (WrappedComponent) => {
|
|
6
|
+
const args = Object.assign({ withRef: false }, options);
|
|
11
7
|
|
|
12
|
-
|
|
8
|
+
class WithGettext extends TextDomain {
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
getWrappedComponent() {
|
|
11
|
+
return this.refs.wrappedComponent;
|
|
12
|
+
}
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
14
|
+
render() {
|
|
15
|
+
const newprops = Object.assign({}, this.props);
|
|
16
|
+
if (args.withRef) {
|
|
17
|
+
newprops.ref = 'wrappedComponent';
|
|
18
|
+
}
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
return React.createElement(WrappedComponent, newprops);
|
|
21
|
+
}
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
}
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
WithGettext.defaultProps = {
|
|
26
|
+
translations,
|
|
27
|
+
plural: pluralForm,
|
|
28
|
+
};
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
WithGettext.displayName = `withGettext(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
return hoistNonReactStatic(WithGettext, WrappedComponent);
|
|
38
33
|
};
|
|
39
34
|
|
|
40
35
|
export default withGettext;
|