Skip to content

Commit c4e1ec8

Browse files
committed
chore: apply coderabbitai suggestions
1 parent e9a8442 commit c4e1ec8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

scripts/compare-translations.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,19 @@ const loadJson = async ({ filePath, mergeLocale, locale }: LocaleInfo): Promise<
107107
return JSON.parse(readFileSync(filePath, 'utf-8')) as NestedObject
108108
}
109109

110-
return await mergeLocaleObject(currentLocales.find(l => l.code === locale)!)
110+
const localeObject = currentLocales.find(l => l.code === locale)
111+
if (!localeObject) {
112+
console.error(
113+
`${COLORS.red}Error: Locale "${locale}" not found in currentLocales${COLORS.reset}`,
114+
)
115+
process.exit(1)
116+
}
117+
const merged = await mergeLocaleObject(localeObject)
118+
if (!merged) {
119+
console.error(`${COLORS.red}Error: Failed to merge locale "${locale}"${COLORS.reset}`)
120+
process.exit(1)
121+
}
122+
return merged as NestedObject
111123
}
112124

113125
type SyncStats = {
@@ -328,6 +340,7 @@ const runAllLocales = async (referenceContent: NestedObject, fix = false): Promi
328340
}
329341

330342
const run = async (): Promise<void> => {
343+
populateLocaleCountries()
331344
const referenceFilePath = join(LOCALES_DIRECTORY, REFERENCE_FILE_NAME)
332345
const referenceContent = await loadJson({
333346
filePath: referenceFilePath,
@@ -339,8 +352,6 @@ const run = async (): Promise<void> => {
339352
const fix = args.includes('--fix')
340353
const targetLocale = args.find(arg => !arg.startsWith('--'))
341354

342-
populateLocaleCountries()
343-
344355
if (targetLocale) {
345356
// Single locale mode
346357
await runSingleLocale(targetLocale, referenceContent, fix)

0 commit comments

Comments
 (0)