@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.
- package/README.md +116 -2
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +192 -200
- package/es/components/FormatText.js +4 -25
- package/es/components/HOCI18N.js +33 -45
- package/es/components/I18N.js +48 -63
- package/es/components/I18NProvider.js +59 -85
- package/es/components/PluralFormat.js +29 -48
- package/es/components/UserTimeDiffFormat.js +65 -74
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +868 -657
- package/es/components/__tests__/FormatText.spec.js +20 -17
- package/es/components/__tests__/HOCI18N.spec.js +18 -22
- package/es/components/__tests__/I18N.spec.js +20 -19
- package/es/components/__tests__/I18NProvider.spec.js +36 -45
- package/es/components/__tests__/PluralFormat.spec.js +20 -17
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +1343 -1095
- package/es/index.js +2 -6
- package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
- package/es/utils/index.js +592 -0
- package/es/utils/jsxTranslations.js +193 -0
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +151 -123
- package/lib/components/FormatText.js +32 -22
- package/lib/components/HOCI18N.js +47 -23
- package/lib/components/I18N.js +62 -36
- package/lib/components/I18NProvider.js +82 -70
- package/lib/components/PluralFormat.js +42 -32
- package/lib/components/UserTimeDiffFormat.js +79 -56
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
- package/lib/components/__tests__/FormatText.spec.js +23 -25
- package/lib/components/__tests__/HOCI18N.spec.js +26 -34
- package/lib/components/__tests__/I18N.spec.js +21 -26
- package/lib/components/__tests__/I18NProvider.spec.js +43 -51
- package/lib/components/__tests__/PluralFormat.spec.js +24 -28
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
- package/lib/index.js +85 -110
- package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
- package/lib/utils/index.js +658 -0
- package/lib/utils/jsxTranslations.js +242 -0
- package/package.json +3 -2
- package/src/components/DateTimeDiffFormat.js +86 -55
- package/src/components/I18N.js +2 -0
- package/src/components/I18NProvider.js +34 -25
- package/src/components/UserTimeDiffFormat.js +24 -18
- package/src/index.js +7 -9
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/utils/index.js +632 -0
- package/src/utils/jsxTranslations.js +180 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -118
- package/es/utils.js +0 -621
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -129
- package/lib/utils.js +0 -651
- package/src/components/NewDateFormat.js +0 -60
- package/src/offset.js +0 -629
- package/src/timezones.js +0 -113
- package/src/utils.js +0 -648
package/src/timezones.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { offsetMap } from './offset';
|
|
2
|
-
function charCodeToInt(charCode) {
|
|
3
|
-
if (charCode > 96) {
|
|
4
|
-
return charCode - 87;
|
|
5
|
-
} else if (charCode > 64) {
|
|
6
|
-
return charCode - 29;
|
|
7
|
-
}
|
|
8
|
-
return charCode - 48;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function unpackBase60(string) {
|
|
12
|
-
let i = 0,
|
|
13
|
-
parts = string.split('.'),
|
|
14
|
-
[whole] = parts,
|
|
15
|
-
fractional = parts[1] || '',
|
|
16
|
-
multiplier = 1,
|
|
17
|
-
num,
|
|
18
|
-
out = 0,
|
|
19
|
-
sign = 1;
|
|
20
|
-
|
|
21
|
-
// handle negative numbers
|
|
22
|
-
if (string.charCodeAt(0) === 45) {
|
|
23
|
-
i = 1;
|
|
24
|
-
sign = -1;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// handle digits before the decimal
|
|
28
|
-
for (i; i < whole.length; i++) {
|
|
29
|
-
num = charCodeToInt(whole.charCodeAt(i));
|
|
30
|
-
out = 60 * out + num;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// handle digits after the decimal
|
|
34
|
-
for (i = 0; i < fractional.length; i++) {
|
|
35
|
-
multiplier = multiplier / 60;
|
|
36
|
-
num = charCodeToInt(fractional.charCodeAt(i));
|
|
37
|
-
out += num * multiplier;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return out * sign;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function arrayToInt(array) {
|
|
44
|
-
for (let i = 0; i < array.length; i++) {
|
|
45
|
-
array[i] = unpackBase60(array[i]);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function intToUntil(array, length) {
|
|
50
|
-
for (let i = 0; i < length; i++) {
|
|
51
|
-
array[i] = Math.round((array[i - 1] || 0) + array[i] * 60000); // minutes to milliseconds
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
array[length - 1] = Infinity;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function mapIndices(source, indices) {
|
|
58
|
-
let out = [],
|
|
59
|
-
i;
|
|
60
|
-
|
|
61
|
-
for (i = 0; i < indices.length; i++) {
|
|
62
|
-
out[i] = source[indices[i]];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function unpack(string) {
|
|
69
|
-
if (string) {
|
|
70
|
-
let data = string.split('|'),
|
|
71
|
-
offsets = data[0].split(' '),
|
|
72
|
-
indices = data[1].split(''),
|
|
73
|
-
untils = data[2].split(' ');
|
|
74
|
-
|
|
75
|
-
arrayToInt(offsets);
|
|
76
|
-
arrayToInt(indices);
|
|
77
|
-
arrayToInt(untils);
|
|
78
|
-
|
|
79
|
-
intToUntil(untils, indices.length);
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
offsets: mapIndices(offsets, indices),
|
|
83
|
-
untils
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const utcOffset = (timestamp, tzData) => {
|
|
89
|
-
let target = +timestamp,
|
|
90
|
-
i;
|
|
91
|
-
let { untils, offsets } = tzData;
|
|
92
|
-
|
|
93
|
-
for (i = 0; i < untils.length; i++) {
|
|
94
|
-
let diff = target + offsets[i] * 60000; //minutes to milliseconds
|
|
95
|
-
if (diff < untils[i]) {
|
|
96
|
-
return offsets[i];
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const getTimezoneOffset = function(timestamp, tzData) {
|
|
102
|
-
if (typeof tzData === 'object') {
|
|
103
|
-
let offset = utcOffset(timestamp, tzData);
|
|
104
|
-
if (Math.abs(offset) < 16) {
|
|
105
|
-
offset = offset / 60;
|
|
106
|
-
}
|
|
107
|
-
return -offset;
|
|
108
|
-
} else {
|
|
109
|
-
return offsetMap[tzData] || -new Date().getTimezoneOffset();
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export { unpack, getTimezoneOffset };
|