diff --git a/test/backend-test/check-translations.test.js b/test/backend-test/check-translations.test.js index 33ec04fc5..b79f6d5a2 100644 --- a/test/backend-test/check-translations.test.js +++ b/test/backend-test/check-translations.test.js @@ -26,36 +26,30 @@ describe("Check Translations", () => { // 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 ^^ - const translationRegex = /\$t\(['"](?.*?)['"]\s*[,)]|i18n-t\s+keypath=\x22(?[^\x22]+)\x22/g; + const translationRegex = /\$t\(['"](?.*?)['"]\s*[,)]|i18n-t[^>]*\s+keypath="(?[^"]+)"/gd; const missingKeys = []; for (const filePath of walk("src")) { if (filePath.endsWith(".vue") || filePath.endsWith(".js")) { - try { - const lines = fs.readFileSync(filePath, "utf-8").split("\n"); - lines.forEach((line, lineNum) => { - let match; - while ((match = translationRegex.exec(line)) !== null) { - const key = match.groups.key1 || match.groups.key2; - if (key && !enTranslations[key]) { - const start = match.index; - const end = start + key.length; - missingKeys.push({ - filePath, - lineNum: lineNum + 1, - key, - line: line.trim(), - start, - end, - }); - } + const lines = fs.readFileSync(filePath, "utf-8").split("\n"); + lines.forEach((line, lineNum) => { + let match; + while ((match = translationRegex.exec(line)) !== null) { + const key = match.groups.key1 || match.groups.key2; + if (key && !enTranslations[key]) { + const [start, end] = match.groups.key1 ? match.indices.groups.key1 : match.indices.groups.key2; + missingKeys.push({ + filePath, + lineNum: lineNum + 1, + key, + line: line, + start, + 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 |"; 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==============================="; const fileCount = new Set(missingKeys.map(item => item.filePath)).size;