Skip to content

Commit fc6f8da

Browse files
committed
Add br tag to translation verification script
1 parent 3ad007e commit fc6f8da

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

gui/scripts/verify-translations-format.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import path from 'path';
44

55
const LOCALES_DIR = path.join('..', 'locales');
66

7-
const ALLOWED_TAGS = ['b'];
7+
const ALLOWED_TAGS = ['b', 'br'];
8+
const ALLOWED_VOID_TAGS = ['br'];
89

910
function getLocales(): string[] {
1011
const localesContent = fs.readdirSync(LOCALES_DIR);
@@ -70,22 +71,25 @@ function checkHtmlTagsImpl(value: string): { correct: boolean, amount: number }
7071
// item.
7172
let tagStack: string[] = [];
7273
for (let tag of tagTypes) {
74+
const selfClosing = tag.endsWith('/');
7375
const endTag = tag.startsWith('/');
74-
tag = endTag ? tag.slice(1) : tag;
76+
tag = endTag ? tag.slice(1) : selfClosing ? tag.slice(0, -1) : tag;
7577

7678
if (!ALLOWED_TAGS.includes(tag)) {
7779
console.error(`Tag "<${tag}>" not allowed: "${value}"`);
7880
return { correct: false, amount: NaN };
7981
}
8082

81-
if (endTag) {
82-
// End tags require a matching start tag.
83-
if (tag !== tagStack.pop()) {
84-
console.error(`Closing non-existent start-tag (</${tag}>) in "${value}"`);
85-
return { correct: false, amount: NaN };
83+
if (!ALLOWED_VOID_TAGS.includes(tag)) {
84+
if (endTag) {
85+
// End tags require a matching start tag.
86+
if (tag !== tagStack.pop()) {
87+
console.error(`Closing non-existent start-tag (</${tag}>) in "${value}"`);
88+
return { correct: false, amount: NaN };
89+
}
90+
} else {
91+
tagStack.push(tag);
8692
}
87-
} else {
88-
tagStack.push(tag);
8993
}
9094
}
9195

0 commit comments

Comments
 (0)