@lingual/i18n-check 0.8.2 → 0.8.3
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 +10 -18
- package/dist/bin/index.js +58 -57
- package/dist/bin/index.test.js +289 -289
- package/dist/errorReporters.d.ts +1 -1
- package/dist/errorReporters.js +21 -21
- package/dist/errorReporters.test.js +39 -39
- package/dist/index.d.ts +3 -3
- package/dist/index.js +59 -42
- package/dist/utils/findInvalidTranslations.d.ts +2 -2
- package/dist/utils/findInvalidTranslations.js +20 -19
- package/dist/utils/findInvalidTranslations.test.js +30 -30
- package/dist/utils/findInvalidi18nTranslations.d.ts +2 -2
- package/dist/utils/findInvalidi18nTranslations.js +35 -35
- package/dist/utils/findInvalidi18nTranslations.test.js +72 -72
- package/dist/utils/findMissingKeys.d.ts +1 -1
- package/dist/utils/findMissingKeys.js +2 -2
- package/dist/utils/findMissingKeys.test.js +20 -20
- package/dist/utils/flattenTranslations.d.ts +1 -1
- package/dist/utils/flattenTranslations.js +3 -3
- package/dist/utils/flattenTranslations.test.js +13 -13
- package/dist/utils/i18NextParser.d.ts +6 -6
- package/dist/utils/i18NextParser.js +29 -29
- package/dist/utils/i18NextParser.test.js +104 -104
- package/dist/utils/nextIntlSrcParser.js +11 -11
- package/dist/utils/nextIntlSrcParser.test.js +156 -156
- package/package.json +14 -4
|
@@ -39,8 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.extract = void 0;
|
|
40
40
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
41
41
|
const ts = __importStar(require("typescript"));
|
|
42
|
-
const USE_TRANSLATIONS =
|
|
43
|
-
const GET_TRANSLATIONS =
|
|
42
|
+
const USE_TRANSLATIONS = 'useTranslations';
|
|
43
|
+
const GET_TRANSLATIONS = 'getTranslations';
|
|
44
44
|
const COMMENT_CONTAINS_STATIC_KEY_REGEX = /t\((["'])(.*?[^\\])(["'])\)/;
|
|
45
45
|
const extract = (filesPaths) => {
|
|
46
46
|
return filesPaths.flatMap(getKeys).sort((a, b) => {
|
|
@@ -49,7 +49,7 @@ const extract = (filesPaths) => {
|
|
|
49
49
|
};
|
|
50
50
|
exports.extract = extract;
|
|
51
51
|
const getKeys = (path) => {
|
|
52
|
-
const content = node_fs_1.default.readFileSync(path,
|
|
52
|
+
const content = node_fs_1.default.readFileSync(path, 'utf-8');
|
|
53
53
|
const sourceFile = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
|
|
54
54
|
const foundKeys = [];
|
|
55
55
|
let namespaces = [];
|
|
@@ -82,7 +82,7 @@ const getKeys = (path) => {
|
|
|
82
82
|
};
|
|
83
83
|
const visit = (node) => {
|
|
84
84
|
let key = null;
|
|
85
|
-
|
|
85
|
+
const initialNamespacesLength = namespaces.length;
|
|
86
86
|
if (node === undefined) {
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
@@ -94,12 +94,12 @@ const getKeys = (path) => {
|
|
|
94
94
|
// from the default `t`, i.e.: const other = useTranslations("namespace1");
|
|
95
95
|
if (node.initializer.expression.text === USE_TRANSLATIONS) {
|
|
96
96
|
const [argument] = node.initializer.arguments;
|
|
97
|
-
const variable = ts.isIdentifier(node.name) ? node.name.text :
|
|
97
|
+
const variable = ts.isIdentifier(node.name) ? node.name.text : 't';
|
|
98
98
|
if (argument && ts.isStringLiteral(argument)) {
|
|
99
99
|
pushNamespace({ name: argument.text, variable });
|
|
100
100
|
}
|
|
101
101
|
else if (argument === undefined) {
|
|
102
|
-
pushNamespace({ name:
|
|
102
|
+
pushNamespace({ name: '', variable });
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -119,14 +119,14 @@ const getKeys = (path) => {
|
|
|
119
119
|
ts.isIdentifier(node.initializer.expression.expression)) {
|
|
120
120
|
if (node.initializer.expression.expression.text === GET_TRANSLATIONS) {
|
|
121
121
|
const [argument] = node.initializer.expression.arguments;
|
|
122
|
-
const variable = ts.isIdentifier(node.name) ? node.name.text :
|
|
122
|
+
const variable = ts.isIdentifier(node.name) ? node.name.text : 't';
|
|
123
123
|
if (argument && ts.isObjectLiteralExpression(argument)) {
|
|
124
124
|
argument.properties.forEach((property) => {
|
|
125
125
|
if (property &&
|
|
126
126
|
ts.isPropertyAssignment(property) &&
|
|
127
127
|
property.name &&
|
|
128
128
|
ts.isIdentifier(property.name) &&
|
|
129
|
-
property.name.text ===
|
|
129
|
+
property.name.text === 'namespace' &&
|
|
130
130
|
ts.isStringLiteral(property.initializer)) {
|
|
131
131
|
pushNamespace({ name: property.initializer.text, variable });
|
|
132
132
|
}
|
|
@@ -136,7 +136,7 @@ const getKeys = (path) => {
|
|
|
136
136
|
pushNamespace({ name: argument.text, variable });
|
|
137
137
|
}
|
|
138
138
|
else if (argument === undefined) {
|
|
139
|
-
pushNamespace({ name:
|
|
139
|
+
pushNamespace({ name: '', variable });
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
}
|
|
@@ -225,7 +225,7 @@ const getKeys = (path) => {
|
|
|
225
225
|
}
|
|
226
226
|
if (key) {
|
|
227
227
|
const namespace = getCurrentNamespaceForIdentifier(key.identifier);
|
|
228
|
-
const namespaceName = namespace ? namespace.name :
|
|
228
|
+
const namespaceName = namespace ? namespace.name : '';
|
|
229
229
|
foundKeys.push({
|
|
230
230
|
key: namespaceName ? `${namespaceName}.${key.name}` : key.name,
|
|
231
231
|
meta: { file: path, namespace: namespaceName },
|
|
@@ -249,7 +249,7 @@ const getKeys = (path) => {
|
|
|
249
249
|
const commentKey = COMMENT_CONTAINS_STATIC_KEY_REGEX.exec(comment)?.[2];
|
|
250
250
|
if (commentKey) {
|
|
251
251
|
const namespace = getCurrentNamespaces();
|
|
252
|
-
const namespaceName = namespace ? namespace[0]?.name :
|
|
252
|
+
const namespaceName = namespace ? namespace[0]?.name : '';
|
|
253
253
|
foundKeys.push({
|
|
254
254
|
key: namespaceName
|
|
255
255
|
? `${namespaceName}.${commentKey}`
|