@zohodesk/i18n 1.0.0-beta.25 → 1.0.0-beta.27
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 +109 -101
- package/es/components/I18NProvider.js +5 -1
- package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/es/index.js +1 -1
- package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
- package/es/{utils.js → utils/index.js} +59 -6
- package/es/utils/jsxTranslations.js +193 -0
- package/lib/components/I18NProvider.js +6 -1
- package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/lib/index.js +6 -0
- package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
- package/lib/{utils.js → utils/index.js} +64 -6
- package/lib/utils/jsxTranslations.js +242 -0
- package/package.json +30 -29
- package/src/I18NContext.js +2 -2
- package/src/components/DateTimeDiffFormat.js +256 -256
- package/src/components/FormatText.js +14 -14
- package/src/components/HOCI18N.js +37 -37
- package/src/components/I18N.js +74 -74
- package/src/components/I18NProvider.js +116 -110
- package/src/components/PluralFormat.js +37 -37
- package/src/components/UserTimeDiffFormat.js +97 -97
- package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
- package/src/components/__tests__/FormatText.spec.js +26 -26
- package/src/components/__tests__/HOCI18N.spec.js +33 -33
- package/src/components/__tests__/I18N.spec.js +29 -29
- package/src/components/__tests__/I18NProvider.spec.js +65 -65
- package/src/components/__tests__/PluralFormat.spec.js +27 -27
- package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
- package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/src/index.js +37 -36
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/{utils.js → utils/index.js} +632 -585
- package/src/utils/jsxTranslations.js +180 -0
package/src/index.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
export {
|
|
2
|
-
formatDate,
|
|
3
|
-
pad,
|
|
4
|
-
replaceI18NValuesWithRegex,
|
|
5
|
-
unescapeUnicode,
|
|
6
|
-
getValues,
|
|
7
|
-
getI18NInfo,
|
|
8
|
-
isToday,
|
|
9
|
-
isYesterday,
|
|
10
|
-
isTomorrow,
|
|
11
|
-
isWithinAWeek,
|
|
12
|
-
isTwoWeeksOrMore,
|
|
13
|
-
userDateFormat,
|
|
14
|
-
getDiffObj,
|
|
15
|
-
getLyears,
|
|
16
|
-
getSuffix,
|
|
17
|
-
getDatePatternWithoutYear,
|
|
18
|
-
setLocalizedData,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export { default as
|
|
31
|
-
export { default as
|
|
32
|
-
export { default as
|
|
33
|
-
export { default as
|
|
34
|
-
export { default as
|
|
35
|
-
export
|
|
36
|
-
|
|
1
|
+
export {
|
|
2
|
+
formatDate,
|
|
3
|
+
pad,
|
|
4
|
+
replaceI18NValuesWithRegex,
|
|
5
|
+
unescapeUnicode,
|
|
6
|
+
getValues,
|
|
7
|
+
getI18NInfo,
|
|
8
|
+
isToday,
|
|
9
|
+
isYesterday,
|
|
10
|
+
isTomorrow,
|
|
11
|
+
isWithinAWeek,
|
|
12
|
+
isTwoWeeksOrMore,
|
|
13
|
+
userDateFormat,
|
|
14
|
+
getDiffObj,
|
|
15
|
+
getLyears,
|
|
16
|
+
getSuffix,
|
|
17
|
+
getDatePatternWithoutYear,
|
|
18
|
+
setLocalizedData,
|
|
19
|
+
setI18NKeyMapping,
|
|
20
|
+
dayi18n,
|
|
21
|
+
monthi18n,
|
|
22
|
+
timei18n
|
|
23
|
+
} from './utils';
|
|
24
|
+
import { getI18NValue as getI18NValue1 } from './utils';
|
|
25
|
+
export { I18NContext } from './I18NContext';
|
|
26
|
+
export {
|
|
27
|
+
default as I18NProvider,
|
|
28
|
+
i18NProviderUtils,
|
|
29
|
+
} from './components/I18NProvider';
|
|
30
|
+
export { default as I18N } from './components/I18N';
|
|
31
|
+
export { default as HOCI18N } from './components/HOCI18N';
|
|
32
|
+
export { default as FormatText } from './components/FormatText';
|
|
33
|
+
export { default as PluralFormat } from './components/PluralFormat';
|
|
34
|
+
export { default as DateTimeDiffFormat } from './components/DateTimeDiffFormat';
|
|
35
|
+
export { default as UserTimeDiffFormat } from './components/UserTimeDiffFormat';
|
|
36
|
+
export const getI18NValue = (i18n, key, values) =>
|
|
37
|
+
getI18NValue1(i18n)(key, values);
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
splitMatchedExp,
|
|
4
|
+
generateChildren,
|
|
5
|
+
replaceWithComponentPlaceHolder,
|
|
6
|
+
createElement,
|
|
7
|
+
prepareI18NFunc,
|
|
8
|
+
getI18NComponent
|
|
9
|
+
} from '../jsxTranslations';
|
|
10
|
+
|
|
11
|
+
function Bold({children}) {
|
|
12
|
+
return <b>{children}</b>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function Simple(props) {
|
|
16
|
+
return <span>{props.children}</span>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('Verifying splitMatchedExp method', () => {
|
|
20
|
+
it('A string with no match test', () => {
|
|
21
|
+
const response = splitMatchedExp({
|
|
22
|
+
expression: '{[0-9]+?}',
|
|
23
|
+
charLenToOmit: 1,
|
|
24
|
+
string: "Hello"
|
|
25
|
+
});
|
|
26
|
+
const expected = {
|
|
27
|
+
splitString: ['Hello'],
|
|
28
|
+
matchedExpKeys: []
|
|
29
|
+
};
|
|
30
|
+
expect(response).toEqual(expected);
|
|
31
|
+
});
|
|
32
|
+
it('A string with JSX Tag placeholder test', () => {
|
|
33
|
+
const response = splitMatchedExp({
|
|
34
|
+
expression: '<[A-Za-z0-9]+?>',
|
|
35
|
+
charLenToOmit: 1,
|
|
36
|
+
string: "Hi <00Good> occurs <01Strong>"
|
|
37
|
+
});
|
|
38
|
+
const expected = {
|
|
39
|
+
splitString: ["Hi ", " occurs ", ""],
|
|
40
|
+
matchedExpKeys: ['00Good', '01Strong']
|
|
41
|
+
};
|
|
42
|
+
expect(response).toEqual(expected);
|
|
43
|
+
});
|
|
44
|
+
it('A string with String placeholder test', () => {
|
|
45
|
+
const response = splitMatchedExp({
|
|
46
|
+
expression: '{[0-9]+?}',
|
|
47
|
+
charLenToOmit: 1,
|
|
48
|
+
string: "Hi {0} occurs {1}"
|
|
49
|
+
});
|
|
50
|
+
const expected = {
|
|
51
|
+
splitString: ["Hi ", " occurs ", ""],
|
|
52
|
+
matchedExpKeys: ['0', '1']
|
|
53
|
+
};
|
|
54
|
+
expect(response).toEqual(expected);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('Verifying generateChildren Method', () => {
|
|
59
|
+
it('A string with Tag Placeholder and String placeholders', () => {
|
|
60
|
+
const children = {
|
|
61
|
+
'00Good': () => {},
|
|
62
|
+
'01Strong': () => {}
|
|
63
|
+
}
|
|
64
|
+
const response = generateChildren({
|
|
65
|
+
children,
|
|
66
|
+
child: 'Hi <00Good>{0}<01Strong>'
|
|
67
|
+
});
|
|
68
|
+
const expected = {
|
|
69
|
+
newChildren : [
|
|
70
|
+
['Hi '],
|
|
71
|
+
children['00Good'],
|
|
72
|
+
['', ''],
|
|
73
|
+
children['01Strong']
|
|
74
|
+
],
|
|
75
|
+
stringPlaceHolders: {
|
|
76
|
+
0: [],
|
|
77
|
+
2: ['0']
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
expect(response).toEqual(expected);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('Verifying the replaceWithComponentPlaceHolder method', () => {
|
|
85
|
+
it('A JSX Tag with string', () => {
|
|
86
|
+
const response = replaceWithComponentPlaceHolder({
|
|
87
|
+
componentId: 'Simple',
|
|
88
|
+
i18nKey: '<Simple>Hi everyone</Simple>',
|
|
89
|
+
childrenLength: 1
|
|
90
|
+
});
|
|
91
|
+
const expected = '<01Simple>';
|
|
92
|
+
expect(response).toBe(expected);
|
|
93
|
+
});
|
|
94
|
+
it('A string with multiple JSX Tags', () => {
|
|
95
|
+
const response = replaceWithComponentPlaceHolder({
|
|
96
|
+
componentId: 'Simple',
|
|
97
|
+
i18nKey: 'Greetings <Simple>Hi everyone</Simple> for the <Simple>Day</Simple>',
|
|
98
|
+
childrenLength: 1
|
|
99
|
+
});
|
|
100
|
+
const expected = 'Greetings <01Simple> for the <Simple>Day</Simple>';
|
|
101
|
+
expect(response).toBe(expected);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('Verifying the createElement method', () => {
|
|
106
|
+
it('A component Id with JSX children and Dynamic String placeholders', () => {
|
|
107
|
+
const jsxChild = createElement({
|
|
108
|
+
componentId: 'Simple',
|
|
109
|
+
children: [
|
|
110
|
+
['Greetings']
|
|
111
|
+
],
|
|
112
|
+
stringPlaceHolders: {
|
|
113
|
+
0: []
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
const response = createElement({
|
|
117
|
+
componentId: -1,
|
|
118
|
+
children: [
|
|
119
|
+
['Hi ', ','],
|
|
120
|
+
jsxChild,
|
|
121
|
+
[' for the day']
|
|
122
|
+
],
|
|
123
|
+
stringPlaceHolders: {
|
|
124
|
+
0: ['0'],
|
|
125
|
+
2: []
|
|
126
|
+
}
|
|
127
|
+
})({
|
|
128
|
+
components: {
|
|
129
|
+
Simple: {
|
|
130
|
+
type: Simple
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
values: ['Zoho Desk']
|
|
134
|
+
});
|
|
135
|
+
const expected = (<React.Fragment>
|
|
136
|
+
Hi Zoho Desk,<Simple>Greetings</Simple> for the day
|
|
137
|
+
</React.Fragment>);
|
|
138
|
+
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('Verifying the prepareI18NFunc method', () => {
|
|
143
|
+
//Hi <Bo01ld>Gigiee</Bo01ld>,<Simple> How are you</Simple><Simple>Make it simple</Simple>
|
|
144
|
+
it('A text with sibling JSX tags and alphanumeric JSX Tags', () => {
|
|
145
|
+
const response = prepareI18NFunc({
|
|
146
|
+
i18nKey: 'Hi <Bo01ld>Gigiee</Bo01ld>,<Simple>How are you</Simple><Simple>Make it simple</Simple>'
|
|
147
|
+
})({
|
|
148
|
+
components: {
|
|
149
|
+
'Bo01ld': {
|
|
150
|
+
type: Bold
|
|
151
|
+
},
|
|
152
|
+
Simple: {
|
|
153
|
+
type: Simple
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const expected = (<React.Fragment>
|
|
158
|
+
Hi <Bold>
|
|
159
|
+
Gigiee
|
|
160
|
+
</Bold>,<Simple>
|
|
161
|
+
How are you
|
|
162
|
+
</Simple><Simple>
|
|
163
|
+
Make it simple
|
|
164
|
+
</Simple>
|
|
165
|
+
</React.Fragment>);
|
|
166
|
+
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('Verifying getI18NComponent method', () => {
|
|
171
|
+
it('An i18n key with JSX tag in its value', () => {
|
|
172
|
+
const i18n = {
|
|
173
|
+
'support.demo': 'Hi <Bo01ld>Gigiee</Bo01ld>,<Simple>How are you</Simple><Simple>Make it simple</Simple>'
|
|
174
|
+
}
|
|
175
|
+
const I18N = getI18NComponent(i18n);
|
|
176
|
+
const response = I18N('support.demo')({
|
|
177
|
+
components: {
|
|
178
|
+
'Bo01ld': {
|
|
179
|
+
type: Bold
|
|
180
|
+
},
|
|
181
|
+
Simple: {
|
|
182
|
+
type: Simple
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const expected = (<React.Fragment>
|
|
187
|
+
Hi <Bold>
|
|
188
|
+
Gigiee
|
|
189
|
+
</Bold>,<Simple>
|
|
190
|
+
How are you
|
|
191
|
+
</Simple><Simple>
|
|
192
|
+
Make it simple
|
|
193
|
+
</Simple>
|
|
194
|
+
</React.Fragment>);
|
|
195
|
+
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('Testing absence of i18n object', () => {
|
|
199
|
+
const I18N = getI18NComponent();
|
|
200
|
+
const response = I18N('support.demo');
|
|
201
|
+
const expected = 'support.demo';
|
|
202
|
+
expect(expected).toBe(response);
|
|
203
|
+
});
|
|
204
|
+
it('Testing of missing i18n key', () => {
|
|
205
|
+
const i18n = {
|
|
206
|
+
'support.demo': 'Demo'
|
|
207
|
+
};
|
|
208
|
+
const I18N = getI18NComponent(i18n);
|
|
209
|
+
const response = I18N('support.need');
|
|
210
|
+
const expected = 'support.need';
|
|
211
|
+
expect(expected).toBe(response);
|
|
212
|
+
});
|
|
213
|
+
});
|