diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-10-23 17:44:26 +0200 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-10-30 17:05:45 +0100 |
| commit | eaf6c236f90da406cb91627355f772a47ddcf0b9 (patch) | |
| tree | 0589d6e4033d35f1b65cb186c9fff540c34295f3 | |
| parent | 1200a98f642b7da7194c2e456e2c1cbe7c204292 (diff) | |
| download | mullvadvpn-eaf6c236f90da406cb91627355f772a47ddcf0b9.tar.xz mullvadvpn-eaf6c236f90da406cb91627355f772a47ddcf0b9.zip | |
Import ALLOWED_TAGS from formatHtml in verify translations script
It is easier if we have one source of truth for what tags are allowed.
| -rw-r--r-- | desktop/packages/mullvad-vpn/scripts/verify-translations-format.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/desktop/packages/mullvad-vpn/scripts/verify-translations-format.ts b/desktop/packages/mullvad-vpn/scripts/verify-translations-format.ts index 4b21b46426..af8cd56e66 100644 --- a/desktop/packages/mullvad-vpn/scripts/verify-translations-format.ts +++ b/desktop/packages/mullvad-vpn/scripts/verify-translations-format.ts @@ -2,9 +2,11 @@ import fs from 'fs'; import { GetTextTranslation, po } from 'gettext-parser'; import path from 'path'; +import { ALLOWED_TAGS } from '../src/renderer/lib/html-formatter'; +import { ValueOfArray } from '../src/shared/utility-types'; + const LOCALES_DIR = path.join('locales'); -const ALLOWED_TAGS = ['b', 'br', 'em']; const ALLOWED_VOID_TAGS = ['br']; // Make sure to report these strings to crowdin. View this as a temporary escape @@ -69,6 +71,10 @@ function checkFormatSpecifiers(translation: GetTextTranslation): boolean { .every((result) => result); } +function isAllowedTag(tag: string): tag is ValueOfArray<typeof ALLOWED_TAGS> { + return ALLOWED_TAGS.some((allowedTag) => tag === allowedTag); +} + function checkHtmlTagsImpl(value: string): { correct: boolean; amount: number } { const tagsRegexp = new RegExp('<.*?>', 'g'); const tags = value.match(tagsRegexp) ?? []; @@ -82,7 +88,7 @@ function checkHtmlTagsImpl(value: string): { correct: boolean; amount: number } const endTag = tag.startsWith('/'); tag = endTag ? tag.slice(1) : selfClosing ? tag.slice(0, -1).trim() : tag; - if (!ALLOWED_TAGS.includes(tag)) { + if (!isAllowedTag(tag)) { console.error(`Tag "<${tag}>" not allowed: "${value}"`); return { correct: false, amount: NaN }; } |
