diff --git a/scripts/i18n/scan-hardcoded.ts b/scripts/i18n/scan-hardcoded.ts index 6aec3f89..1420f063 100755 --- a/scripts/i18n/scan-hardcoded.ts +++ b/scripts/i18n/scan-hardcoded.ts @@ -104,6 +104,15 @@ function isHuman(value: string | undefined): value is string { const stripComments = (source: string): string => source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^[ \t]*\/\/.*$/gm, ''); +/** + * ``, ``, `
` and `` mark content as code rather than prose — that is what the
+ * elements are for. `Authorization: Bearer …` is an HTTP header, which the doc's
+ * never-translate list covers as an identifier crossing a boundary, and translating it would break the
+ * thing it documents.
+ */
+const stripCodeElements = (source: string): string =>
+  source.replace(/<(code|kbd|pre|samp)\b[^>]*>[\s\S]*?<\/\1>/g, '<$1/>');
+
 function* walk(dir: string): Generator {
   let entries: string[];
   try {
@@ -135,7 +144,7 @@ function scan(root: string): { files: number; hits: Hit[] } {
     files++;
     let source: string;
     try {
-      source = stripComments(readFileSync(file, 'utf8'));
+      source = stripCodeElements(stripComments(readFileSync(file, 'utf8')));
     } catch {
       continue;
     }