@lingual/i18n-check 0.7.5 → 0.8.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/dist/bin/index.js +22 -9
- package/dist/bin/index.test.js +200 -93
- package/dist/errorReporters.d.ts +7 -4
- package/dist/errorReporters.js +48 -4
- package/dist/index.js +24 -2
- package/dist/utils/findInvalidTranslations.d.ts +4 -1
- package/dist/utils/findInvalidTranslations.js +94 -4
- package/dist/utils/findInvalidTranslations.test.js +26 -8
- package/dist/utils/findInvalidi18nTranslations.js +90 -3
- package/dist/utils/findInvalidi18nTranslations.test.js +80 -11
- package/dist/utils/nextIntlSrcParser.d.ts +2 -0
- package/dist/utils/nextIntlSrcParser.js +38 -7
- package/dist/utils/nextIntlSrcParser.test.js +146 -118
- package/package.json +1 -1
|
@@ -44,7 +44,7 @@ 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) => {
|
|
47
|
-
return a > b ? 1 : -1;
|
|
47
|
+
return a.key > b.key ? 1 : -1;
|
|
48
48
|
});
|
|
49
49
|
};
|
|
50
50
|
exports.extract = extract;
|
|
@@ -67,6 +67,14 @@ const getKeys = (path) => {
|
|
|
67
67
|
const pushNamespace = (namespace) => {
|
|
68
68
|
namespaces.push(namespace);
|
|
69
69
|
};
|
|
70
|
+
const setNamespaceAsDynamic = (name) => {
|
|
71
|
+
namespaces = namespaces.map((namespace) => {
|
|
72
|
+
if (namespace.name === name) {
|
|
73
|
+
return { ...namespace, dynamic: true };
|
|
74
|
+
}
|
|
75
|
+
return namespace;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
70
78
|
const removeNamespaces = (range = 1) => {
|
|
71
79
|
if (namespaces.length > 0) {
|
|
72
80
|
namespaces = namespaces.slice(0, namespaces.length - range);
|
|
@@ -74,7 +82,7 @@ const getKeys = (path) => {
|
|
|
74
82
|
};
|
|
75
83
|
const visit = (node) => {
|
|
76
84
|
let key = null;
|
|
77
|
-
let
|
|
85
|
+
let initialNamespacesLength = namespaces.length;
|
|
78
86
|
if (node === undefined) {
|
|
79
87
|
return;
|
|
80
88
|
}
|
|
@@ -168,7 +176,7 @@ const getKeys = (path) => {
|
|
|
168
176
|
if (key) {
|
|
169
177
|
foundKeys.push({
|
|
170
178
|
key: inlineNamespace ? `${inlineNamespace}.${key}` : key,
|
|
171
|
-
meta: { file: path },
|
|
179
|
+
meta: { file: path, namespace: inlineNamespace ?? undefined },
|
|
172
180
|
});
|
|
173
181
|
}
|
|
174
182
|
}
|
|
@@ -187,6 +195,12 @@ const getKeys = (path) => {
|
|
|
187
195
|
if (argument && ts.isStringLiteral(argument)) {
|
|
188
196
|
key = { name: argument.text, identifier: expressionName };
|
|
189
197
|
}
|
|
198
|
+
else if (argument && ts.isIdentifier(argument)) {
|
|
199
|
+
setNamespaceAsDynamic(namespace.name);
|
|
200
|
+
}
|
|
201
|
+
else if (argument && ts.isTemplateExpression(argument)) {
|
|
202
|
+
setNamespaceAsDynamic(namespace.name);
|
|
203
|
+
}
|
|
190
204
|
}
|
|
191
205
|
}
|
|
192
206
|
// Search for `t.*()` calls, i.e. t.html() or t.rich()
|
|
@@ -201,6 +215,12 @@ const getKeys = (path) => {
|
|
|
201
215
|
if (argument && ts.isStringLiteral(argument)) {
|
|
202
216
|
key = { name: argument.text, identifier: expressionName };
|
|
203
217
|
}
|
|
218
|
+
else if (argument && ts.isIdentifier(argument)) {
|
|
219
|
+
setNamespaceAsDynamic(namespace.name);
|
|
220
|
+
}
|
|
221
|
+
else if (argument && ts.isTemplateExpression(argument)) {
|
|
222
|
+
setNamespaceAsDynamic(namespace.name);
|
|
223
|
+
}
|
|
204
224
|
}
|
|
205
225
|
}
|
|
206
226
|
if (key) {
|
|
@@ -208,7 +228,7 @@ const getKeys = (path) => {
|
|
|
208
228
|
const namespaceName = namespace ? namespace.name : "";
|
|
209
229
|
foundKeys.push({
|
|
210
230
|
key: namespaceName ? `${namespaceName}.${key.name}` : key.name,
|
|
211
|
-
meta: { file: path },
|
|
231
|
+
meta: { file: path, namespace: namespaceName },
|
|
212
232
|
});
|
|
213
233
|
}
|
|
214
234
|
// Search for single-line comments that contain the static values of a dynamic key
|
|
@@ -234,15 +254,26 @@ const getKeys = (path) => {
|
|
|
234
254
|
key: namespaceName
|
|
235
255
|
? `${namespaceName}.${commentKey}`
|
|
236
256
|
: commentKey,
|
|
237
|
-
meta: { file: path },
|
|
257
|
+
meta: { file: path, namespace: namespaceName },
|
|
238
258
|
});
|
|
239
259
|
}
|
|
240
260
|
}
|
|
241
261
|
});
|
|
242
262
|
}
|
|
243
263
|
ts.forEachChild(node, visit);
|
|
244
|
-
if (ts.isFunctionLike(node) &&
|
|
245
|
-
|
|
264
|
+
if (ts.isFunctionLike(node) &&
|
|
265
|
+
namespaces.length > initialNamespacesLength) {
|
|
266
|
+
// check if the namespaces are dynamic and add a placeholder key
|
|
267
|
+
const currentNamespaces = getCurrentNamespaces(namespaces?.length - initialNamespacesLength);
|
|
268
|
+
currentNamespaces?.forEach((namespace) => {
|
|
269
|
+
if (namespace.dynamic) {
|
|
270
|
+
foundKeys.push({
|
|
271
|
+
key: namespace.name,
|
|
272
|
+
meta: { file: path, namespace: namespace.name, dynamic: true },
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
removeNamespaces(namespaces.length - initialNamespacesLength);
|
|
246
277
|
}
|
|
247
278
|
};
|
|
248
279
|
ts.forEachChild(sourceFile, visit);
|