Skip to content

Commit cbb56e6

Browse files
committed
perf: create current locales map
1 parent 120d983 commit cbb56e6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

scripts/compare-translations.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-console */
2+
import type { LocaleObject } from '@nuxtjs/i18n'
23
import * as process from 'node:process'
34
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
45
import { basename, join } from 'node:path'
@@ -29,6 +30,7 @@ interface LocaleInfo {
2930
}
3031

3132
const countries = new Map<string, Map<string, LocaleInfo>>()
33+
const availableLocales = new Map<string, LocaleObject>()
3234

3335
const extractLocalInfo = (
3436
filePath: string,
@@ -55,6 +57,10 @@ const populateLocaleCountries = (): void => {
5557
}
5658
}
5759
}
60+
61+
for (const localeData of currentLocales) {
62+
availableLocales.set(localeData.code, localeData)
63+
}
5864
}
5965

6066
/**
@@ -107,7 +113,7 @@ const loadJson = async ({ filePath, mergeLocale, locale }: LocaleInfo): Promise<
107113
return JSON.parse(readFileSync(filePath, 'utf-8')) as NestedObject
108114
}
109115

110-
const localeObject = currentLocales.find(l => l.code === locale)
116+
const localeObject = availableLocales.get(locale)
111117
if (!localeObject) {
112118
console.error(
113119
`${COLORS.red}Error: Locale "${locale}" not found in currentLocales${COLORS.reset}`,

0 commit comments

Comments
 (0)