fix(test): Improve translation check test and fix related issues
This commit is contained in:
parent
9ed4d74f1d
commit
9a5d3dbca4
@ -26,36 +26,30 @@ describe("Check Translations", () => {
|
|||||||
|
|
||||||
// this is a resonably crude check, you can get around this trivially
|
// this is a resonably crude check, you can get around this trivially
|
||||||
/// this check is just to save on maintainer energy to explain this on every review ^^
|
/// this check is just to save on maintainer energy to explain this on every review ^^
|
||||||
const translationRegex = /\$t\(['"](?<key1>.*?)['"]\s*[,)]|i18n-t\s+keypath=\x22(?<key2>[^\x22]+)\x22/g;
|
const translationRegex = /\$t\(['"](?<key1>.*?)['"]\s*[,)]|i18n-t[^>]*\s+keypath="(?<key2>[^"]+)"/gd;
|
||||||
|
|
||||||
const missingKeys = [];
|
const missingKeys = [];
|
||||||
|
|
||||||
for (const filePath of walk("src")) {
|
for (const filePath of walk("src")) {
|
||||||
if (filePath.endsWith(".vue") || filePath.endsWith(".js")) {
|
if (filePath.endsWith(".vue") || filePath.endsWith(".js")) {
|
||||||
try {
|
|
||||||
const lines = fs.readFileSync(filePath, "utf-8").split("\n");
|
const lines = fs.readFileSync(filePath, "utf-8").split("\n");
|
||||||
lines.forEach((line, lineNum) => {
|
lines.forEach((line, lineNum) => {
|
||||||
let match;
|
let match;
|
||||||
while ((match = translationRegex.exec(line)) !== null) {
|
while ((match = translationRegex.exec(line)) !== null) {
|
||||||
const key = match.groups.key1 || match.groups.key2;
|
const key = match.groups.key1 || match.groups.key2;
|
||||||
if (key && !enTranslations[key]) {
|
if (key && !enTranslations[key]) {
|
||||||
const start = match.index;
|
const [start, end] = match.groups.key1 ? match.indices.groups.key1 : match.indices.groups.key2;
|
||||||
const end = start + key.length;
|
|
||||||
missingKeys.push({
|
missingKeys.push({
|
||||||
filePath,
|
filePath,
|
||||||
lineNum: lineNum + 1,
|
lineNum: lineNum + 1,
|
||||||
key,
|
key,
|
||||||
line: line.trim(),
|
line: line,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
|
||||||
console.error(`Error processing file: ${filePath}`, e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +64,7 @@ describe("Check Translations", () => {
|
|||||||
report += `\n | ${arrow} unrecognized translation key`;
|
report += `\n | ${arrow} unrecognized translation key`;
|
||||||
report += "\n |";
|
report += "\n |";
|
||||||
report += `\n = note: please register the translation key '${key}' in en.json so that our awesome team of translators can translate them`;
|
report += `\n = note: please register the translation key '${key}' in en.json so that our awesome team of translators can translate them`;
|
||||||
report += "\n = tip: if you want to contribute translations, please visit our https://weblate.kuma.pet\n";
|
report += "\n = tip: if you want to contribute translations, please visit https://weblate.kuma.pet\n";
|
||||||
});
|
});
|
||||||
report += "\n===============================";
|
report += "\n===============================";
|
||||||
const fileCount = new Set(missingKeys.map(item => item.filePath)).size;
|
const fileCount = new Set(missingKeys.map(item => item.filePath)).size;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user