(filePath: string)
| 25 | } |
| 26 | |
| 27 | export async function loadCustomStrings(filePath: string): Promise<void> { |
| 28 | try { |
| 29 | // Read custom strings from file path only |
| 30 | const fileContent = await fs.readFile(filePath, "utf8") |
| 31 | const customStringsData = JSON.parse(fileContent) |
| 32 | |
| 33 | // User-provided strings override all languages. |
| 34 | Object.keys(defaultResources).forEach((locale) => { |
| 35 | i18next.addResourceBundle(locale, "translation", customStringsData) |
| 36 | }) |
| 37 | } catch (error) { |
| 38 | if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") { |
| 39 | throw new Error(`Custom strings file not found: ${filePath}\nPlease ensure the file exists and is readable.`) |
| 40 | } else if (error instanceof SyntaxError) { |
| 41 | throw new Error(`Invalid JSON in custom strings file: ${filePath}\n${error.message}`) |
| 42 | } else { |
| 43 | throw new Error( |
| 44 | `Failed to load custom strings from ${filePath}: ${error instanceof Error ? error.message : String(error)}`, |
| 45 | ) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | init({ |
| 51 | lng: "en", |
no outgoing calls
no test coverage detected