@andre1502/react-utilities 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. package/README.md +72 -17
  2. package/dist/Config/Config.js +21 -4
  3. package/dist/Config/Config.js.map +1 -1
  4. package/dist/Config/Output.js +9 -1
  5. package/dist/Config/Output.js.map +1 -1
  6. package/dist/EnvironmentEnum-BjXsfSRZ.js +9 -0
  7. package/dist/EnvironmentEnum-BjXsfSRZ.js.map +1 -0
  8. package/dist/EnvironmentEnum-UcQ6Il1O.js +9 -0
  9. package/dist/EnvironmentEnum-UcQ6Il1O.js.map +1 -0
  10. package/dist/I18n/I18n.d.ts +6 -0
  11. package/dist/I18n/I18n.js +104 -0
  12. package/dist/I18n/I18n.js.map +1 -0
  13. package/dist/I18n-CB7SyXYJ.js +3291 -0
  14. package/dist/I18n-CB7SyXYJ.js.map +1 -0
  15. package/dist/I18n-yXLN_hDO.js +3288 -0
  16. package/dist/I18n-yXLN_hDO.js.map +1 -0
  17. package/dist/config-cli.cjs +34 -5
  18. package/dist/config-cli.cjs.map +1 -1
  19. package/dist/config-cli.d.ts +2 -0
  20. package/dist/config-cli.js +8 -0
  21. package/dist/config-cli.js.map +1 -1
  22. package/dist/config-cli.mjs +32 -7
  23. package/dist/config-cli.mjs.map +1 -1
  24. package/dist/enums/EnvironmentEnum.d.ts +5 -0
  25. package/dist/enums/EnvironmentEnum.js +13 -0
  26. package/dist/enums/EnvironmentEnum.js.map +1 -0
  27. package/dist/i18n.cjs +15 -0
  28. package/dist/i18n.cjs.map +1 -0
  29. package/dist/i18n.d.ts +3 -0
  30. package/dist/i18n.js +28 -0
  31. package/dist/i18n.js.map +1 -0
  32. package/dist/i18n.mjs +4 -0
  33. package/dist/i18n.mjs.map +1 -0
  34. package/dist/index-cli.cjs +5 -0
  35. package/dist/index-cli.cjs.map +1 -1
  36. package/dist/index-cli.mjs +1 -0
  37. package/dist/index-cli.mjs.map +1 -1
  38. package/dist/index-rn.cjs +9 -0
  39. package/dist/index-rn.cjs.map +1 -1
  40. package/dist/index-rn.d.ts +1 -0
  41. package/dist/index-rn.js +11 -0
  42. package/dist/index-rn.js.map +1 -1
  43. package/dist/index-rn.mjs +3 -0
  44. package/dist/index-rn.mjs.map +1 -1
  45. package/dist/index.cjs +9 -0
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +11 -0
  49. package/dist/index.js.map +1 -1
  50. package/dist/index.mjs +3 -0
  51. package/dist/index.mjs.map +1 -1
  52. package/package.json +11 -6
  53. package/src/Config/Config.ts +22 -4
  54. package/src/Config/Output.ts +16 -7
  55. package/src/I18n/I18n.ts +117 -0
  56. package/src/config-cli.ts +2 -0
  57. package/src/enums/EnvironmentEnum.ts +5 -0
  58. package/src/i18n.ts +4 -0
  59. package/src/index-rn.ts +1 -0
  60. package/src/index.ts +1 -0
  61. package/dist/index-fmt.cjs +0 -16
  62. package/dist/index-fmt.cjs.map +0 -1
  63. package/dist/index-fmt.d.ts +0 -1
  64. package/dist/index-fmt.js +0 -17
  65. package/dist/index-fmt.js.map +0 -1
  66. package/dist/index-fmt.mjs +0 -3
  67. package/dist/index-fmt.mjs.map +0 -1
  68. package/src/index-fmt.ts +0 -1
package/dist/index-rn.js CHANGED
@@ -14,6 +14,17 @@ Object.keys(_format).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _i18n = require("./i18n");
18
+ Object.keys(_i18n).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _i18n[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _i18n[key];
25
+ }
26
+ });
27
+ });
17
28
  var _sentryRn = require("./sentry-rn");
