Skip to content

Commit

Permalink
Add br tag to translation verification script
Browse files Browse the repository at this point in the history
  • Loading branch information
raksooo committed Mar 13, 2024
1 parent 3ad007e commit fc6f8da
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions gui/scripts/verify-translations-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import path from 'path';

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

const ALLOWED_TAGS = ['b'];
const ALLOWED_TAGS = ['b', 'br'];
const ALLOWED_VOID_TAGS = ['br'];

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

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

if (endTag) {
// End tags require a matching start tag.
if (tag !== tagStack.pop()) {
console.error(`Closing non-existent start-tag (</${tag}>) in "${value}"`);
return { correct: false, amount: NaN };
if (!ALLOWED_VOID_TAGS.includes(tag)) {
if (endTag) {
// End tags require a matching start tag.
if (tag !== tagStack.pop()) {
console.error(`Closing non-existent start-tag (</${tag}>) in "${value}"`);
return { correct: false, amount: NaN };
}
} else {
tagStack.push(tag);
}
} else {
tagStack.push(tag);
}
}

Expand Down

0 comments on commit fc6f8da

Please sign in to comment.