Skip to content

Commit a8b7fbe

Browse files
strickvlclaude
andcommitted
refactor: use addResourceBundle instead of re-initializing i18next
Replace manual resource merging and re-initialization with i18next's built-in addResourceBundle API. This is more efficient, cleaner, and the idiomatic way to add custom translations dynamically. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e89a9af commit a8b7fbe

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

src/node/i18n/index.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,9 @@ export async function loadCustomStrings(customStringsArg: string): Promise<void>
3939
customStringsData = JSON.parse(fileContent)
4040
}
4141

42-
// Re-initialize i18next with merged resources
43-
const mergedResources = Object.keys(defaultResources).reduce((acc, lang) => {
44-
const langKey = lang as keyof typeof defaultResources
45-
acc[langKey] = {
46-
translation: {
47-
...defaultResources[langKey].translation,
48-
...customStringsData,
49-
},
50-
}
51-
return acc
52-
}, {} as typeof defaultResources)
53-
54-
await i18next.init({
55-
lng: "en",
56-
fallbackLng: "en",
57-
returnNull: false,
58-
lowerCaseLng: true,
59-
debug: process.env.NODE_ENV === "development",
60-
resources: mergedResources,
42+
// User-provided strings override all languages.
43+
Object.keys(defaultResources).forEach((locale) => {
44+
i18next.addResourceBundle(locale, "translation", customStringsData)
6145
})
6246
} catch (error) {
6347
throw new Error(`Failed to load custom strings: ${error instanceof Error ? error.message : String(error)}`)

0 commit comments

Comments
 (0)