18
29
  Object.keys(_sentryRn).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
@@ -1 +1 @@
1
- {"version":3,"file":"index-rn.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_sentryRn"],"sources":["../src/index-rn.ts"],"sourcesContent":["export * from './format';\nexport * from './sentry-rn';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,SAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,SAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,SAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,SAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index-rn.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_i18n","_sentryRn"],"sources":["../src/index-rn.ts"],"sourcesContent":["export * from './format';\nexport * from './i18n';\nexport * from './sentry-rn';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,KAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,KAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,KAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,KAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,SAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,SAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,SAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAE,SAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
package/dist/index-rn.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  export { CurrencySymbolEnum, formatAccountNumber, formatNumber, getCurrencySymbol, parseFormatNumber } from './format.mjs';
2
+ export { E as EnvironmentEnum } from './EnvironmentEnum-UcQ6Il1O.js';
3
+ export { g as getV, i as initI18n } from './I18n-yXLN_hDO.js';
2
4
  export { i as initSentry, r as recordAdditionalSentryHttp } from './ReactNative-mNnws-b5.js';
3
5
  import '@formatjs/intl-numberformat';
6
+ import 'cross-fetch';
4
7
  import '@sentry/react-native';
5
8
  import './Utils-Cq948gfa.js';
6
9
  //# sourceMappingURL=index-rn.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-rn.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index-rn.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/dist/index.cjs CHANGED
@@ -1,8 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var format = require('./format.cjs');
4
+ var EnvironmentEnum = require('./EnvironmentEnum-BjXsfSRZ.js');
5
+ var I18n = require('./I18n-CB7SyXYJ.js');
4
6
  var React = require('./React-qUl0CBmE.js');
5
7
  require('@formatjs/intl-numberformat');
8
+ require('cross-fetch');
6
9
  require('@sentry/react');
7
10
  require('./Utils-Dilye04y.js');
8
11
 
@@ -16,6 +19,12 @@ exports.formatAccountNumber = format.formatAccountNumber;
16
19
  exports.formatNumber = format.formatNumber;
17
20
  exports.getCurrencySymbol = format.getCurrencySymbol;
18
21
  exports.parseFormatNumber = format.parseFormatNumber;
22
+ Object.defineProperty(exports, "EnvironmentEnum", {
23
+ enumerable: true,
24
+ get: function () { return EnvironmentEnum.EnvironmentEnum; }
25
+ });
26
+ exports.getV = I18n.getV;
27
+ exports.initI18n = I18n.initI18n;
19
28
  exports.initSentry = React.initSentry;
20
29
  exports.recordAdditionalSentryHttp = React.recordAdditionalSentryHttp;
21
30
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './format';
2
+ export * from './i18n';
2
3
  export * from './sentry';
package/dist/index.js CHANGED
@@ -14,6 +14,17 @@ Object.keys(_format).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _i18n = require("./i18n");
18
+ Object.keys(_i18n).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _i18n[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _i18n[key];
25
+ }
26
+ });
27
+ });
17
28
  var _sentry = require("./sentry");
18
29
  Object.keys(_sentry).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_sentry"],"sources":["../src/index.ts"],"sourcesContent":["export * from './format';\nexport * from './sentry';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,OAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,OAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,OAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,OAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_i18n","_sentry"],"sources":["../src/index.ts"],"sourcesContent":["export * from './format';\nexport * from './i18n';\nexport * from './sentry';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,KAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,KAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,KAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,KAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,OAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,OAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,OAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAE,OAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
package/dist/index.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  export { CurrencySymbolEnum, formatAccountNumber, formatNumber, getCurrencySymbol, parseFormatNumber } from './format.mjs';
2
+ export { E as EnvironmentEnum } from './EnvironmentEnum-UcQ6Il1O.js';
3
+ export { g as getV, i as initI18n } from './I18n-yXLN_hDO.js';
2
4
  export { i as initSentry, r as recordAdditionalSentryHttp } from './React-BaJ1KfGF.js';
3
5
  import '@formatjs/intl-numberformat';
