fix: skip translation key extraction for files without i18n usage (#6221)

This commit is contained in:
Ludy
2026-04-25 13:08:24 +01:00
committed by GitHub
parent 5cfb77314f
commit 9890d6a7de
@@ -21,6 +21,7 @@ const IGNORED_FILE_PATTERNS = [
const IGNORED_KEYS = new Set<string>([ const IGNORED_KEYS = new Set<string>([
// If the script has found a false-positive that shouldn't be in the translations, include it here // If the script has found a false-positive that shouldn't be in the translations, include it here
]); ]);
const LIKELY_TRANSLATION_USAGE_RE = /(?:^|[^\w$])t\s*\(|\.t\s*\(|\bi18nKey\b/;
type FoundKey = { type FoundKey = {
key: string; key: string;
@@ -90,6 +91,10 @@ const getScriptKind = (file: string): ts.ScriptKind => {
*/ */
const extractKeys = (file: string): FoundKey[] => { const extractKeys = (file: string): FoundKey[] => {
const code = fs.readFileSync(file, "utf8"); const code = fs.readFileSync(file, "utf8");
if (!LIKELY_TRANSLATION_USAGE_RE.test(code)) {
return [];
}
const sourceFile = ts.createSourceFile( const sourceFile = ts.createSourceFile(
file, file,
code, code,