@zohodesk/i18n 1.0.0-beta.32 → 1.0.0-beta.34
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/README.md +8 -0
- package/es/components/DateTimeDiffFormat.js +2 -2
- package/es/components/FormatText.js +3 -2
- package/es/components/HOCI18N.js +5 -5
- package/es/components/I18N.js +2 -2
- package/es/components/I18NProvider.js +3 -3
- package/es/components/PluralFormat.js +3 -5
- package/es/components/UserTimeDiffFormat.js +2 -2
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +2 -2
- package/es/components/__tests__/FormatText.spec.js +2 -2
- package/es/components/__tests__/HOCI18N.spec.js +2 -2
- package/es/components/__tests__/I18N.spec.js +6 -7
- package/es/components/__tests__/I18NProvider.spec.js +2 -2
- package/es/components/__tests__/PluralFormat.spec.js +3 -3
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +2 -2
- package/es/index.js +11 -10
- package/es/utils/__tests__/jsxTranslations.spec.js +1 -1
- package/es/utils/index.js +1 -1
- package/es/utils/jsxTranslations.js +23 -13
- package/lib/index.js +8 -0
- package/lib/utils/jsxTranslations.js +23 -10
- package/package.json +2 -2
- package/src/index.js +1 -0
- package/src/utils/jsxTranslations.js +23 -11
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { pad, getValues, getDiffObj, formatDate, getLyears, getDatePatternWithoutYear } from
|
|
4
|
-
import FormatText from
|
|
3
|
+
import { pad, getValues, getDiffObj, formatDate, getLyears, getDatePatternWithoutYear } from "../utils";
|
|
4
|
+
import FormatText from "./FormatText";
|
|
5
5
|
import datetime from '@zohodesk/datetimejs';
|
|
6
6
|
export default class DateTimeDiffFormat extends React.Component {
|
|
7
7
|
constructor(props) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import I18N from
|
|
3
|
+
import I18N from "./I18N";
|
|
4
4
|
export default class FormatText extends React.Component {
|
|
5
5
|
render() {
|
|
6
|
-
return /*#__PURE__*/React.createElement(I18N, this.props
|
|
6
|
+
return /*#__PURE__*/React.createElement(I18N, { ...this.props
|
|
7
|
+
});
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
}
|
package/es/components/HOCI18N.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
1
|
import React, { Children } from 'react';
|
|
4
2
|
import PropTypes from 'prop-types';
|
|
5
|
-
import { replaceI18NValuesWithRegex, unescapeUnicode } from
|
|
6
|
-
import { I18NContext } from
|
|
3
|
+
import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
|
|
4
|
+
import { I18NContext } from "../I18NContext";
|
|
7
5
|
export default (function () {
|
|
8
6
|
let i18NKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
9
7
|
return Component => {
|
|
@@ -39,7 +37,9 @@ export default (function () {
|
|
|
39
37
|
|
|
40
38
|
return result;
|
|
41
39
|
}, {});
|
|
42
|
-
return /*#__PURE__*/React.createElement(Component,
|
|
40
|
+
return /*#__PURE__*/React.createElement(Component, { ...this.props,
|
|
41
|
+
...i18nProps
|
|
42
|
+
});
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
}
|
package/es/components/I18N.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { Children } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { replaceI18NValuesWithRegex, unescapeUnicode } from
|
|
3
|
+
import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
|
|
4
4
|
import { HTMLPurifier } from '@zoho/SecurityJS';
|
|
5
|
-
import { I18NContext } from
|
|
5
|
+
import { I18NContext } from "../I18NContext";
|
|
6
6
|
export default class I18N extends React.Component {
|
|
7
7
|
constructor(props) {
|
|
8
8
|
super(props);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { getI18NValue, userDateFormat } from
|
|
4
|
-
import { getI18NComponent } from
|
|
5
|
-
import { I18NContext } from
|
|
3
|
+
import { getI18NValue, userDateFormat } from "../utils";
|
|
4
|
+
import { getI18NComponent } from "../utils/jsxTranslations";
|
|
5
|
+
import { I18NContext } from "../I18NContext";
|
|
6
6
|
const emptyObj = {};
|
|
7
7
|
|
|
8
8
|
const dummy = (key, values) => key;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
1
|
import React from 'react';
|
|
4
2
|
import PropTypes from 'prop-types';
|
|
5
|
-
import FormatText from
|
|
3
|
+
import FormatText from "./FormatText";
|
|
6
4
|
export default class PluralFormat extends React.Component {
|
|
7
5
|
render() {
|
|
8
6
|
const {
|
|
@@ -23,13 +21,13 @@ export default class PluralFormat extends React.Component {
|
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
values = `${value}`;
|
|
26
|
-
return /*#__PURE__*/React.createElement(FormatText,
|
|
24
|
+
return /*#__PURE__*/React.createElement(FormatText, { ...this.props,
|
|
27
25
|
i18NKey: key,
|
|
28
26
|
values: values,
|
|
29
27
|
one: null,
|
|
30
28
|
many: null,
|
|
31
29
|
zero: null
|
|
32
|
-
})
|
|
30
|
+
});
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { Component } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import DateTimeDiffFormat from
|
|
4
|
-
import { I18NContext } from
|
|
3
|
+
import DateTimeDiffFormat from "./DateTimeDiffFormat";
|
|
4
|
+
import { I18NContext } from "../I18NContext";
|
|
5
5
|
export default class UserTimeDiffFormat extends Component {
|
|
6
6
|
render() {
|
|
7
7
|
let currentTime = new Date();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import DateTimeDiffFormat from
|
|
2
|
-
import I18NProvider from
|
|
1
|
+
import DateTimeDiffFormat from "../DateTimeDiffFormat";
|
|
2
|
+
import I18NProvider from "../I18NProvider";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import renderer from 'react-test-renderer';
|
|
5
5
|
let tzData = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import FormatText from
|
|
2
|
-
import I18NProvider from
|
|
1
|
+
import FormatText from "../FormatText";
|
|
2
|
+
import I18NProvider from "../I18NProvider";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import renderer from 'react-test-renderer';
|
|
5
5
|
describe('FormatText component', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import HOCI18N from
|
|
2
|
-
import I18NProvider from
|
|
1
|
+
import HOCI18N from "..//HOCI18N";
|
|
2
|
+
import I18NProvider from "../I18NProvider";
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import renderer from 'react-test-renderer';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import I18N from '../I18N';
|
|
4
|
-
import I18NProvider from '../I18NProvider';
|
|
1
|
+
import I18N from "../I18N";
|
|
2
|
+
import I18NProvider from "../I18NProvider";
|
|
5
3
|
import React from 'react';
|
|
6
4
|
import renderer from 'react-test-renderer';
|
|
7
5
|
const defaultProps = {
|
|
@@ -13,9 +11,9 @@ describe('I18N component', () => {
|
|
|
13
11
|
i18n: {
|
|
14
12
|
key1: 'vimal1<b>vimal</b>'
|
|
15
13
|
}
|
|
16
|
-
}, /*#__PURE__*/React.createElement(I18N,
|
|
14
|
+
}, /*#__PURE__*/React.createElement(I18N, { ...defaultProps,
|
|
17
15
|
isHtml: true
|
|
18
|
-
})))
|
|
16
|
+
})));
|
|
19
17
|
let tree = ele.toJSON();
|
|
20
18
|
expect(tree).toMatchSnapshot();
|
|
21
19
|
});
|
|
@@ -24,7 +22,8 @@ describe('I18N component', () => {
|
|
|
24
22
|
i18n: {
|
|
25
23
|
key1: 'vimal1<b>vimal</b>'
|
|
26
24
|
}
|
|
27
|
-
}, /*#__PURE__*/React.createElement(I18N, defaultProps
|
|
25
|
+
}, /*#__PURE__*/React.createElement(I18N, { ...defaultProps
|
|
26
|
+
})));
|
|
28
27
|
let tree = ele.toJSON();
|
|
29
28
|
expect(tree).toMatchSnapshot();
|
|
30
29
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import I18NProvider, { i18NProviderUtils } from
|
|
2
|
-
import I18N from
|
|
1
|
+
import I18NProvider, { i18NProviderUtils } from "../I18NProvider";
|
|
2
|
+
import I18N from "../I18N";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import renderer from 'react-test-renderer';
|
|
5
5
|
import { Provider } from 'react-redux';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import PluralFormat from
|
|
2
|
-
import I18NProvider from
|
|
3
|
-
import FormatText from
|
|
1
|
+
import PluralFormat from "../PluralFormat";
|
|
2
|
+
import I18NProvider from "../I18NProvider";
|
|
3
|
+
import FormatText from "../FormatText";
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import renderer from 'react-test-renderer';
|
|
6
6
|
describe('PluralFormat component', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import UserTimeDiffFormat from
|
|
2
|
-
import I18NProvider, { i18NProviderUtils } from
|
|
1
|
+
import UserTimeDiffFormat from "../UserTimeDiffFormat";
|
|
2
|
+
import I18NProvider, { i18NProviderUtils } from "../I18NProvider";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import renderer from 'react-test-renderer';
|
|
5
5
|
let temp = Date;
|
package/es/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix, getDatePatternWithoutYear, setLocalizedData, setI18NKeyMapping, dayi18n, monthi18n, timei18n } from
|
|
2
|
-
import { getI18NValue as getI18NValue1 } from
|
|
3
|
-
export { I18NContext } from
|
|
4
|
-
export { default as I18NProvider, i18NProviderUtils } from
|
|
5
|
-
export { default as I18N } from
|
|
6
|
-
export { default as HOCI18N } from
|
|
7
|
-
export { default as FormatText } from
|
|
8
|
-
export { default as PluralFormat } from
|
|
9
|
-
export { default as DateTimeDiffFormat } from
|
|
10
|
-
export { default as UserTimeDiffFormat } from
|
|
1
|
+
export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix, getDatePatternWithoutYear, setLocalizedData, setI18NKeyMapping, dayi18n, monthi18n, timei18n } from "./utils";
|
|
2
|
+
import { getI18NValue as getI18NValue1 } from "./utils";
|
|
3
|
+
export { I18NContext } from "./I18NContext";
|
|
4
|
+
export { default as I18NProvider, i18NProviderUtils } from "./components/I18NProvider";
|
|
5
|
+
export { default as I18N } from "./components/I18N";
|
|
6
|
+
export { default as HOCI18N } from "./components/HOCI18N";
|
|
7
|
+
export { default as FormatText } from "./components/FormatText";
|
|
8
|
+
export { default as PluralFormat } from "./components/PluralFormat";
|
|
9
|
+
export { default as DateTimeDiffFormat } from "./components/DateTimeDiffFormat";
|
|
10
|
+
export { default as UserTimeDiffFormat } from "./components/UserTimeDiffFormat";
|
|
11
|
+
export { placeComponentForTags } from "./utils/jsxTranslations";
|
|
11
12
|
export const getI18NValue = (i18n, key, values) => getI18NValue1(i18n)(key, values);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { splitMatchedExp, generateChildren, replaceWithComponentPlaceHolder, createElement, prepareI18NFunc, getI18NComponent } from
|
|
2
|
+
import { splitMatchedExp, generateChildren, replaceWithComponentPlaceHolder, createElement, prepareI18NFunc, getI18NComponent } from "../jsxTranslations";
|
|
3
3
|
|
|
4
4
|
function Bold(_ref) {
|
|
5
5
|
let {
|
package/es/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import datetime from '@zohodesk/datetimejs';
|
|
2
|
-
import { i18NProviderUtils } from
|
|
2
|
+
import { i18NProviderUtils } from "../components/I18NProvider";
|
|
3
3
|
export const dayi18n = {
|
|
4
4
|
'Sun': 'deskreact.calendar.daynameshort.sunday',
|
|
5
5
|
'Mon': 'deskreact.calendar.daynameshort.monday',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { unescapeUnicode } from
|
|
2
|
+
import { unescapeUnicode } from "./index";
|
|
3
|
+
import { i18NProviderUtils } from "../components/I18NProvider";
|
|
3
4
|
export function splitMatchedExp(_ref) {
|
|
4
5
|
let {
|
|
5
6
|
expression,
|
|
@@ -165,6 +166,26 @@ export function prepareI18NFunc() {
|
|
|
165
166
|
stringPlaceHolders
|
|
166
167
|
});
|
|
167
168
|
}
|
|
169
|
+
|
|
170
|
+
function i18nMechanismForComponents(i18nValue, key) {
|
|
171
|
+
if (typeof i18nValue === 'string') {
|
|
172
|
+
i18nValue = unescapeUnicode(i18nValue);
|
|
173
|
+
const value = prepareI18NFunc({
|
|
174
|
+
i18nKey: i18nValue
|
|
175
|
+
});
|
|
176
|
+
window.loadI18nChunk && window.loadI18nChunk({
|
|
177
|
+
[key]: value
|
|
178
|
+
});
|
|
179
|
+
i18nValue = value;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return i18nValue;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function placeComponentForTags(i18nValue) {
|
|
186
|
+
const value = i18NProviderUtils.getI18NComponent(i18nValue);
|
|
187
|
+
return i18nMechanismForComponents(value, value);
|
|
188
|
+
}
|
|
168
189
|
export function getI18NComponent(i18n) {
|
|
169
190
|
if (typeof i18n === 'undefined') {
|
|
170
191
|
return key => key;
|
|
@@ -177,17 +198,6 @@ export function getI18NComponent(i18n) {
|
|
|
177
198
|
return key;
|
|
178
199
|
}
|
|
179
200
|
|
|
180
|
-
|
|
181
|
-
i18nStr = unescapeUnicode(i18nStr);
|
|
182
|
-
const value = prepareI18NFunc({
|
|
183
|
-
i18nKey: i18nStr
|
|
184
|
-
});
|
|
185
|
-
window.loadI18nChunk && window.loadI18nChunk({
|
|
186
|
-
[key]: value
|
|
187
|
-
});
|
|
188
|
-
i18nStr = value;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return i18nStr;
|
|
201
|
+
return i18nMechanismForComponents(i18nStr, key);
|
|
192
202
|
};
|
|
193
203
|
}
|
package/lib/index.js
CHANGED
|
@@ -150,6 +150,12 @@ Object.defineProperty(exports, "pad", {
|
|
|
150
150
|
return _utils.pad;
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
+
Object.defineProperty(exports, "placeComponentForTags", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function get() {
|
|
156
|
+
return _jsxTranslations.placeComponentForTags;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
153
159
|
Object.defineProperty(exports, "replaceI18NValuesWithRegex", {
|
|
154
160
|
enumerable: true,
|
|
155
161
|
get: function get() {
|
|
@@ -205,6 +211,8 @@ var _DateTimeDiffFormat = _interopRequireDefault(require("./components/DateTimeD
|
|
|
205
211
|
|
|
206
212
|
var _UserTimeDiffFormat = _interopRequireDefault(require("./components/UserTimeDiffFormat"));
|
|
207
213
|
|
|
214
|
+
var _jsxTranslations = require("./utils/jsxTranslations");
|
|
215
|
+
|
|
208
216
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
209
217
|
|
|
210
218
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createElement = createElement;
|
|
7
7
|
exports.generateChildren = generateChildren;
|
|
8
8
|
exports.getI18NComponent = getI18NComponent;
|
|
9
|
+
exports.placeComponentForTags = placeComponentForTags;
|
|
9
10
|
exports.prepareI18NFunc = prepareI18NFunc;
|
|
10
11
|
exports.replaceWithComponentPlaceHolder = replaceWithComponentPlaceHolder;
|
|
11
12
|
exports.splitMatchedExp = splitMatchedExp;
|
|
@@ -14,6 +15,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
14
15
|
|
|
15
16
|
var _index = require("./index");
|
|
16
17
|
|
|
18
|
+
var _I18NProvider = require("../components/I18NProvider");
|
|
19
|
+
|
|
17
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
18
21
|
|
|
19
22
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -214,6 +217,25 @@ function prepareI18NFunc() {
|
|
|
214
217
|
});
|
|
215
218
|
}
|
|
216
219
|
|
|
220
|
+
function i18nMechanismForComponents(i18nValue, key) {
|
|
221
|
+
if (typeof i18nValue === 'string') {
|
|
222
|
+
i18nValue = (0, _index.unescapeUnicode)(i18nValue);
|
|
223
|
+
var value = prepareI18NFunc({
|
|
224
|
+
i18nKey: i18nValue
|
|
225
|
+
});
|
|
226
|
+
window.loadI18nChunk && window.loadI18nChunk(_defineProperty({}, key, value));
|
|
227
|
+
i18nValue = value;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return i18nValue;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function placeComponentForTags(i18nValue) {
|
|
234
|
+
var value = _I18NProvider.i18NProviderUtils.getI18NComponent(i18nValue);
|
|
235
|
+
|
|
236
|
+
return i18nMechanismForComponents(value, value);
|
|
237
|
+
}
|
|
238
|
+
|
|
217
239
|
function getI18NComponent(i18n) {
|
|
218
240
|
if (typeof i18n === 'undefined') {
|
|
219
241
|
return function (key) {
|
|
@@ -228,15 +250,6 @@ function getI18NComponent(i18n) {
|
|
|
228
250
|
return key;
|
|
229
251
|
}
|
|
230
252
|
|
|
231
|
-
|
|
232
|
-
i18nStr = (0, _index.unescapeUnicode)(i18nStr);
|
|
233
|
-
var value = prepareI18NFunc({
|
|
234
|
-
i18nKey: i18nStr
|
|
235
|
-
});
|
|
236
|
-
window.loadI18nChunk && window.loadI18nChunk(_defineProperty({}, key, value));
|
|
237
|
-
i18nStr = value;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return i18nStr;
|
|
253
|
+
return i18nMechanismForComponents(i18nStr, key);
|
|
241
254
|
};
|
|
242
255
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/i18n",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.34",
|
|
4
4
|
"main": "lib/index",
|
|
5
5
|
"module": "es/index.js",
|
|
6
6
|
"jsnext:main": "es/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"lint": "react-cli lint"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@zoho/SecurityJS": "7.2.
|
|
23
|
+
"@zoho/SecurityJS": "7.2.4"
|
|
24
24
|
},
|
|
25
25
|
"react-cli": {
|
|
26
26
|
"docs": {
|
package/src/index.js
CHANGED
|
@@ -33,5 +33,6 @@ export { default as FormatText } from './components/FormatText';
|
|
|
33
33
|
export { default as PluralFormat } from './components/PluralFormat';
|
|
34
34
|
export { default as DateTimeDiffFormat } from './components/DateTimeDiffFormat';
|
|
35
35
|
export { default as UserTimeDiffFormat } from './components/UserTimeDiffFormat';
|
|
36
|
+
export { placeComponentForTags } from "./utils/jsxTranslations";
|
|
36
37
|
export const getI18NValue = (i18n, key, values) =>
|
|
37
38
|
getI18NValue1(i18n)(key, values);
|
|
@@ -2,6 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
unescapeUnicode
|
|
4
4
|
} from './index';
|
|
5
|
+
import {
|
|
6
|
+
i18NProviderUtils
|
|
7
|
+
} from "../components/I18NProvider";
|
|
5
8
|
|
|
6
9
|
export function splitMatchedExp({
|
|
7
10
|
expression,
|
|
@@ -156,6 +159,25 @@ export function prepareI18NFunc({
|
|
|
156
159
|
});
|
|
157
160
|
}
|
|
158
161
|
|
|
162
|
+
function i18nMechanismForComponents(i18nValue, key) {
|
|
163
|
+
if(typeof i18nValue === 'string') {
|
|
164
|
+
i18nValue = unescapeUnicode(i18nValue);
|
|
165
|
+
const value = prepareI18NFunc({
|
|
166
|
+
i18nKey: i18nValue
|
|
167
|
+
});
|
|
168
|
+
window.loadI18nChunk && window.loadI18nChunk({
|
|
169
|
+
[key] : value
|
|
170
|
+
});
|
|
171
|
+
i18nValue = value;
|
|
172
|
+
}
|
|
173
|
+
return i18nValue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function placeComponentForTags(i18nValue) {
|
|
177
|
+
const value = i18NProviderUtils.getI18NComponent(i18nValue);
|
|
178
|
+
return i18nMechanismForComponents(value, value);
|
|
179
|
+
}
|
|
180
|
+
|
|
159
181
|
export function getI18NComponent(i18n) {
|
|
160
182
|
if(typeof i18n === 'undefined') {
|
|
161
183
|
return (key) => key;
|
|
@@ -165,16 +187,6 @@ export function getI18NComponent(i18n) {
|
|
|
165
187
|
if (i18nStr === undefined) {
|
|
166
188
|
return key;
|
|
167
189
|
}
|
|
168
|
-
|
|
169
|
-
i18nStr = unescapeUnicode(i18nStr);
|
|
170
|
-
const value = prepareI18NFunc({
|
|
171
|
-
i18nKey: i18nStr
|
|
172
|
-
});
|
|
173
|
-
window.loadI18nChunk && window.loadI18nChunk({
|
|
174
|
-
[key] : value
|
|
175
|
-
});
|
|
176
|
-
i18nStr = value;
|
|
177
|
-
}
|
|
178
|
-
return i18nStr;
|
|
190
|
+
return i18nMechanismForComponents(i18nStr, key);
|
|
179
191
|
}
|
|
180
192
|
}
|