Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scripts/i18n-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,14 @@ for (const file of sourceFiles) {
const bindings = [
...source.matchAll(/\b(?:const|let|var)\s+(\w+)\s*=\s*useScopedT\(\s*"(\w+)"\s*\)/g),
].map((m) => ({ name: m[1], ns: m[2], at: m.index }));
for (const match of source.matchAll(/\b(t[A-Z]?\w*)\(\s*"([\w.-]+)"/g)) {
// A callee is a translator when the file binds it to useScopedT, or when it is named like
// one handed in as a prop or parameter: `t`, or `t` plus a capital (`tCommon`). Any other
// name starting with a t, like `tierOutputDims("source")`, is not a translation call.
const bound = new Set(bindings.map((b) => b.name));
const isTranslator = (callee) => bound.has(callee) || /^t(?:[A-Z]\w*)?$/.test(callee);
for (const match of source.matchAll(/\b([A-Za-z_]\w*)\(\s*"([\w.-]+)"/g)) {
const [, callee, key] = match;
if (!isTranslator(callee)) continue;
checkedKeyCount++;
const own = bindings.filter((b) => b.name === callee);
const nearest = own.filter((b) => b.at < match.index).at(-1);
Expand Down
Loading