@zohodesk/i18n 1.0.0-beta.15.1 → 1.0.0-beta.18

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 (67) hide show
  1. package/README.md +73 -41
  2. package/es/components/DateTimeDiffFormat.js +46 -12
  3. package/es/components/HOCI18N.js +33 -30
  4. package/es/components/I18NProvider.js +7 -16
  5. package/es/components/UserTimeDiffFormat.js +11 -9
  6. package/es/components/__tests__/DateTimeDiffFormat.spec.js +177 -136
  7. package/es/components/__tests__/FormatText.spec.js +0 -1
  8. package/es/components/__tests__/HOCI18N.spec.js +0 -1
  9. package/es/components/__tests__/I18N.spec.js +0 -2
  10. package/es/components/__tests__/I18NProvider.spec.js +0 -1
  11. package/es/components/__tests__/PluralFormat.spec.js +0 -1
  12. package/es/components/__tests__/UserTimeDiffFormat.spec.js +287 -206
  13. package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  14. package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  15. package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  16. package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  17. package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  18. package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  19. package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  20. package/es/index.js +2 -3
  21. package/es/utils.js +119 -171
  22. package/lib/components/DateTimeDiffFormat.js +49 -15
  23. package/lib/components/FormatText.js +4 -4
  24. package/lib/components/HOCI18N.js +4 -4
  25. package/lib/components/I18N.js +4 -4
  26. package/lib/components/I18NProvider.js +12 -21
  27. package/lib/components/PluralFormat.js +4 -4
  28. package/lib/components/UserTimeDiffFormat.js +12 -14
  29. package/lib/components/__tests__/I18NProvider.spec.js +1 -1
  30. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1 -1
  31. package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  32. package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  33. package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  34. package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  35. package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  36. package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  37. package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  38. package/lib/index.js +54 -56
  39. package/lib/utils.js +130 -212
  40. package/package.json +28 -28
  41. package/src/I18NContext.js +2 -2
  42. package/src/components/DateTimeDiffFormat.js +254 -211
  43. package/src/components/FormatText.js +14 -14
  44. package/src/components/HOCI18N.js +37 -37
  45. package/src/components/I18N.js +72 -72
  46. package/src/components/I18NProvider.js +106 -116
  47. package/src/components/PluralFormat.js +37 -37
  48. package/src/components/UserTimeDiffFormat.js +94 -103
  49. package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
  50. package/src/components/__tests__/FormatText.spec.js +26 -26
  51. package/src/components/__tests__/HOCI18N.spec.js +33 -33
  52. package/src/components/__tests__/I18N.spec.js +29 -29
  53. package/src/components/__tests__/I18NProvider.spec.js +65 -65
  54. package/src/components/__tests__/PluralFormat.spec.js +27 -27
  55. package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
  56. package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  57. package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  58. package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  59. package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  60. package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  61. package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  62. package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  63. package/src/index.js +33 -33
  64. package/src/utils.js +527 -587
  65. package/es/components/NewDateFormat.js +0 -53
  66. package/lib/components/NewDateFormat.js +0 -60
  67. package/src/components/NewDateFormat.js +0 -60
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@zohodesk/i18n",
3
- "version": "1.0.0-beta.15.1",
4
- "main": "lib/index",
5
- "module": "es/index.js",
6
- "jsnext:main": "es/index.js",
7
- "private": false,
8
- "umdVar": "i18n",
9
- "author": "",
10
- "license": "ISC",
11
- "scripts": {
12
- "clean": "react-cli clean lib es coverage",
13
- "build": "react-cli build:component:cmjs",
14
- "build:es": "react-cli build:library:es",
15
- "build:dev": "npm run clean && npm run build --module:mode=dev -- -w",
16
- "prepublish": "npm run init && npm run build && npm run build:es ",
17
- "prepare": "npm run init && npm run build && npm run build:es",
18
- "init": "npm run clean",
19
- "lint": "react-cli lint"
20
- },
21
- "dependencies": {
22
- "@zoho/SecurityJS": "5.0.2"
23
- },
24
- "react-cli": {
25
- "docs": {
26
- "componentFolder": "./src"
27
- }
28
- }
1
+ {
2
+ "name": "@zohodesk/i18n",
3
+ "version": "1.0.0-beta.18",
4
+ "main": "lib/index",
5
+ "module": "es/index.js",
6
+ "jsnext:main": "es/index.js",
7
+ "private": false,
8
+ "umdVar": "i18n",
9
+ "author": "",
10
+ "license": "ISC",
11
+ "scripts": {
12
+ "clean": "react-cli clean lib es coverage",
13
+ "build": "react-cli build:component:cmjs",
14
+ "build:es": "react-cli build:library:es",
15
+ "build:dev": "npm run clean && npm run build --module:mode=dev -- -w",
16
+ "prepublish": "npm run init && npm run build && npm run build:es ",
17
+ "prepare": "npm run init && npm run build && npm run build:es",
18
+ "init": "npm run clean",
19
+ "lint": "react-cli lint"
20
+ },
21
+ "dependencies": {
22
+ "@zoho/SecurityJS": "5.0.2"
23
+ },
24
+ "react-cli": {
25
+ "docs": {
26
+ "componentFolder": "./src"
27
+ }
28
+ }
29
29
  }
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
-
1
+ import React from 'react';
2
+
3
3
  export const I18NContext = React.createContext();
