@absolutesight/react-gettext 1.0.1 → 1.0.2

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.
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _buildTextDomain = _interopRequireDefault(require("./buildTextDomain"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const TextDomainContext = /*#__PURE__*/_react.default.createContext((0, _buildTextDomain.default)({}, 'n != 1'));
11
+ var _default = exports.default = TextDomainContext;
@@ -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] : {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
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
13
+ */
14
+ function buildTextDomain() {
15
+ let translations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16
+ let plural = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "n != 1";
17
+ return {
18
+ gettext: _gettext.gettext.bind(null, translations),
19
+ ngettext: _gettext.ngettext.bind(null, translations, plural),
20
+ xgettext: _gettext.xgettext.bind(null, translations),
21
+ nxgettext: _gettext.nxgettext.bind(null, translations, plural)
22
+ };
23
+ }
24
+ var _default = exports.default = buildTextDomain;
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/package.json CHANGED
@@ -1,83 +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": "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
- }
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.2",
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/absolutesight/gettext"
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 { 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;
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;
@@ -1,6 +1,6 @@
1
- import React from 'react';
2
- import buildTextDomain from './buildTextDomain';
3
-
4
- const TextDomainContext = React.createContext(buildTextDomain({}, 'n != 1'));
5
-
6
- 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;
@@ -1,18 +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 = {}, 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;
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;