@ttoss/i18n-cli 0.3.7 → 0.4.1
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 +35 -0
- package/dist/index.js +69 -7
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @ttoss/i18n-cli
|
|
2
|
+
|
|
3
|
+
**@ttoss/i18n-cli** is a CLI to [extract](https://formatjs.io/docs/getting-started/message-extraction) and [compile](https://formatjs.io/docs/getting-started/message-distribution) translations from your code. It implements [FormatJS Application Workflow](https://formatjs.io/docs/getting-started/application-workflow).
|
|
4
|
+
|
|
5
|
+
This package is part of the ttoss ecosystem, so it simplifies the process of extracting and compiling translations of your application and all ttoss packages that it uses. For example, if your application uses the [@ttoss/react-i18n](https://ttoss.dev/docs/modules/packages/react-i18n/), `@ttoss/i18n-cli` will extract and compile the translations of this package as well.
|
|
6
|
+
|
|
7
|
+
:::note
|
|
8
|
+
You should declare your messages as describe in the [FormatJS](https://formatjs.io/docs/getting-started/message-declaration) documentation.
|
|
9
|
+
:::
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
yarn add @ttoss/i18n-cli --dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Extract only:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
yarn ttoss-i18n --no-compile
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Extract and compile:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
yarn ttoss-i18n
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Ignoring ttoss packages:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
yarn ttoss-i18n --ignore-ttoss-packages
|
|
35
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -29,17 +30,78 @@ var path = __toESM(require("path"));
|
|
|
29
30
|
var import_cli_lib = require("@formatjs/cli-lib");
|
|
30
31
|
var DEFAULT_DIR = "i18n";
|
|
31
32
|
var EXTRACT_DIR = path.join(DEFAULT_DIR, "lang");
|
|
33
|
+
var EXTRACT_FILE = path.join(EXTRACT_DIR, "en.json");
|
|
32
34
|
var COMPILE_DIR = path.join(DEFAULT_DIR, "compiled-lang");
|
|
33
35
|
var args = process.argv.slice(2);
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
36
|
+
var getTtossExtractedTranslations = async () => {
|
|
37
|
+
const packageJsonAsString = await fs.promises.readFile(
|
|
38
|
+
path.join(process.cwd(), "package.json")
|
|
39
|
+
);
|
|
40
|
+
const packageJson = JSON.parse(packageJsonAsString.toString());
|
|
41
|
+
const ttossDependencies = Object.keys(
|
|
42
|
+
{
|
|
43
|
+
...packageJson.dependencies,
|
|
44
|
+
...packageJson.peerDependencies
|
|
45
|
+
}
|
|
46
|
+
).filter((dependency) => {
|
|
47
|
+
return dependency.startsWith("@ttoss");
|
|
48
|
+
}).filter((dependency) => {
|
|
49
|
+
return dependency !== "@ttoss/react-i18n";
|
|
50
|
+
}).filter((dependency, index, array) => {
|
|
51
|
+
return array.indexOf(dependency) === index;
|
|
37
52
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
const ttossExtractedTranslations = {};
|
|
54
|
+
for (const dependency of ttossDependencies) {
|
|
55
|
+
try {
|
|
56
|
+
const extractedTranslations = require(path.join(
|
|
57
|
+
dependency,
|
|
58
|
+
EXTRACT_FILE
|
|
59
|
+
));
|
|
60
|
+
const extractedTranslationsWithModule = Object.keys(
|
|
61
|
+
extractedTranslations
|
|
62
|
+
).reduce((acc, key) => {
|
|
63
|
+
return {
|
|
64
|
+
...acc,
|
|
65
|
+
[key]: {
|
|
66
|
+
...extractedTranslations[key],
|
|
67
|
+
module: dependency
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}, {});
|
|
71
|
+
Object.assign(
|
|
72
|
+
ttossExtractedTranslations,
|
|
73
|
+
extractedTranslationsWithModule
|
|
74
|
+
);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return ttossExtractedTranslations;
|
|
80
|
+
};
|
|
81
|
+
(async () => {
|
|
82
|
+
const extractedDataAsString = await (0, import_cli_lib.extract)(
|
|
83
|
+
glob.sync("src/**/*.{ts,tsx}", {
|
|
84
|
+
ignore: ["src/**/*.test.{ts,tsx}", "src/**/*.d.ts"]
|
|
85
|
+
}),
|
|
86
|
+
{
|
|
87
|
+
idInterpolationPattern: "[sha512:contenthash:base64:6]"
|
|
88
|
+
}
|
|
42
89
|
);
|
|
90
|
+
const ignoreTtossPackages = args.includes("--ignore-ttoss-packages");
|
|
91
|
+
const ttossExtractedTranslations = await getTtossExtractedTranslations();
|
|
92
|
+
const finalExtractedData = (() => {
|
|
93
|
+
if (ignoreTtossPackages) {
|
|
94
|
+
return extractedDataAsString;
|
|
95
|
+
}
|
|
96
|
+
const parsedExtractedData = JSON.parse(extractedDataAsString);
|
|
97
|
+
const finalExtractedData2 = {
|
|
98
|
+
...parsedExtractedData,
|
|
99
|
+
...ttossExtractedTranslations
|
|
100
|
+
};
|
|
101
|
+
return JSON.stringify(finalExtractedData2, null, 2);
|
|
102
|
+
})();
|
|
103
|
+
await fs.promises.mkdir(EXTRACT_DIR, { recursive: true });
|
|
104
|
+
await fs.promises.writeFile(EXTRACT_FILE, finalExtractedData);
|
|
43
105
|
if (args.includes("--no-compile")) {
|
|
44
106
|
return;
|
|
45
107
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/i18n-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"build": "tsup-node"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@formatjs/cli-lib": "^
|
|
21
|
-
"glob": "^
|
|
20
|
+
"@formatjs/cli-lib": "^6.0.3",
|
|
21
|
+
"glob": "^9.3.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@ttoss/config": "^1.
|
|
24
|
+
"@ttoss/config": "^1.29.0"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "2dc5f62e02ab8c901d6bb603024488b6aa3dda2b"
|
|
30
30
|
}
|