@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
@@ -9,6 +9,8 @@ export default class UserTimeDiffFormat extends Component {
9
9
  let currentTimeUTCString = currentTime.toISOString();
10
10
  let {
11
11
  type,
12
+ page,
13
+ isNeedTime,
12
14
  to,
13
15
  today,
14
16
  yesterday,
@@ -21,32 +23,31 @@ export default class UserTimeDiffFormat extends Component {
21
23
  className,
22
24
  displayType,
23
25
  dataId,
24
- isOverdue
26
+ isOverdue,
27
+ isDateField
25
28
  } = this.props;
26
- let { tzData, timeFormat, datePattern, dateTimeFormat, timeZone } =
29
+ let { tzData, timeFormat, datePattern, isEnabledCurrentYear } =
27
30
  this.context || {};
28
31
 
29
32
  if (!format && !others) {
30
- let pattern =
31
- displayType === 'date'
32
- ? datePattern
33
- : displayType === 'time'
34
- ? timeFormat
35
- : displayType === 'dateTime'
33
+ format = ({ dateTimeFormat, dateFormat, timeFormat }) => {
34
+ displayType === 'dateTime'
36
35
  ? dateTimeFormat
37
- : '';
38
- format = () => pattern;
36
+ : displayType === 'date'
37
+ ? dateFormat
38
+ : timeFormat;
39
+ };
39
40
  }
40
41
 
41
- let tz = tzData || timeZone;
42
-
43
42
  return (
44
43
  <DateTimeDiffFormat
45
44
  type={type}
45
+ page={page}
46
+ isNeedTime={isNeedTime}
46
47
  from={currentTimeUTCString}
47
- fromTzData={tz}
48
+ fromTzData={tzData}
48
49
  to={to}
49
- toTzData={tz}
50
+ toTzData={tzData}
50
51
  today={today}
51
52
  yesterday={yesterday}
52
53
  tomorrow={tomorrow}
@@ -58,6 +59,10 @@ export default class UserTimeDiffFormat extends Component {
58
59
  className={className}
59
60
  dataId={dataId}
60
61
  isOverdue={isOverdue}
62
+ timeFormat={timeFormat}
63
+ datePattern={datePattern}
64
+ isEnabledCurrentYear={isEnabledCurrentYear}
65
+ isDateField={isDateField}
61
66
  />
62
67
  );
63
68
  }
@@ -68,6 +73,7 @@ UserTimeDiffFormat.propTypes = {
68
73
  dataId: PropTypes.string,
69
74
  displayType: PropTypes.oneOf(['date', 'time', 'dateTime']),
70
75
  format: PropTypes.func,
76
+ isDateField: PropTypes.bool,
71
77
  later: PropTypes.string,
72
78
  others: PropTypes.func,
73
79
  title: PropTypes.string,
@@ -75,17 +81,17 @@ UserTimeDiffFormat.propTypes = {
75
81
  today: PropTypes.oneOfType([
76
82
  PropTypes.string,
77
83
  PropTypes.object,
78
- PropTypes.func
84
+ PropTypes.func,
79
85
  ]),
80
86
  tomorrow: PropTypes.oneOfType([
81
87
  PropTypes.string,
82
88
  PropTypes.object,
83
- PropTypes.func
89
+ PropTypes.func,
84
90
  ]),
85
91
  yesterday: PropTypes.oneOfType([
86
92
  PropTypes.string,
87
93
  PropTypes.object,
88
- PropTypes.func
89
- ])
94
+ PropTypes.func,
95
+ ]),
90
96
  };
91
97
  UserTimeDiffFormat.contextType = I18NContext;
package/src/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export {
2
- browserOffset,
3
2
  formatDate,
4
3
  pad,
5
4
  replaceI18NValuesWithRegex,
@@ -11,22 +10,22 @@ export {
11
10
  isTomorrow,
12
11
  isWithinAWeek,
13
12
  isTwoWeeksOrMore,
14
- convertTimezone,
15
- getUtcTimeStamp,
16
- convertUtcToUserTz,
17
- convertUserTzToUtc,
18
13
  userDateFormat,
19
14
  getDiffObj,
20
15
  getLyears,
21
16
  getSuffix,
22
- getFormatedDate
17
+ getDatePatternWithoutYear,
18
+ setLocalizedData,
19
+ setI18NKeyMapping,
20
+ dayi18n,
21
+ monthi18n,
22
+ timei18n
23
23
  } from './utils';
24
24
  import { getI18NValue as getI18NValue1 } from './utils';
25
- export { unpack, getTimezoneOffset } from './timezones';
26
25
  export { I18NContext } from './I18NContext';
27
26
  export {
28
27
  default as I18NProvider,
29
- i18NProviderUtils
28
+ i18NProviderUtils,
30
29
  } from './components/I18NProvider';
31
30
  export { default as I18N } from './components/I18N';
32
31
  export { default as HOCI18N } from './components/HOCI18N';
@@ -36,4 +35,3 @@ export { default as DateTimeDiffFormat } from './components/DateTimeDiffFormat';
36
35
  export { default as UserTimeDiffFormat } from './components/UserTimeDiffFormat';
37
36
  export const getI18NValue = (i18n, key, values) =>
38
37
  getI18NValue1(i18n)(key, values);
39
- export { default as NewDateFormat } from './components/NewDateFormat';
@@ -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
+ });