@ttoss/i18n-cli 0.7.3 → 0.7.4
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 +24 -9
- package/dist/index.js +11 -6
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -21,19 +21,24 @@ Add this script to your `package.json`
|
|
|
21
21
|
```json
|
|
22
22
|
{
|
|
23
23
|
"scripts": {
|
|
24
|
-
"i18n": "ttoss-i18n"
|
|
25
|
-
"i18n:extract": "ttoss-i18n --no-compile",
|
|
26
|
-
"i18n:ignore-ttoss-pkg": "ttoss-i18n --ignore-ttoss-packages"
|
|
24
|
+
"i18n": "ttoss-i18n"
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
```
|
|
30
28
|
|
|
29
|
+
Add to your `.gitignore`:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
i18n/compiled/
|
|
33
|
+
i18n/missing/
|
|
34
|
+
```
|
|
35
|
+
|
|
31
36
|
## Usage
|
|
32
37
|
|
|
33
38
|
### Extract only:
|
|
34
39
|
|
|
35
40
|
```sh
|
|
36
|
-
pnpm
|
|
41
|
+
pnpm i18n --no-compile # ttoss-i18n --no-compile
|
|
37
42
|
```
|
|
38
43
|
|
|
39
44
|
This command extracts translations from your code but doesn't compile them. And created a new path (`i18n/lang/en.json`) if doesn't exists with extracted translations. As followed below:
|
|
@@ -64,20 +69,28 @@ To translate your text, you only need to duplicate the file `i18n/lang/en.json`
|
|
|
64
69
|
}
|
|
65
70
|
```
|
|
66
71
|
|
|
72
|
+
`en` is the default language, so you don't need to create a file for it. But you need to create a file for each language you want to translate.
|
|
73
|
+
|
|
67
74
|
### Extract and compile:
|
|
68
75
|
|
|
69
76
|
```sh
|
|
70
|
-
pnpm
|
|
77
|
+
pnpm i18n # ttoss-i18n
|
|
71
78
|
```
|
|
72
79
|
|
|
73
|
-
This command extracts translations from your code and compiles them into a usable format. And create a new path (`i18n/compiled/
|
|
80
|
+
This command extracts translations from your code and compiles them into a usable format. And create a new path (`i18n/compiled/LANG.json` and `i18n/missing/LANG.json`) if doesn't exists with compiled translations based in all of the files on path `i18n/lang`. As followed below:
|
|
74
81
|
|
|
75
82
|
- 📂 i18n
|
|
76
83
|
- 📂 compiled
|
|
77
84
|
- 📄 en.json
|
|
78
85
|
- 📄 pt-BR.json
|
|
86
|
+
- 📂 lang
|
|
87
|
+
- 📄 en.json
|
|
88
|
+
- 📄 pt-BR.json
|
|
89
|
+
- 📂 missing
|
|
90
|
+
- 📄 en.json
|
|
91
|
+
- 📄 pt-BR.json
|
|
79
92
|
|
|
80
|
-
#### en.json
|
|
93
|
+
#### i18n/compiled/en.json
|
|
81
94
|
|
|
82
95
|
```json
|
|
83
96
|
// i18n/compiled/en.json
|
|
@@ -91,7 +104,7 @@ This command extracts translations from your code and compiles them into a usabl
|
|
|
91
104
|
}
|
|
92
105
|
```
|
|
93
106
|
|
|
94
|
-
#### pt-BR.json
|
|
107
|
+
#### i18n/compiled/pt-BR.json
|
|
95
108
|
|
|
96
109
|
```json
|
|
97
110
|
// i18n/compiled/pt-BR.json
|
|
@@ -105,10 +118,12 @@ This command extracts translations from your code and compiles them into a usabl
|
|
|
105
118
|
}
|
|
106
119
|
```
|
|
107
120
|
|
|
121
|
+
The `i18n/missing` folder contains all the translations that are missing in the `i18n/lang/LANG.json` file, compared with `i18n/lang/en.json`. This folder is useful to know which translations are missing in your application.
|
|
122
|
+
|
|
108
123
|
### Ignoring ttoss packages:
|
|
109
124
|
|
|
110
125
|
```sh
|
|
111
|
-
pnpm
|
|
126
|
+
pnpm i18n --ignore-ttoss-packages # ttoss-i18n --ignore-ttoss-packages
|
|
112
127
|
```
|
|
113
128
|
|
|
114
129
|
This command extracts and compiles translations, ignoring translations from all ttoss packages, if you have them installed in your project.
|
package/dist/index.js
CHANGED
|
@@ -31,12 +31,13 @@ var fs = __toESM(require("fs"));
|
|
|
31
31
|
var glob = __toESM(require("glob"));
|
|
32
32
|
var path = __toESM(require("path"));
|
|
33
33
|
var import_cli_lib = require("@formatjs/cli-lib");
|
|
34
|
+
var import_minimist = __toESM(require("minimist"));
|
|
34
35
|
var DEFAULT_DIR = "i18n";
|
|
35
36
|
var EXTRACT_DIR = path.join(DEFAULT_DIR, "lang");
|
|
36
37
|
var EXTRACT_FILE = path.join(EXTRACT_DIR, "en.json");
|
|
37
38
|
var COMPILE_DIR = path.join(DEFAULT_DIR, "compiled");
|
|
38
39
|
var MISSING_DIR = path.join(DEFAULT_DIR, "missing");
|
|
39
|
-
var
|
|
40
|
+
var argv = (0, import_minimist.default)(process.argv.slice(2));
|
|
40
41
|
var getTtossExtractedTranslations = async () => {
|
|
41
42
|
const packageJsonAsString = await fs.promises.readFile(path.join(process.cwd(), "package.json"));
|
|
42
43
|
const packageJson = JSON.parse(packageJsonAsString.toString());
|
|
@@ -91,12 +92,14 @@ var getTtossExtractedTranslations = async () => {
|
|
|
91
92
|
return ttossExtractedTranslations;
|
|
92
93
|
};
|
|
93
94
|
(async () => {
|
|
94
|
-
const
|
|
95
|
-
|
|
95
|
+
const pattern = argv.pattern || "src/**/*.{ts,tsx}";
|
|
96
|
+
const ignore = argv.ignore || ["src/**/*.test.{ts,tsx}", "src/**/*.d.ts"];
|
|
97
|
+
const extractedDataAsString = await (0, import_cli_lib.extract)(glob.sync(pattern, {
|
|
98
|
+
ignore
|
|
96
99
|
}), {
|
|
97
100
|
idInterpolationPattern: "[sha512:contenthash:base64:6]"
|
|
98
101
|
});
|
|
99
|
-
const ignoreTtossPackages =
|
|
102
|
+
const ignoreTtossPackages = argv["ignore-ttoss-packages"];
|
|
100
103
|
const ttossExtractedTranslations = await getTtossExtractedTranslations();
|
|
101
104
|
const finalExtractedData = (() => {
|
|
102
105
|
if (ignoreTtossPackages) {
|
|
@@ -113,7 +116,7 @@ var getTtossExtractedTranslations = async () => {
|
|
|
113
116
|
recursive: true
|
|
114
117
|
});
|
|
115
118
|
await fs.promises.writeFile(EXTRACT_FILE, finalExtractedData);
|
|
116
|
-
if (
|
|
119
|
+
if (argv["no-compile"]) {
|
|
117
120
|
return;
|
|
118
121
|
}
|
|
119
122
|
const translations = glob.sync(EXTRACT_DIR + "/*.json");
|
|
@@ -146,7 +149,9 @@ var getTtossExtractedTranslations = async () => {
|
|
|
146
149
|
acc[key] = extractedTranslations[key];
|
|
147
150
|
}
|
|
148
151
|
return acc;
|
|
149
|
-
},
|
|
152
|
+
},
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
+
{});
|
|
150
155
|
if (filename) {
|
|
151
156
|
await fs.promises.writeFile(path.join(MISSING_DIR, filename), JSON.stringify(missingTranslations, null, 2));
|
|
152
157
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/i18n-cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"author": "ttoss",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Pedro Arantes <arantespp@gmail.com> (https://arantespp.com)"
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@formatjs/cli-lib": "^6.3.3",
|
|
22
|
-
"glob": "^10.3.10"
|
|
22
|
+
"glob": "^10.3.10",
|
|
23
|
+
"minimist": "^1.2.8"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"tsup": "^8.0.1",
|