@modern-js/plugin-i18n 1.2.6 → 1.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @modern-js/plugin-i18n
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 33cebd2: chore(plugin-i18n): merge `@modern-js/i18n-cli-language-detector` to `@modern-js/plugin-i18n`
8
+
9
+ chore(plugin-i18n): 合并 `@modern-js/i18n-cli-language-detector` 包到 `@modern-js/plugin-i18n` 包作为子路径
10
+
11
+ ### Patch Changes
12
+
13
+ - @modern-js/utils@1.7.12
14
+
15
+ ## 1.2.7
16
+
17
+ ### Patch Changes
18
+
19
+ - a1198d509: feat: bump babel 7.18.0
20
+
3
21
  ## 1.2.6
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,30 @@
1
+ class I18CLILanguageDetector {
2
+ formatShellLocale(rawLC) {
3
+ if (!rawLC) {
4
+ return '';
5
+ } // Get array of available languages
6
+
7
+
8
+ const LCs = rawLC.split(':');
9
+ const LC = LCs[0] // Get `en_US` part from `en_US.UTF-8`
10
+ .split('.')[0] // Slice en_US to en
11
+ .split('_')[0] // slice en-US to en
12
+ .split('-')[0];
13
+
14
+ if (LC === 'C') {
15
+ return '';
16
+ }
17
+
18
+ return LC;
19
+ }
20
+
21
+ detect() {
22
+ var _ref, _ref2, _ref3, _process$env$LC_ALL;
23
+
24
+ const shellLocale = (_ref = (_ref2 = (_ref3 = (_process$env$LC_ALL = process.env.LC_ALL) !== null && _process$env$LC_ALL !== void 0 ? _process$env$LC_ALL : process.env.LC_MESSAGES) !== null && _ref3 !== void 0 ? _ref3 : process.env.LANG) !== null && _ref2 !== void 0 ? _ref2 : process.env.LANGUAGE) !== null && _ref !== void 0 ? _ref : Intl.DateTimeFormat().resolvedOptions().locale;
25
+ return this.formatShellLocale(shellLocale);
26
+ }
27
+
28
+ }
29
+
30
+ export { I18CLILanguageDetector };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.I18CLILanguageDetector = void 0;
7
+
8
+ class I18CLILanguageDetector {
9
+ formatShellLocale(rawLC) {
10
+ if (!rawLC) {
11
+ return '';
12
+ } // Get array of available languages
13
+
14
+
15
+ const LCs = rawLC.split(':');
16
+ const LC = LCs[0] // Get `en_US` part from `en_US.UTF-8`
17
+ .split('.')[0] // Slice en_US to en
18
+ .split('_')[0] // slice en-US to en
19
+ .split('-')[0];
20
+
21
+ if (LC === 'C') {
22
+ return '';
23
+ }
24
+
25
+ return LC;
26
+ }
27
+
28
+ detect() {
29
+ var _ref, _ref2, _ref3, _process$env$LC_ALL;
30
+
31
+ const shellLocale = (_ref = (_ref2 = (_ref3 = (_process$env$LC_ALL = process.env.LC_ALL) !== null && _process$env$LC_ALL !== void 0 ? _process$env$LC_ALL : process.env.LC_MESSAGES) !== null && _ref3 !== void 0 ? _ref3 : process.env.LANG) !== null && _ref2 !== void 0 ? _ref2 : process.env.LANGUAGE) !== null && _ref !== void 0 ? _ref : Intl.DateTimeFormat().resolvedOptions().locale;
32
+ return this.formatShellLocale(shellLocale);
33
+ }
34
+
35
+ }
36
+
37
+ exports.I18CLILanguageDetector = I18CLILanguageDetector;
@@ -0,0 +1,42 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+
4
+ var I18CLILanguageDetector = /*#__PURE__*/function () {
5
+ function I18CLILanguageDetector() {
6
+ _classCallCheck(this, I18CLILanguageDetector);
7
+ }
8
+
9
+ _createClass(I18CLILanguageDetector, [{
10
+ key: "formatShellLocale",
11
+ value: function formatShellLocale(rawLC) {
12
+ if (!rawLC) {
13
+ return '';
14
+ } // Get array of available languages
15
+
16
+
17
+ var LCs = rawLC.split(':');
18
+ var LC = LCs[0] // Get `en_US` part from `en_US.UTF-8`
19
+ .split('.')[0] // Slice en_US to en
20
+ .split('_')[0] // slice en-US to en
21
+ .split('-')[0];
22
+
23
+ if (LC === 'C') {
24
+ return '';
25
+ }
26
+
27
+ return LC;
28
+ }
29
+ }, {
30
+ key: "detect",
31
+ value: function detect() {
32
+ var _ref, _ref2, _ref3, _process$env$LC_ALL;
33
+
34
+ var shellLocale = (_ref = (_ref2 = (_ref3 = (_process$env$LC_ALL = process.env.LC_ALL) !== null && _process$env$LC_ALL !== void 0 ? _process$env$LC_ALL : process.env.LC_MESSAGES) !== null && _ref3 !== void 0 ? _ref3 : process.env.LANG) !== null && _ref2 !== void 0 ? _ref2 : process.env.LANGUAGE) !== null && _ref !== void 0 ? _ref : Intl.DateTimeFormat().resolvedOptions().locale;
35
+ return this.formatShellLocale(shellLocale);
36
+ }
37
+ }]);
38
+
39
+ return I18CLILanguageDetector;
40
+ }();
41
+
42
+ export { I18CLILanguageDetector };
@@ -29,7 +29,7 @@ declare class I18n implements TI18n {
29
29
  lang(lang: string): {
30
30
  t: (key: string, vars?: {
31
31
  [key: string]: string;
32
- } | undefined, fallbackText?: string | undefined) => string;
32
+ } | undefined, fallbackText?: string) => string;
33
33
  };
