Skip to content

Commit 6a24488

Browse files
committed
use Set and plain for loop
1 parent 791192b commit 6a24488

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

scripts/utils/Translator/Translator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ abstract class Translator {
5353
*/
5454
public validateTemplateHTML(original: string, translated: string): boolean {
5555
// Attributes that are allowed to be translated
56-
const TRANSLATABLE_ATTRIBUTES = ['alt', 'title', 'placeholder', 'aria-label', 'aria-describedby', 'aria-labelledby', 'value'];
56+
const TRANSLATABLE_ATTRIBUTES = new Set(['alt', 'title', 'placeholder', 'aria-label', 'aria-describedby', 'aria-labelledby', 'value']);
5757

5858
const parseHTMLStructure = (s: string) => {
5959
const doc = parseDocument(s);
@@ -65,12 +65,12 @@ abstract class Translator {
6565
// Extract attributes, excluding translatable ones
6666
const attributes: string[] = [];
6767
if (element.attribs) {
68-
Object.entries(element.attribs).forEach(([attrName, attrValue]) => {
68+
for (const [attrName, attrValue] of Object.entries(element.attribs ?? {})) {
6969
const normalizedAttrName = attrName.toLowerCase();
70-
if (!TRANSLATABLE_ATTRIBUTES.includes(normalizedAttrName)) {
70+
if (!TRANSLATABLE_ATTRIBUTES.has(normalizedAttrName)) {
7171
attributes.push(`${normalizedAttrName}="${attrValue ?? ''}"`);
7272
}
73-
});
73+
}
7474
}
7575

7676
return {

0 commit comments

Comments
 (0)