@@ -1,211 +1,254 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { pad, getValues, getDiffObj, formatDate, getLyears } from '../utils';
4
- import FormatText from './FormatText';
5
- import datetime from '@zohodesk/datetimejs';
6
- export default class DateTimeDiffFormat extends React.Component {
7
- constructor(props) {
8
- super(props);
9
- this.getSuffix = this.getSuffix.bind(this);
10
- }
11
-
12
- getSuffix(min) {
13
- let suffix;
14
- if (this.props.ago && min < 0) {
15
- suffix = this.props.ago || '';
16
- } else if (this.props.later || min > 0) {
17
- suffix = this.props.later || '';
18
- } else {
19
- suffix = '';
20
- }
21
- return suffix;
22
- }
23
-
24
- render() {
25
- const {
26
- type,
27
- page,
28
- isNeedTime,
29
- from,
30
- fromTzData,
31
- to,
32
- toTzData,
33
- today,
34
- yesterday,
35
- tomorrow,
36
- others,
37
- format,
38
- dataId,
39
- className = null,
40
- title = null,
41
- isOverdue,
42
- timeFormat,
43
- dateTimeFormat,
44
- defaulDatePattern,
45
- defaultDateTimeFormat,
46
- } = this.props;
47
-
48
- let fromDateObj = datetime
49
- .toDate(datetime.tz.utcToTz(from, fromTzData))
50
- .getTime();
51
- let toDateObj = datetime
52
- .toDate(datetime.tz.utcToTz(to, toTzData))
53
- .getTime();
54
-
55
- let diffMin = new Date(to).getTime() - new Date(from).getTime();
56
- let suffix = this.getSuffix(diffMin);
57
- let diff = getDiffObj(diffMin);
58
- let withInAWeak = diff.y === 0 && diff.yd <= 7;
59
-
60
- let diffObj = {
61
- h: diff.h,
62
- m: diff.m,
63
- s: diff.s,
64
- y: diff.y,
65
- hh: pad(diff.h, 2),
66
- mm: pad(diff.m, 2),
67
- ss: pad(diff.s, 2),
68
- yy: pad(diff.y, 2),
69
- days: diff.yd,
70
- yDays: pad(diff.yd, 2),
71
- isWithInAWeek: withInAWeak,
72
- suffix: suffix,
73
- };
74
- let diffObj1 = {
75
- to: to,
76
- type: type,
77
- page: page,
78
- isNeedTime: isNeedTime,
79
- hours: diff.h,
80
- minutes: diff.m,
81
- seconds: diff.s,
82
- years: diff.y,
83
- yDays: diff.yd,
84
- yMonth: diff.m,
85
- isWithInAWeek: withInAWeak,
86
- suffix: suffix,
87
- crntDate: new Date(from).getDate(),
88
- crntMonth: new Date(from).getMonth(),
89
- crntYear: new Date(from).getFullYear(),
90
- crntHours: new Date(from).getHours(),
91
- crntMinutes: new Date(from).getMinutes(),
92
- crntSeconds: new Date(from).getSeconds(),
93
- tDate: new Date(to).getDate(),
94
- tMonth: new Date(to).getMonth(),
95
- tYear: new Date(to).getFullYear(),
96
- tHours: new Date(to).getHours(),
97
- tMinutes: new Date(to).getMinutes(),
98
- tSeconds: new Date(to).getSeconds(),
99
- betweenleepYears: getLyears(from, to),
100
- isOverdue: isOverdue,
101
- timeFormat: timeFormat,
102
- datePattern: defaulDatePattern,
103
- dateTimeFormat: defaultDateTimeFormat,
104
- };
105
-
106
- let key = '';
107
- let values = [];
108
- let text = null;
109
- let isSuffixEnable = false;
110
- if (format) {
111
- let years, months, days, hours, minutes, seconds;
112
- years = diffObj1.years > 1 ? '2' : diffObj1.years;
113
-
114
- days = diff.yd > 1 ? '2' : diff.yd;
115
- hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
116
- minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
117
-
118
- let count = 0;
119
- let pattern = [years, days, hours, minutes].reduce((res, next) => {
120
- if (count === 2) {
121
- res = `${res}0`;
122
- } else if (next !== 0) {
123
- count++;
124
- res = res + next;
125
- } else {
126
- res = res + next;
127
- }
128
- return res;
129
- }, '');
130
-
131
- let value = format(diffObj1, pattern);
132
- if (value && typeof value === 'object') {
133
- key = value.key;
134
- values = getValues(value.params, diffObj);
135
- if (pattern.indexOf('00000') === 0) {
136
- //suffix ignore for second hook
137
- isSuffixEnable = false;
138
- } else {
139
- isSuffixEnable = true;
140
- }
141
- } else if (typeof value === 'string') {
142
- text = formatDate(toDateObj, value, diffObj1);
143
- }
144
- } else {
145
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
146
- let dateObj = new Date(toDateObj);
147
- let curDateObj = new Date(fromDateObj);
148
- if (dateObj.getDate() === curDateObj.getDate()) {
149
- var value = (today && today(diffObj1)) || others(diffObj1);
150
- text = formatDate(toDateObj, value);
151
- } else if (
152
- (dateObj.getMonth() === curDateObj.getMonth() &&
153
- dateObj.getDate() < curDateObj.getDate()) ||
154
- dateObj.getMonth() < curDateObj.getMonth()
155
- ) {
156
- var value = (yesterday && yesterday(diffObj1)) || others(diffObj1);
157
- text = formatDate(toDateObj, value);
158
- } else if (
159
- dateObj.getMonth() > curDateObj.getMonth() ||
160
- dateObj.getDate() > curDateObj.getDate()
161
- ) {
162
- var value = (tomorrow && tomorrow(diffObj1)) || others(diffObj1);
163
- text = formatDate(toDateObj, value);
164
- }
165
- } else {
166
- var value = others(diffObj1);
167
- text = formatDate(toDateObj, value);
168
- }
169
- }
170
- return text ? (
171
- <span className={className} data-title={title} data-id={dataId}>
172
- {text}
173
- </span>
174
- ) : (
175
- <FormatText
176
- i18NKey={isSuffixEnable && suffix !== '' ? `${key}.${suffix}` : key}
177
- values={values}
178
- className={className}
179
- data-title={title}
180
- />
181
- );
182
- }
183
- }
184
- DateTimeDiffFormat.propTypes = {
185
- ago: PropTypes.string,
186
- className: PropTypes.string,
187
- dataId: PropTypes.string,
188
- format: PropTypes.func,
189
- from: PropTypes.string,
190
- fromTzData: PropTypes.object,
191
- later: PropTypes.string,
192
- others: PropTypes.func,
193
- title: PropTypes.string,
194
- to: PropTypes.string,
195
- toTzData: PropTypes.object,
196
- today: PropTypes.oneOfType([
197
- PropTypes.string,
198
- PropTypes.object,
199
- PropTypes.func,
200
- ]),
201
- tomorrow: PropTypes.oneOfType([
202
- PropTypes.string,
203
- PropTypes.object,
204
- PropTypes.func,
205
- ]),
206
- yesterday: PropTypes.oneOfType([
207
- PropTypes.string,
208
- PropTypes.object,
209
- PropTypes.func,
210
- ]),
211
- };
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {
4
+ pad,
5
+ getValues,
6
+ getDiffObj,
7
+ formatDate,
8
+ getLyears,
9
+ getDatePatternWithoutYear,
10
+ } from '../utils';
11
+ import FormatText from './FormatText';
12
+ import datetime from '@zohodesk/datetimejs';
13
+ export default class DateTimeDiffFormat extends React.Component {
14
+ constructor(props) {
15
+ super(props);
16
+ this.getSuffix = this.getSuffix.bind(this);
17
+ }
18
+
19
+ getSuffix(min) {
20
+ let suffix;
21
+ if (this.props.ago && min < 0) {
22
+ suffix = this.props.ago || '';
23
+ } else if (this.props.later || min > 0) {
24
+ suffix = this.props.later || '';
25
+ } else {
26
+ suffix = '';
27
+ }
28
+ return suffix;
29
+ }
30
+
31
+ render() {
32
+ const {
33
+ type,
34
+ page,
35
+ isNeedTime,
36
+ from,
37
+ fromTzData,
38
+ to,
39
+ toTzData,
40
+ today,
41
+ yesterday,
42
+ tomorrow,
43
+ others,
44
+ format,
45
+ dataId,
46
+ className = null,
47
+ title = null,
48
+ isOverdue,
49
+ timeFormat,
50
+ datePattern,
51
+ isEnabledCurrentYear,
52
+ } = this.props;
53
+
54
+ let fromDateObj = datetime
55
+ .toDate(datetime.tz.utcToTz(from, fromTzData))
56
+ .getTime();
57
+ let toDateObj = datetime
58
+ .toDate(datetime.tz.utcToTz(to, toTzData))
59
+ .getTime();
60
+
61
+ let diffMin = new Date(to).getTime() - new Date(from).getTime();
62
+ let suffix = this.getSuffix(diffMin);
63
+ let diff = getDiffObj(diffMin);
64
+ let withInAWeak = diff.y === 0 && diff.yd <= 7;
65
+
66
+ let diffObj = {
67
+ h: diff.h,
68
+ m: diff.m,
69
+ s: diff.s,
70
+ y: diff.y,
71
+ hh: pad(diff.h, 2),
72
+ mm: pad(diff.m, 2),
73
+ ss: pad(diff.s, 2),
74
+ yy: pad(diff.y, 2),
75
+ days: diff.yd,
76
+ yDays: pad(diff.yd, 2),
77
+ isWithInAWeek: withInAWeak,
78
+ suffix: suffix,
79
+ };
80
+ let diffObj1 = {
81
+ to: to,
82
+ type: type,
83
+ page: page,
84
+ isNeedTime: isNeedTime,
85
+ hours: diff.h,
86
+ minutes: diff.m,
87
+ seconds: diff.s,
88
+ years: diff.y,
89
+ yDays: diff.yd,
90
+ isWithInAWeek: withInAWeak,
91
+ suffix: suffix,
92
+ crntDate: new Date(from).getDate(),
93
+ crntMonth: new Date(from).getMonth(),
94
+ crntYear: new Date(from).getFullYear(),
95
+ crntHours: new Date(from).getHours(),
96
+ crntMinutes: new Date(from).getMinutes(),
97
+ crntSeconds: new Date(from).getSeconds(),
98
+ tDate: new Date(to).getDate(),
99
+ tMonth: new Date(to).getMonth(),
100
+ tYear: new Date(to).getFullYear(),
101
+ tHours: new Date(to).getHours(),
102
+ tMinutes: new Date(to).getMinutes(),
103
+ tSeconds: new Date(to).getSeconds(),
104
+ betweenleepYears: getLyears(from, to),
105
+ isOverdue: isOverdue,
106
+ timeFormat: timeFormat,
107
+ datePattern: datePattern,
108
+ dateTimePattern: `${datePattern} ${timeFormat}`,
109
+ };
110
+
111
+ //In if condition we'll remove year and set date format if the current year is not required
112
+ //In else part we'll set the date format as it is
113
+ if (
114
+ isEnabledCurrentYear === true &&
115
+ diffObj1.years === 0 &&
116
+ diffObj1.tYear === diffObj1.crntYear
117
+ ) {
118
+ let dateFormat = getDatePatternWithoutYear(datePattern);
119
+ diffObj1.dateFormat = dateFormat;
120
+ diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
121
+ } else {
122
+ diffObj1.dateFormat = datePattern;
123
+ diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
124
+ }
125
+
126
+ let key = '';
127
+ let values = [];
128
+ let text = null;
129
+ let isSuffixEnable = false;
130
+ if (format) {
131
+ let years, months, days, hours, minutes, seconds;
132
+ years = diffObj1.years > 1 ? '2' : diffObj1.years;
133
+
134
+ days = diff.yd > 1 ? '2' : diff.yd;
135
+ hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
136
+ minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
137
+
138
+ let count = 0;
139
+ let pattern = [years, days, hours, minutes].reduce((res, next) => {
140
+ if (count === 2) {
141
+ res = `${res}0`;
142
+ } else if (next !== 0) {
143
+ count++;
144
+ res = res + next;
145
+ } else {
146
+ res = res + next;
147
+ }
148
+ return res;
149
+ }, '');
150
+
151
+ let value = format(diffObj1, pattern);
152
+ if (value && typeof value === 'object') {
153
+ key = value.key;
154
+ values = getValues(value.params, diffObj);
155
+ if (pattern.indexOf('00000') === 0) {
156
+ //suffix ignore for second hook
157
+ isSuffixEnable = false;
158
+ } else {
159
+ isSuffixEnable = true;
160
+ }
161
+ } else if (typeof value === 'string') {
162
+ text = formatDate(toDateObj, value, diffObj1);
163
+ }
164
+ } else {
165
+ let dateObj = new Date(toDateObj);
166
+ let curDateObj = new Date(fromDateObj);
167
+ let diffDayType = diffObj1.yDays;
168
+
169
+ //In this condition, to calculate different days we have copied it from live --> diffDayType
170
+ if (
171
+ isOverdue &&
172
+ dateObj.getDate() < curDateObj.getDate() &&
173
+ diffObj1.yDays == 0
174
+ ) {
175
+ diffDayType = -1;
176
+ }
177
+ if (!isOverdue) {
178
+ let diffHr = dateObj.getHours() - curDateObj.getHours();
179
+ if (diffHr < 0) {
180
+ diffDayType += 1;
181
+ } else if (diffHr == 0) {
182
+ let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
183
+ if (diffMins < 0) {
184
+ diffDayType += 1;
185
+ } else if (diffMins == 0) {
186
+ let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
187
+ if (diffSec < 0) {
188
+ diffDayType += 1;
189
+ }
190
+ }
191
+ }
192
+ }
193
+ if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
194
+ if (dateObj.getDate() === curDateObj.getDate()) {
195
+ var value = (today && today(diffObj1)) || others(diffObj1);
196
+ text = formatDate(toDateObj, value);
197
+ } else if (
198
+ (dateObj.getMonth() === curDateObj.getMonth() &&
199
+ dateObj.getDate() < curDateObj.getDate()) ||
200
+ dateObj.getMonth() < curDateObj.getMonth()
201
+ ) {
202
+ var value = (yesterday && yesterday(diffObj1)) || others(diffObj1);
203
+ text = formatDate(toDateObj, value);
204
+ } else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
205
+ var value = (tomorrow && tomorrow(diffObj1)) || others(diffObj1);
206
+ text = formatDate(toDateObj, value);
207
+ }
208
+ } else {
209
+ var value = others(diffObj1);
210
+ text = formatDate(toDateObj, value);
211
+ }
212
+ }
213
+ return text ? (
214
+ <span className={className} data-title={title} data-id={dataId}>
215
+ {text}
216
+ </span>
217
+ ) : (
218
+ <FormatText
219
+ i18NKey={isSuffixEnable && suffix !== '' ? `${key}.${suffix}` : key}
220
+ values={values}
221
+ className={className}
222
+ data-title={title}
223
+ />
224
+ );
225
+ }
226
+ }
227
+ DateTimeDiffFormat.propTypes = {
228
+ ago: PropTypes.string,
229
+ className: PropTypes.string,
230
+ dataId: PropTypes.string,
231
+ format: PropTypes.func,
232
+ from: PropTypes.string,
233
+ fromTzData: PropTypes.object,
234
+ later: PropTypes.string,
235
+ others: PropTypes.func,
236
+ title: PropTypes.string,
237
+ to: PropTypes.string,
238
+ toTzData: PropTypes.object,
239
+ today: PropTypes.oneOfType([
240
+ PropTypes.string,
241
+ PropTypes.object,
242
+ PropTypes.func,
243
+ ]),
244
+ tomorrow: PropTypes.oneOfType([
245
+ PropTypes.string,
246
+ PropTypes.object,
247
+ PropTypes.func,
248
+ ]),
249
+ yesterday: PropTypes.oneOfType([
250
+ PropTypes.string,
251
+ PropTypes.object,
252
+ PropTypes.func,
253
+ ]),
254
+ };
@@ -1,14 +1,14 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import I18N from './I18N';
4
-
5
- export default class FormatText extends React.Component {
6
- render() {
7
- return <I18N {...this.props} />;
8
- }
9
- }
10
- FormatText.propTypes = {
11
- i18NKey: PropTypes.string.isRequired,
12
- isHtml: PropTypes.bool,
13
- values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
14
- };
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import I18N from './I18N';
4
+
5
+ export default class FormatText extends React.Component {
6
+ render() {
7
+ return <I18N {...this.props} />;
8
+ }
9
+ }
10
+ FormatText.propTypes = {
11
+ i18NKey: PropTypes.string.isRequired,
12
+ isHtml: PropTypes.bool,
13
+ values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
14
+ };
@@ -1,37 +1,37 @@
1
- import React, { Children } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { replaceI18NValuesWithRegex, unescapeUnicode } from '../utils';
4
- import { I18NContext } from '../I18NContext';
5
- export default (i18NKeys = []) => Component => {
6
- class HOCI18N extends React.Component {
7
- constructor(props) {
8
- super(props);
9
- this.getI18NValue = this.getI18NValue.bind(this);
10
- }
11
-
12
- getI18NValue(key) {
13
- const { i18n } = this.context || {};
14
- if (typeof i18n === 'undefined') {
15
- return key;
16
- }
17
- let i18nStr = i18n[key];
18
- if (i18nStr === undefined) {
19
- return key;
20
- }
21
- return unescapeUnicode(i18nStr);
22
- }
23
-
24
- render() {
25
- let i18nProps = i18NKeys.reduce((result, key) => {
26
- if (this.props[key]) {
27
- result[key] = this.getI18NValue(this.props[key]);
28
- }
29
- return result;
30
- }, {});
31
- return <Component {...this.props} {...i18nProps} />;
32
- }
33
- }
34
-
35
- HOCI18N.contextType = I18NContext;
36
- return HOCI18N;
37
- };
1
+ import React, { Children } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { replaceI18NValuesWithRegex, unescapeUnicode } from '../utils';
4
+ import { I18NContext } from '../I18NContext';
5
+ export default (i18NKeys = []) => Component => {
6
+ class HOCI18N extends React.Component {
7
+ constructor(props) {
8
+ super(props);
9
+ this.getI18NValue = this.getI18NValue.bind(this);
10
+ }
11
+
12
+ getI18NValue(key) {
13
+ const { i18n } = this.context || {};
14
+ if (typeof i18n === 'undefined') {
15
+ return key;
16
+ }
17
+ let i18nStr = i18n[key];
18
+ if (i18nStr === undefined) {
19
+ return key;
20
+ }
21
+ return unescapeUnicode(i18nStr);
22
+ }
23
+
24
+ render() {
25
+ let i18nProps = i18NKeys.reduce((result, key) => {
26
+ if (this.props[key]) {
27
+ result[key] = this.getI18NValue(this.props[key]);
28
+ }
29
+ return result;
30
+ }, {});
31
+ return <Component {...this.props} {...i18nProps} />;
32
+ }
33
+ }
34
+
35
+ HOCI18N.contextType = I18NContext;
36
+ return HOCI18N;
37
+ };