6
+ import 'cross-fetch';
4
7
  import '@sentry/react';
5
8
  import './Utils-Cq948gfa.js';
6
9
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andre1502/react-utilities",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "module to combine common functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,11 +15,6 @@
15
15
  "require": "./dist/index.cjs",
16
16
  "import": "./dist/index.mjs"
17
17
  },
18
- "./fmt": {
19
- "types": "./dist/index-fmt.d.ts",
20
- "require": "./dist/index-fmt.cjs",
21
- "import": "./dist/index-fmt.mjs"
22
- },
23
18
  "./react-native": {
24
19
  "types": "./dist/index-rn.d.ts",
25
20
  "require": "./dist/index-rn.cjs",
@@ -35,6 +30,11 @@
35
30
  "require": "./dist/format.cjs",
36
31
  "import": "./dist/format.mjs"
37
32
  },
33
+ "./i18n": {
34
+ "types": "./dist/i18n.d.ts",
35
+ "require": "./dist/i18n.cjs",
36
+ "import": "./dist/i18n.mjs"
37
+ },
38
38
  "./sentry": {
39
39
  "types": "./dist/sentry.d.ts",
40
40
  "require": "./dist/sentry.cjs",
@@ -89,6 +89,11 @@
89
89
  "@types/lodash": "^4.17.7",
90
90
  "google-auth-library": "^9.11.0",
91
91
  "googleapis": "^140.0.1",
92
+ "i18next": "^23.16.5",
93
+ "i18next-chained-backend": "^4.6.2",
94
+ "i18next-http-backend": "^2.6.2",
95
+ "i18next-localstorage-backend": "^4.2.0",
96
+ "i18next-resources-to-backend": "^1.2.1",
92
97
  "lodash": "^4.17.21",
93
98
  "sitemap": "^8.0.0"
94
99
  },
@@ -1,4 +1,5 @@
1
1
  import * as lodash from 'lodash';
2
+ import { EnvironmentEnum } from '../enums/EnvironmentEnum';
2
3
  import { OutputMap } from '../interfaces/Config/OutputMap';
3
4
  import { OutputOptions } from '../interfaces/Config/OutputOptions';
4
5
  import { outputToFile } from './Output';
@@ -102,7 +103,24 @@ const exportConfig = (data: OutputMap, options: OutputOptions): void => {
102
103
  params: data,
103
104
  };
104
105
 
105
- const content = `module.exports = ${JSON.stringify(config, null, 2)}`;
106
+ let content = '';
107
+
108
+ switch (options.exportAs) {
109
+ case 'ts':
110
+ content = 'export default ' + JSON.stringify(config, null, 2);
111
+ options.filename = `${options.filename}.ts`;
112
+ break;
113
+ case 'json':
114
+ content = JSON.stringify(config, null, 2);
115
+ options.filename = `${options.filename}.json`;
116
+ break;
117
+ case 'js':
118
+ content = `module.exports = ${JSON.stringify(config, null, 2)}`;
119
+ options.filename = `${options.filename}.js`;
120
+ break;
121
+ default:
122
+ throw new Error(`exportAs ${options.exportAs} not supported.`);
123
+ }
106
124
 
107
125
  outputToFile(content, options);
108
126
  };
