Merge branch 'V2' into feature/v2/viewer-improvements

This commit is contained in:
Reece Browne 2025-10-31 18:37:28 +00:00 committed by GitHub
commit 1767b755b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@ const IGNORED_KEYS = new Set<string>([
type FoundKey = { type FoundKey = {
key: string; key: string;
fallback: string;
file: string; file: string;
line: number; line: number;
column: number; column: number;
@ -86,22 +87,27 @@ const extractKeys = (file: string): FoundKey[] => {
const found: FoundKey[] = []; const found: FoundKey[] = [];
const record = (node: ts.Node, key: string) => { const record = (node: ts.Node, key: string, fallback: string = "") => {
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart()); const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
found.push({ key, file, line: line + 1, column: character + 1 }); found.push({ key, fallback, file, line: line + 1, column: character + 1 });
}; };
const visit = (node: ts.Node) => { const visit = (node: ts.Node) => {
if (ts.isCallExpression(node)) { if (ts.isCallExpression(node)) {
const callee = node.expression; const callee = node.expression;
const arg = node.arguments.at(0); const arg0 = node.arguments.at(0);
const arg1 = node.arguments.at(1);
const isT = const isT =
(ts.isIdentifier(callee) && callee.text === 't') || (ts.isIdentifier(callee) && callee.text === 't') ||
(ts.isPropertyAccessExpression(callee) && callee.name.text === 't'); (ts.isPropertyAccessExpression(callee) && callee.name.text === 't');
if (isT && arg && (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg))) { if (isT && arg0 && (ts.isStringLiteral(arg0) || ts.isNoSubstitutionTemplateLiteral(arg0))) {
record(arg, arg.text); let arg1Text: string = "";
if (arg1 && (ts.isStringLiteral(arg1) || ts.isNoSubstitutionTemplateLiteral(arg1))) {
arg1Text = arg1.text;
}
record(arg0, arg0.text, arg1Text);
} }
} }
@ -154,12 +160,13 @@ describe('Missing translation coverage', () => {
const missingKeys = usedKeys.filter(({ key }) => !availableKeys.has(key)); const missingKeys = usedKeys.filter(({ key }) => !availableKeys.has(key));
const annotations = missingKeys.map(({ key, file, line, column }) => { const annotations = missingKeys.map(({ key, fallback, file, line, column }) => {
const workspaceRelativeRaw = path.relative(REPO_ROOT, file); const workspaceRelativeRaw = path.relative(REPO_ROOT, file);
const workspaceRelativeFile = workspaceRelativeRaw.replace(/\\/g, '/'); const workspaceRelativeFile = workspaceRelativeRaw.replace(/\\/g, '/');
return { return {
key, key,
fallback,
file: workspaceRelativeFile, file: workspaceRelativeFile,
line, line,
column, column,
@ -167,12 +174,20 @@ describe('Missing translation coverage', () => {
}); });
// Output errors in GitHub Annotations format so they appear tagged in the code in CI // Output errors in GitHub Annotations format so they appear tagged in the code in CI
for (const { key, file, line, column } of annotations) { for (const { key, fallback, file, line, column } of annotations) {
process.stderr.write( process.stderr.write(
`::error file=${file},line=${line},col=${column}::Missing en-GB translation for ${key}\n`, `::error file=${file},line=${line},col=${column}::Missing en-GB translation for ${key} (${fallback})\n`,
); );
} }
expect(missingKeys).toEqual([]); const neatened = annotations.map(({ key, fallback, file, line, column }) => {
return {
key,
fallback,
location: `${file}:${line}:${column}`,
}
});
expect(neatened).toEqual([]);
}); });
}); });