34
34
  }
35
35
 
@@ -0,0 +1,6 @@
1
+ declare class I18CLILanguageDetector {
2
+ private formatShellLocale;
3
+ detect(): string;
4
+ }
5
+
6
+ export { I18CLILanguageDetector };
package/package.json CHANGED
@@ -11,12 +11,19 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.6",
14
+ "version": "1.3.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
18
18
  "module": "./dist/js/treeshaking/index.js",
19
19
  "jsnext:modern": "./dist/js/modern/index.js",
20
+ "typesVersions": {
21
+ "*": {
22
+ "language-detector": [
23
+ "./dist/types/language-detector.d.ts"
24
+ ]
25
+ }
26
+ },
20
27
  "exports": {
21
28
  ".": {
22
29
  "node": {
@@ -24,11 +31,18 @@
24
31
  "require": "./dist/js/node/index.js"
25
32
  },
26
33
  "default": "./dist/js/treeshaking/index.js"
34
+ },
35
+ "./language-detector": {
36
+ "node": {
37
+ "import": "./dist/js/modern/language-detector.js",
38
+ "require": "./dist/js/node/language-detector.js"
39
+ },
40
+ "default": "./dist/js/treeshaking/language-detector.js"
27
41
  }
28
42
  },
29
43
  "dependencies": {
30
- "@babel/runtime": "^7",
31
- "@modern-js/utils": "^1.7.3"
44
+ "@babel/runtime": "^7.18.0",
45
+ "@modern-js/utils": "^1.7.12"
32
46
  },
33
47
  "devDependencies": {
34
48
  "@types/jest": "^27",
@@ -61,7 +75,8 @@
61
75
  "files": [
62
76
  "src/**/*",
63
77
  "tsconfig.json",
64
- "package.json"
78
+ "package.json",
79
+ "tests/**/*"
65
80
  ],
66
81
  "output": []
67
82
  }