@zohodesk/i18n 1.0.0-beta.4 → 1.0.0-beta.41-murphy

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 (70) hide show
  1. package/README.md +130 -4
  2. package/docs/murphy/01-MURPHY_OVERVIEW.md +148 -0
  3. package/docs/murphy/02-MURPHY_ARCHITECTURE.md +283 -0
  4. package/docs/murphy/03-MURPHY_BACKEND_CONFIG.md +337 -0
  5. package/docs/murphy/04-MURPHY_FRONTEND_INIT.md +437 -0
  6. package/docs/murphy/05-MURPHY_DESK_CLIENT_USAGE.md +467 -0
  7. package/docs/murphy/06-MURPHY_I18N_INTEGRATION.md +402 -0
  8. package/docs/murphy/07-MURPHY_WHY_I18N_APPROACH.md +391 -0
  9. package/es/I18NContext.js +1 -2
  10. package/es/components/DateTimeDiffFormat.js +185 -209
  11. package/es/components/FormatText.js +7 -27
  12. package/es/components/HOCI18N.js +35 -58
  13. package/es/components/I18N.js +48 -74
  14. package/es/components/I18NProvider.js +59 -93
  15. package/es/components/PluralFormat.js +28 -51
  16. package/es/components/UserTimeDiffFormat.js +66 -81
  17. package/es/components/__tests__/DateTimeDiffFormat.spec.js +810 -663
  18. package/es/components/__tests__/FormatText.spec.js +22 -19
  19. package/es/components/__tests__/HOCI18N.spec.js +19 -25
  20. package/es/components/__tests__/I18N.spec.js +23 -21
  21. package/es/components/__tests__/I18NProvider.spec.js +38 -47
  22. package/es/components/__tests__/PluralFormat.spec.js +23 -20
  23. package/es/components/__tests__/UserTimeDiffFormat.spec.js +1259 -1110
  24. package/es/index.js +13 -15
  25. package/es/utils/__tests__/jsxTranslations.spec.js +170 -0
  26. package/es/utils/errorReporter.js +41 -0
  27. package/es/utils/index.js +543 -0
  28. package/es/utils/jsxTranslations.js +185 -0
  29. package/lib/I18NContext.js +5 -10
  30. package/lib/components/DateTimeDiffFormat.js +131 -146
  31. package/lib/components/FormatText.js +29 -42
  32. package/lib/components/HOCI18N.js +34 -45
  33. package/lib/components/I18N.js +46 -57
  34. package/lib/components/I18NProvider.js +72 -95
  35. package/lib/components/PluralFormat.js +39 -55
  36. package/lib/components/UserTimeDiffFormat.js +76 -84
  37. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +751 -635
  38. package/lib/components/__tests__/FormatText.spec.js +21 -30
  39. package/lib/components/__tests__/HOCI18N.spec.js +22 -41
  40. package/lib/components/__tests__/I18N.spec.js +20 -33
  41. package/lib/components/__tests__/I18NProvider.spec.js +40 -63
  42. package/lib/components/__tests__/PluralFormat.spec.js +23 -35
  43. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1195 -1046
  44. package/lib/index.js +83 -104
  45. package/lib/utils/__tests__/jsxTranslations.spec.js +172 -0
  46. package/lib/utils/errorReporter.js +49 -0
  47. package/lib/utils/index.js +583 -0
  48. package/lib/utils/jsxTranslations.js +216 -0
  49. package/package.json +4 -3
  50. package/src/components/DateTimeDiffFormat.js +84 -55
  51. package/src/components/I18N.js +2 -0
  52. package/src/components/I18NProvider.js +44 -33
  53. package/src/components/UserTimeDiffFormat.js +22 -18
  54. package/src/index.js +12 -9
  55. package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
  56. package/src/utils/errorReporter.js +48 -0
  57. package/src/utils/index.js +644 -0
  58. package/src/utils/jsxTranslations.js +199 -0
  59. package/es/components/NewDateFormat.js +0 -50
  60. package/es/offset.js +0 -629
  61. package/es/timezones.js +0 -118
  62. package/es/utils.js +0 -621
  63. package/lib/components/NewDateFormat.js +0 -68
  64. package/lib/offset.js +0 -634
  65. package/lib/timezones.js +0 -129
  66. package/lib/utils.js +0 -651
  67. package/src/components/NewDateFormat.js +0 -60
  68. package/src/offset.js +0 -629
  69. package/src/timezones.js +0 -113
  70. 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 };