@@ -120,17 +138,17 @@ const envMap = (env: string): string => {
120
138
  case 'dev':
121
139
  case 'develop':
122
140
  case 'development':
123
- result = 'dev';
141
+ result = EnvironmentEnum.DEV;
124
142
  break;
125
143
  case 'stg':
126
144
  case 'stag':
127
145
  case 'staging':
128
- result = 'staging';
146
+ result = EnvironmentEnum.STAGING;
129
147
  break;
130
148
  case 'prd':
131
149
  case 'prod':
132
150
  case 'production':
133
- result = 'production';
151
+ result = EnvironmentEnum.PRODUCTION;
134
152
  break;
135
153
  default:
136
154
  throw new Error(`env ${env} not supported.`);
@@ -1,4 +1,4 @@
1
- import { writeFile } from 'fs';
1
+ import { existsSync, mkdirSync, writeFile } from 'fs';
2
2
  import { OutputOptions } from '../interfaces/Config/OutputOptions';
3
3
 
4
4
  /**
@@ -17,13 +17,22 @@ const outputToFile = (content: string, options: OutputOptions): void => {
17
17
 
18
18
  const filePath = `${options.folder}/${filename}`;
19
19
 
20
- writeFile(filePath, content, 'utf8', function (err) {
21
- if (err) {
22
- throw err;
23
- }
20
+ if (!existsSync(options.folder)) {
21
+ mkdirSync(options.folder, { recursive: true });
22
+ }
23
+
24
+ writeFile(
25
+ filePath,
26
+ content,
27
+ { encoding: 'utf-8', flag: 'w' },
28
+ function (err) {
29
+ if (err) {
30
+ throw err;
31
+ }
24
32
 
25
- console.log(filePath, content);
26
- });
33
+ console.log(filePath, content);
34
+ },
35
+ );
27
36
  };
28
37
 
29
38
  export { outputToFile };
@@ -0,0 +1,117 @@
1
+ import i18next, { InitOptions, ThirdPartyModule } from 'i18next';
2
+ import ChainedBackend from 'i18next-chained-backend';
3
+ import HttpBackend from 'i18next-http-backend';
4
+ import LocalStorageBackend from 'i18next-localstorage-backend';
5
+ import ResourcesToBackend from 'i18next-resources-to-backend';
6
+
7
+ const getV = (divider: number): number => {
8
+ return Math.floor(Date.now() / divider);
9
+ };
10
+
11
+ const initI18n = (
12
+ initReactI18next: ThirdPartyModule,
13
+ lang: string,
14
+ fallbackLang: string,
15
+ langCacheExpiredTimeMs: number,
16
+ resources: { [key: string]: any },
17
+ version: string,
18
+ withLocalstorageBackend?: boolean,
19
+ cdnUrl?: string,
20
+ debug?: boolean,
21
+ ) => {
22
+ let backends: Array<any> = [];
23
+ let backendOptions: Array<any> = [];
24
+ const langs = Object.keys(resources);
25
+
26
+ // https://www.i18next.com/how-to/backend-fallback
27
+ if (withLocalstorageBackend) {
28
+ const versions: { [key: string]: string } = {};
29
+
30
+ langs.forEach((value) => Object.assign(versions, { [value]: version }));
31
+
32
+ backends.push(LocalStorageBackend);
33
+ backendOptions.push({
34
+ // prefix for stored languages
35
+ prefix: `i18next_res_`,
36
+
37
+ // expiration
38
+ expirationTime: langCacheExpiredTimeMs,
39
+
40
+ // language versions
41
+ versions: versions,
42
+ });
43
+ }
44
+
45
+ if (cdnUrl) {
46
+ backends.push(HttpBackend);
47
+ backendOptions.push({
48
+ // load resources from url path
49
+ loadPath: `${cdnUrl}/locales/{{lng}}.json`,
50
+ // adds parameters to resource URL. 'example.com' -> 'example.com?v=1.3.5'
51
+ queryStringParams: {
52
+ v: `${version}.${getV(langCacheExpiredTimeMs)}`,
53
+ },
54
+
55
+ reloadInterval: langCacheExpiredTimeMs, // can be used to reload resources in a specific interval (milliseconds) (useful in server environments)
56
+ });
57
+ }
58
+
59
+ backends.push(ResourcesToBackend(resources));
60
+
61
+ // https://www.i18next.com/misc/creating-own-plugins#languagedetector
62
+ const languageDetector: any = {
63
+ type: 'languageDetector',
64
+ name: 'customDetector',
65
+ async: false,
66
+ init: () => {
67
+ /* use services and options */
68
+ },
69
+ detect: (callback: any) => {
70
+ return lang;
71
+ },
72
+ };
73
+
74
+ const config: InitOptions = {
75
+ debug: debug ?? false,
76
+ compatibilityJSON: 'v4',
77
+ ns: ['translation'],
78
+ defaultNS: 'translation',
79
+ lng: lang,
80
+ fallbackLng: fallbackLang,
81
+ load: 'currentOnly',
82
+ keySeparator: false,
83
+ nonExplicitSupportedLngs: true,
84
+ backend: {
85
+ backends: backends,
86
+ backendOptions: backendOptions,
87
+ cacheHitMode: 'refreshAndUpdateStore',
88
+ reloadInterval: langCacheExpiredTimeMs,
89
+ refreshExpirationTime: langCacheExpiredTimeMs, // only after determined time it should trigger a refresh if necessary
90
+ },
91
+ react: {
92
+ bindI18nStore: 'added', // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated
93
+ },
94
+ interpolation: {
95
+ escapeValue: false, // react already safes from xss
96
+ },
97
+ };
98
+
99
+ if (!i18next.isInitialized) {
100
+ i18next
101
+ .use(ChainedBackend)
102
+ .use(languageDetector)
103
+ .use(initReactI18next) // passes i18n down to react-i18next
104
+ .init(config, (ex, t) => {
105
+ if (ex) {
106
+ console.error(`Error when i18n init`, ex);
107
+ return;
108
+ }
109
+
110
+ setInterval(() => {
111
+ i18next.reloadResources();
112
+ }, langCacheExpiredTimeMs);
113
+ });
114
+ }
115
+ };
116
+
117
+ export { getV, initI18n };
package/src/config-cli.ts CHANGED
@@ -3,6 +3,7 @@ import { JSONClient } from 'google-auth-library/build/src/auth/googleauth';
3
3
  import { exportConfig, processConfig } from './Config/Config';
