@zohodesk/i18n 1.0.0-beta.3 → 1.0.0-beta.30

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