@lingual/i18n-check 0.7.0 → 0.7.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 +27 -4
- package/dist/bin/index.js +4 -4
- package/dist/errorReporters.d.ts +2 -1
- package/dist/errorReporters.js +9 -1
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -114,28 +114,51 @@ yarn i18n:check --locales translations/i18NextMessageExamples -s en-US -f i18nex
|
|
|
114
114
|
|
|
115
115
|
### --only, -o
|
|
116
116
|
|
|
117
|
-
By default i18n-check will perform a validation against any **missing** and/or **invalid** keys. There are situations where only a specific check should run. By using the `-o` or `--only` option you can specify a specific check to run.
|
|
117
|
+
By default i18n-check will perform a validation against any **missing** and/or **invalid** keys, additionally **unused** and **undefined** checks if the `--unused` option is set. There are situations where only a specific check should run. By using the `-o` or `--only` option you can specify a specific check to run.
|
|
118
118
|
|
|
119
|
-
The available options are
|
|
119
|
+
The available options are:
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
- `missingKeys`: will check against any missing keys in the target files.
|
|
122
|
+
- `invalidKeys`: will check for invalid keys, where the target translations has a different type then the one defined in the source file.
|
|
123
|
+
- `unused`: will check for any locale keys that do not exist in the codebase.
|
|
124
|
+
- `undefined`: will check for any keys that exist in the codebase but not in the source locale files.
|
|
125
|
+
|
|
126
|
+
Check for missing keys only:
|
|
122
127
|
|
|
123
128
|
```bash
|
|
124
129
|
yarn i18n:check --locales translations/messageExamples -s en-US -o missingKeys
|
|
125
130
|
```
|
|
126
131
|
|
|
127
|
-
Check for invalid keys:
|
|
132
|
+
Check for invalid keys only:
|
|
128
133
|
|
|
129
134
|
```bash
|
|
130
135
|
yarn i18n:check --locales translations/messageExamples -s en-US -o invalidKeys
|
|
131
136
|
```
|
|
132
137
|
|
|
138
|
+
Check for unused key only:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
yarn i18n:check --locales translations/messageExamples -s en-US -o unused
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Check for undefined keys only:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
yarn i18n:check --locales translations/messageExamples -s en-US -o undefined
|
|
148
|
+
```
|
|
149
|
+
|
|
133
150
|
Check for missing and invalid keys (which is the default):
|
|
134
151
|
|
|
135
152
|
```bash
|
|
136
153
|
yarn i18n:check --locales translations/messageExamples -s en-US -o missingKeys invalidKeys
|
|
137
154
|
```
|
|
138
155
|
|
|
156
|
+
Check for unused and undefined keys only:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
yarn i18n:check --locales translations/messageExamples -s en-US -o unused undefined
|
|
160
|
+
```
|
|
161
|
+
|
|
139
162
|
### --unused, -u
|
|
140
163
|
|
|
141
164
|
This feature is currently only supported for `react-intl` and `i18next` as well as `next-intl` (experimental at the moment) based React applications and is useful when you need to know which keys exist in your translation files but not in your codebase. Additionally an inverse check is run to find any keys that exist in the codebase but not in the translation files.
|
package/dist/bin/index.js
CHANGED
|
@@ -20,7 +20,7 @@ commander_1.program
|
|
|
20
20
|
.option("-s, --source <locale>", "the source locale to validate against")
|
|
21
21
|
.option("-f, --format <type>", "define the specific format: i18next, react-intl or next-intl")
|
|
22
22
|
.option("-c, --check <checks...>", "this option is deprecated - use -o or --only instead")
|
|
23
|
-
.option("-o, --only <only...>", "define the specific checks you want to run:
|
|
23
|
+
.option("-o, --only <only...>", "define the specific checks you want to run: invalidKeys, missingKeys, unused, undefined. By default the check will validate against missing and invalid keys, i.e. --only invalidKeys,missingKeys")
|
|
24
24
|
.option("-r, --reporter <style>", "define the reporting style: standard or summary")
|
|
25
25
|
.option("-e, --exclude <exclude...>", "define the file(s) and/or folders(s) that should be excluded from the check")
|
|
26
26
|
.option("-u, --unused <path>", "define the source path to find all unused and undefined keys")
|
|
@@ -32,10 +32,10 @@ const getCheckOptions = () => {
|
|
|
32
32
|
console.log(chalk_1.default.yellow("The --check option has been deprecated, use the --only option instead."));
|
|
33
33
|
}
|
|
34
34
|
if (!checkOption) {
|
|
35
|
-
return
|
|
35
|
+
return errorReporters_1.CheckOptions;
|
|
36
36
|
}
|
|
37
|
-
const checks = checkOption.filter((check) =>
|
|
38
|
-
return checks.length > 0 ? checks :
|
|
37
|
+
const checks = checkOption.filter((check) => errorReporters_1.CheckOptions.includes(check.trim()));
|
|
38
|
+
return checks.length > 0 ? checks : errorReporters_1.CheckOptions;
|
|
39
39
|
};
|
|
40
40
|
const isSource = (fileInfo, srcPath) => {
|
|
41
41
|
return (fileInfo.path.some((path) => path.toLowerCase() === srcPath.toLowerCase()) || fileInfo.name.toLowerCase().slice(0, -5) === srcPath.toLowerCase());
|
package/dist/errorReporters.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const CheckOptions: string[];
|
|
2
|
+
export type Context = (typeof CheckOptions)[number];
|
|
2
3
|
export declare const contextMapping: Record<Context, string>;
|
|
3
4
|
export declare const standardReporter: (result: {
|
|
4
5
|
file: string;
|
package/dist/errorReporters.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createTable = exports.summaryReporter = exports.standardReporter = exports.contextMapping = void 0;
|
|
3
|
+
exports.createTable = exports.summaryReporter = exports.standardReporter = exports.contextMapping = exports.CheckOptions = void 0;
|
|
4
4
|
const console_1 = require("console");
|
|
5
5
|
const stream_1 = require("stream");
|
|
6
|
+
exports.CheckOptions = [
|
|
7
|
+
"invalidKeys",
|
|
8
|
+
"missingKeys",
|
|
9
|
+
"unused",
|
|
10
|
+
"undefined",
|
|
11
|
+
];
|
|
6
12
|
exports.contextMapping = {
|
|
7
13
|
invalidKeys: "invalid",
|
|
8
14
|
missingKeys: "missing",
|
|
15
|
+
unused: "unused",
|
|
16
|
+
undefined: "undefined",
|
|
9
17
|
};
|
|
10
18
|
const standardReporter = (result) => {
|
|
11
19
|
return (0, exports.createTable)(result.map(({ file, key }) => ({ file, key })));
|
package/dist/index.js
CHANGED
|
@@ -48,10 +48,14 @@ const checkTranslations = (source, targets, options = { format: "icu", checks: [
|
|
|
48
48
|
exports.checkTranslations = checkTranslations;
|
|
49
49
|
const checkUnusedKeys = async (translationFiles, filesToParse, options = {
|
|
50
50
|
format: "react-intl",
|
|
51
|
+
checks: [],
|
|
51
52
|
}, componentFunctions = []) => {
|
|
52
53
|
if (!options.format || !ParseFormats.includes(options.format)) {
|
|
53
54
|
return undefined;
|
|
54
55
|
}
|
|
56
|
+
if (!options.checks || !options.checks.includes("unused")) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
55
59
|
if (options.format === "react-intl") {
|
|
56
60
|
return findUnusedReactIntlTranslations(translationFiles, filesToParse);
|
|
57
61
|
}
|
|
@@ -119,10 +123,14 @@ const findUnusedNextIntlTranslations = async (translationFiles, filesToParse) =>
|
|
|
119
123
|
};
|
|
120
124
|
const checkUndefinedKeys = async (source, filesToParse, options = {
|
|
121
125
|
format: "react-intl",
|
|
126
|
+
checks: [],
|
|
122
127
|
}, componentFunctions = []) => {
|
|
123
128
|
if (!options.format || !ParseFormats.includes(options.format)) {
|
|
124
129
|
return undefined;
|
|
125
130
|
}
|
|
131
|
+
if (!options.checks || !options.checks.includes("undefined")) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
126
134
|
if (options.format === "react-intl") {
|
|
127
135
|
return findUndefinedReactIntlKeys(source, filesToParse);
|
|
128
136
|
}
|