4
4
  import { authorizeServiceAccount, fetchGoogleSheet } from './Config/GoogleAuth';
5
5
  import { exportLocales, processLocales } from './Config/Locales';
6
+ import { EnvironmentEnum } from './enums/EnvironmentEnum';
6
7
  import { ConfigOptions } from './interfaces/Config/ConfigOptions';
7
8
 
8
9
  export { transformConfig } from './Config/Config';
@@ -10,6 +11,7 @@ export { transformSitemap } from './Config/Sitemap';
10
11
  export * from './interfaces/Config/ConfigOptions';
11
12
  export * from './interfaces/Config/OutputOptions';
12
13
  export type { ExportAs, FormatAs } from './types/Config/OptionType';
14
+ export { EnvironmentEnum };
13
15
 
14
16
  /**
15
17
  * Private function to fetch locales
@@ -0,0 +1,5 @@
1
+ export enum EnvironmentEnum {
2
+ DEV = 'dev',
3
+ STAGING = 'staging',
4
+ PRODUCTION = 'production',
5
+ }
package/src/i18n.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { EnvironmentEnum } from './enums/EnvironmentEnum';
2
+
3
+ export * from './I18n/I18n';
4
+ export { EnvironmentEnum };
package/src/index-rn.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './format';
2
+ export * from './i18n';
2
3
  export * from './sentry-rn';
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './format';
2
+ export * from './i18n';
2
3
  export * from './sentry';
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- var format = require('./format.cjs');
4
- require('@formatjs/intl-numberformat');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "CurrencySymbolEnum", {
9
- enumerable: true,
10
- get: function () { return format.CurrencySymbolEnum; }
11
- });
12
- exports.formatAccountNumber = format.formatAccountNumber;
13
- exports.formatNumber = format.formatNumber;
14
- exports.getCurrencySymbol = format.getCurrencySymbol;
15
- exports.parseFormatNumber = format.parseFormatNumber;
16
- //# sourceMappingURL=index-fmt.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-fmt.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- export * from './format';
package/dist/index-fmt.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _format = require("./format");
7
- Object.keys(_format).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _format[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _format[key];
14
- }
15
- });
16
- });
17
- //# sourceMappingURL=index-fmt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-fmt.js","names":["_format","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../src/index-fmt.ts"],"sourcesContent":["export * from './format';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- export { CurrencySymbolEnum, formatAccountNumber, formatNumber, getCurrencySymbol, parseFormatNumber } from './format.mjs';
2
- import '@formatjs/intl-numberformat';
3
- //# sourceMappingURL=index-fmt.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-fmt.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
package/src/index-fmt.ts DELETED
@@ -1 +0,0 @@
1
- export * from './format';