@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
|
@@ -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/buildTextDomain.js
CHANGED
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _gettext = require("./gettext");
|
|
8
|
-
/**
|
|
9
|
-
* TODO: We need to add description here
|
|
10
|
-
* @param {object} translations JSON
|
|
11
|
-
* @param {any} plural TODO: No idea obout type
|
|
12
|
-
* @returns {object} JSON
|
|
8
|
+
/**
|
|
9
|
+
* TODO: We need to add description here
|
|
10
|
+
* @param {object} translations JSON
|
|
11
|
+
* @param {any} plural TODO: No idea obout type
|
|
12
|
+
* @returns {object} JSON
|
|
13
13
|
*/
|
|
14
14
|
function buildTextDomain() {
|
|
15
15
|
let translations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
package/lib/gettext.js
CHANGED
|
@@ -10,20 +10,20 @@ exports.nxgettext = nxgettext;
|
|
|
10
10
|
exports.xgettext = xgettext;
|
|
11
11
|
const DELIMITER = "\u0004"; // End of Transmission (EOT)
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* TODO: We need to add description here
|
|
15
|
-
* @param {any} catalog string or function
|
|
16
|
-
* @returns {string} string or string from a function
|
|
13
|
+
/**
|
|
14
|
+
* TODO: We need to add description here
|
|
15
|
+
* @param {any} catalog string or function
|
|
16
|
+
* @returns {string} string or string from a function
|
|
17
17
|
*/
|
|
18
18
|
function getTranslations(catalog) {
|
|
19
19
|
return typeof catalog === "function" ? catalog() : catalog;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* TODO: We need to add description here
|
|
24
|
-
* @param {any} plural string or function
|
|
25
|
-
* @param {any} n TODO: No idea what will pass in it
|
|
26
|
-
* @returns {any} 0 if nothing
|
|
22
|
+
/**
|
|
23
|
+
* TODO: We need to add description here
|
|
24
|
+
* @param {any} plural string or function
|
|
25
|
+
* @param {any} n TODO: No idea what will pass in it
|
|
26
|
+
* @returns {any} 0 if nothing
|
|
27
27
|
*/
|
|
28
28
|
function getPluralForm(plural, n) {
|
|
29
29
|
// return 0 if n is not integer
|
|
@@ -47,25 +47,25 @@ function getPluralForm(plural, n) {
|
|
|
47
47
|
return 0;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
51
|
-
* TODO: We need to add description here
|
|
52
|
-
* @param {string} catalog Catalog
|
|
53
|
-
* @param {string} message Message
|
|
54
|
-
* @returns {string} Message
|
|
50
|
+
/**
|
|
51
|
+
* TODO: We need to add description here
|
|
52
|
+
* @param {string} catalog Catalog
|
|
53
|
+
* @param {string} message Message
|
|
54
|
+
* @returns {string} Message
|
|
55
55
|
*/
|
|
56
56
|
function gettext(catalog, message) {
|
|
57
57
|
const messages = getTranslations(catalog);
|
|
58
58
|
return Object.prototype.hasOwnProperty.call(messages, message) ? messages[message] : message;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
* TODO: WE need to add description here
|
|
63
|
-
* @param {string} catalog Catalog
|
|
64
|
-
* @param {string} plurality Plurality
|
|
65
|
-
* @param {string} singular Singular
|
|
66
|
-
* @param {string} plural Plural
|
|
67
|
-
* @param {number} n n
|
|
68
|
-
* @returns {string} Message
|
|
61
|
+
/**
|
|
62
|
+
* TODO: WE need to add description here
|
|
63
|
+
* @param {string} catalog Catalog
|
|
64
|
+
* @param {string} plurality Plurality
|
|
65
|
+
* @param {string} singular Singular
|
|
66
|
+
* @param {string} plural Plural
|
|
67
|
+
* @param {number} n n
|
|
68
|
+
* @returns {string} Message
|
|
69
69
|
*/
|
|
70
70
|
function ngettext(catalog, plurality, singular, plural, n) {
|
|
71
71
|
const messages = getTranslations(catalog);
|
|
@@ -74,12 +74,12 @@ function ngettext(catalog, plurality, singular, plural, n) {
|
|
|
74
74
|
return Object.prototype.hasOwnProperty.call(messages, singular) && Array.isArray(messages[singular]) && messages[singular].length > pluralIndex && pluralIndex >= 0 ? messages[singular][pluralIndex] : defaultValue;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/**
|
|
78
|
-
* TODO: We need to add description here
|
|
79
|
-
* @param {string} catalog Catalog
|
|
80
|
-
* @param {string} message Message
|
|
81
|
-
* @param {string} context Context
|
|
82
|
-
* @returns {string} Message
|
|
77
|
+
/**
|
|
78
|
+
* TODO: We need to add description here
|
|
79
|
+
* @param {string} catalog Catalog
|
|
80
|
+
* @param {string} message Message
|
|
81
|
+
* @param {string} context Context
|
|
82
|
+
* @returns {string} Message
|
|
83
83
|
*/
|
|
84
84
|
function xgettext(catalog, message, context) {
|
|
85
85
|
const messages = getTranslations(catalog);
|
|
@@ -87,15 +87,15 @@ function xgettext(catalog, message, context) {
|
|
|
87
87
|
return Object.prototype.hasOwnProperty.call(messages, key) ? messages[key] : message;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
/**
|
|
91
|
-
* TODO: We need to add description here
|
|
92
|
-
* @param {string} catalog Catalog
|
|
93
|
-
* @param {string} plurality Plurality
|
|
94
|
-
* @param {string} singular Singular
|
|
95
|
-
* @param {string} plural Plural
|
|
96
|
-
* @param {number} n n
|
|
97
|
-
* @param {string} context Context
|
|
98
|
-
* @returns {string} Message
|
|
90
|
+
/**
|
|
91
|
+
* TODO: We need to add description here
|
|
92
|
+
* @param {string} catalog Catalog
|
|
93
|
+
* @param {string} plurality Plurality
|
|
94
|
+
* @param {string} singular Singular
|
|
95
|
+
* @param {string} plural Plural
|
|
96
|
+
* @param {number} n n
|
|
97
|
+
* @param {string} context Context
|
|
98
|
+
* @returns {string} Message
|
|
99
99
|
*/
|
|
100
100
|
function nxgettext(catalog, plurality, singular, plural, n, context) {
|
|
101
101
|
const messages = getTranslations(catalog);
|
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
|
@@ -1,81 +1,83 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@absolutesight/react-gettext",
|
|
3
|
-
"description": "Gettext implementation for React based project.",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"author": "Qadeer Ahmad <qadeer@gmail.com>",
|
|
6
|
-
"homepage": "https://absolutesight.com",
|
|
7
|
-
"bugs": {
|
|
8
|
-
"url": "https://absolutesight.com"
|
|
9
|
-
},
|
|
10
|
-
"version": "
|
|
11
|
-
"main": "
|
|
12
|
-
"files": [
|
|
13
|
-
"*.md",
|
|
14
|
-
"dist",
|
|
15
|
-
"LICENSE",
|
|
16
|
-
"lib",
|
|
17
|
-
"src"
|
|
18
|
-
],
|
|
19
|
-
"keywords": [
|
|
20
|
-
"react",
|
|
21
|
-
"gettext",
|
|
22
|
-
"gettextjs"
|
|
23
|
-
],
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git@github.com
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "npm run build:commonjs & npm run build:umd & npm run build:umd:min",
|
|
30
|
-
"build
|
|
31
|
-
"build:
|
|
32
|
-
"build:
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"@babel/
|
|
42
|
-
"@babel/
|
|
43
|
-
"babel-
|
|
44
|
-
"babel-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"eslint
|
|
50
|
-
"eslint-
|
|
51
|
-
"eslint-plugin-
|
|
52
|
-
"eslint-
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"react
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"react": "^
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@absolutesight/react-gettext",
|
|
3
|
+
"description": "Gettext implementation for React based project.",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Qadeer Ahmad <qadeer@gmail.com>",
|
|
6
|
+
"homepage": "https://absolutesight.com",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://absolutesight.com"
|
|
9
|
+
},
|
|
10
|
+
"version": "1.0.1",
|
|
11
|
+
"main": "src/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"*.md",
|
|
14
|
+
"dist",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"lib",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"react",
|
|
21
|
+
"gettext",
|
|
22
|
+
"gettextjs"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+ssh://git@github.com/eugene-manuilov/react-gettext.git"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build:win": "npm run build:commonjs:win & npm run build:umd & npm run build:umd:min:win",
|
|
30
|
+
"build": "npm run build:commonjs & npm run build:umd & npm run build:umd:min",
|
|
31
|
+
"build:commonjs": "mkdir -p lib && babel ./src -d lib",
|
|
32
|
+
"build:commonjs:win": "rmdir lib /s /q && mkdir lib && babel ./src -d lib",
|
|
33
|
+
"build:umd": "webpack --output-filename=react-gettext.js",
|
|
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",
|
|
36
|
+
"test": "BABEL_ENV=test jest",
|
|
37
|
+
"prepublish": "npm run build",
|
|
38
|
+
"lint": "eslint src --fix --max-warnings=0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/cli": "^7.23.9",
|
|
42
|
+
"@babel/core": "^7.23.9",
|
|
43
|
+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
|
44
|
+
"@babel/preset-env": "^7.23.9",
|
|
45
|
+
"@babel/preset-react": "^7.23.3",
|
|
46
|
+
"babel-jest": "^29.7.0",
|
|
47
|
+
"babel-loader": "^9.1.3",
|
|
48
|
+
"enzyme": "^3.11.0",
|
|
49
|
+
"eslint": "^8.57.0",
|
|
50
|
+
"eslint-config-react-app": "^7.0.1",
|
|
51
|
+
"eslint-plugin-import": "^2.29.1",
|
|
52
|
+
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
53
|
+
"eslint-plugin-react": "^7.33.2",
|
|
54
|
+
"eslint-webpack-plugin": "^4.0.1",
|
|
55
|
+
"faker": "^6.6.6",
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"jest-enzyme": "^7.1.2",
|
|
58
|
+
"lodash": "^4.17.21",
|
|
59
|
+
"prop-types": "^15.8.1",
|
|
60
|
+
"react": "^18.2.0",
|
|
61
|
+
"react-dom": "^18.2.0",
|
|
62
|
+
"react-test-renderer": "^18.2.0",
|
|
63
|
+
"webpack": "^5.90.3",
|
|
64
|
+
"webpack-cli": "^5.1.4"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"hoist-non-react-statics": "^1.2.0 || ^2.0.0-0 || ^3.0.0-0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"hoist-non-react-statics": "^1.2.0 || ^2.0.0-0 || ^3.0.0-0",
|
|
71
|
+
"prop-types": "^15.0.0-0 || ^16.0.0-0",
|
|
72
|
+
"react": "^15.0.0-0 || ^16.0.0-0 || ^17.0.0-0 || ^18.0.0-0"
|
|
73
|
+
},
|
|
74
|
+
"jest": {
|
|
75
|
+
"setupFilesAfterEnv": [
|
|
76
|
+
"<rootDir>/__tests__/__setup.js"
|
|
77
|
+
],
|
|
78
|
+
"testMatch": [
|
|
79
|
+
"<rootDir>/__tests__/**/[^_]*.js"
|
|
80
|
+
],
|
|
81
|
+
"verbose": true
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/TextDomain.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
TextDomain.childContextTypes = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export default TextDomain;
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
gettext,
|
|
6
|
+
ngettext,
|
|
7
|
+
xgettext,
|
|
8
|
+
nxgettext,
|
|
9
|
+
} from './gettext';
|
|
10
|
+
|
|
11
|
+
class TextDomain extends Component {
|
|
12
|
+
|
|
13
|
+
getChildContext() {
|
|
14
|
+
const self = this;
|
|
15
|
+
|
|
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
|
+
}
|
|
23
|
+
|
|
24
|
+
gettext(message) {
|
|
25
|
+
const { translations } = this.props;
|
|
26
|
+
return gettext(translations, message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
ngettext(singular, plural, n) {
|
|
30
|
+
const { translations, plural: plurality } = this.props;
|
|
31
|
+
return ngettext(translations, plurality, singular, plural, n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
xgettext(message, context) {
|
|
35
|
+
const { translations } = this.props;
|
|
36
|
+
return xgettext(translations, message, context);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
nxgettext(singular, plural, n, context) {
|
|
40
|
+
const { translations, plural: plurality } = this.props;
|
|
41
|
+
return nxgettext(translations, plurality, singular, plural, n, context);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
render() {
|
|
45
|
+
const { children } = this.props;
|
|
46
|
+
return children;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
TextDomain.propTypes = {
|
|
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
|
+
]),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
TextDomain.defaultProps = {
|
|
70
|
+
translations: {},
|
|
71
|
+
plural: 'n != 1',
|
|
72
|
+
children: [],
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
TextDomain.childContextTypes = {
|
|
76
|
+
gettext: PropTypes.func,
|
|
77
|
+
ngettext: PropTypes.func,
|
|
78
|
+
xgettext: PropTypes.func,
|
|
79
|
+
nxgettext: PropTypes.func,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default TextDomain;
|
package/src/TextDomainContext.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import buildTextDomain from './buildTextDomain';
|
|
3
|
-
|
|
4
|
-
const TextDomainContext = React.createContext(buildTextDomain({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default TextDomainContext;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import buildTextDomain from './buildTextDomain';
|
|
3
|
+
|
|
4
|
+
const TextDomainContext = React.createContext(buildTextDomain({}, 'n != 1'));
|
|
5
|
+
|
|
6
|
+
export default TextDomainContext;
|
package/src/buildTextDomain.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { gettext, ngettext, nxgettext, xgettext } from "./gettext";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* TODO: We need to add description here
|
|
5
|
-
* @param {object} translations JSON
|
|
6
|
-
* @param {any} plural TODO: No idea obout type
|
|
7
|
-
* @returns {object} JSON
|
|
8
|
-
*/
|
|
9
|
-
function buildTextDomain(translations = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export default buildTextDomain;
|
|
1
|
+
import { gettext, ngettext, nxgettext, xgettext } from "./gettext";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TODO: We need to add description here
|
|
5
|
+
* @param {object} translations JSON
|
|
6
|
+
* @param {any} plural TODO: No idea obout type
|
|
7
|
+
* @returns {object} JSON
|
|
8
|
+
*/
|
|
9
|
+
function buildTextDomain(translations = {}, plural = "n != 1") {
|
|
10
|
+
return {
|
|
11
|
+
gettext: gettext.bind(null, translations),
|
|
12
|
+
ngettext: ngettext.bind(null, translations, plural),
|
|
13
|
+
xgettext: xgettext.bind(null, translations),
|
|
14
|
+
nxgettext: nxgettext.bind(null, translations, plural)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default buildTextDomain;
|