Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Tweak core/i18n to prevent double import warnings in browser extension (#2457)

Leendert de Borst121a59ea48e1
diff --git a/apps/web/src/i18n/i18n.ts b/apps/web/src/i18n/i18n.ts
index 220aac80d..92e10828c 100644
--- a/apps/web/src/i18n/i18n.ts
+++ b/apps/web/src/i18n/i18n.ts
@@ -1,4 +1,5 @@
-import { englishTranslations, loadTranslations, type TranslationTree } from '@aliasvault/i18n';
+import { englishTranslations, type TranslationTree } from '@aliasvault/i18n';
+import { loadTranslations } from '@aliasvault/i18n/load';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
diff --git a/core/i18n/package.json b/core/i18n/package.json
index 819e1e93c..bd590ede6 100644
--- a/core/i18n/package.json
+++ b/core/i18n/package.json
@@ -9,6 +9,7 @@
".": "./src/index.ts",
"./all": "./src/all.ts",
"./languages": "./src/languages.ts",
+ "./load": "./src/load.ts",
"./locales/*": "./locales/*"
},
"scripts": {
diff --git a/core/i18n/src/__tests__/registry.test.ts b/core/i18n/src/__tests__/registry.test.ts
index 13517ef79..6128dae7b 100644
--- a/core/i18n/src/__tests__/registry.test.ts
+++ b/core/i18n/src/__tests__/registry.test.ts
@@ -4,7 +4,8 @@ import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { ALL_TRANSLATIONS } from '../all';
-import { DEFAULT_LANGUAGE, LANGUAGE_CODES, LANGUAGES, UI_LANGUAGES, loadTranslations } from '../index';
+import { DEFAULT_LANGUAGE, LANGUAGE_CODES, LANGUAGES, UI_LANGUAGES } from '../index';
+import { loadTranslations } from '../load';
const localesDir = path.resolve(import.meta.dirname, '../../locales');
diff --git a/core/i18n/src/index.ts b/core/i18n/src/index.ts
index 61058b9f1..03e691b4f 100644
--- a/core/i18n/src/index.ts
+++ b/core/i18n/src/index.ts
@@ -5,8 +5,6 @@
import en from '../locales/en.json';
-import { isLanguageCode } from './languages';
-
export * from './languages';
/**
@@ -29,43 +27,6 @@ export type TranslationKey = LeafKeys<typeof en>;
*/
export const englishTranslations: TranslationTree = en;
-/**
- * Import the locale file of a language. One static import per language, so bundlers that support code splitting only
- * load the language in use.
- * @param code - the language code
- */
-async function importLocale(code: string): Promise<{ default: TranslationTree }> {
- switch (code) {
- case 'da': return import('../locales/da.json');
- case 'de': return import('../locales/de.json');
- case 'es': return import('../locales/es.json');
- case 'fi': return import('../locales/fi.json');
- case 'fr': return import('../locales/fr.json');
- case 'ga': return import('../locales/ga.json');
- case 'he': return import('../locales/he.json');
- case 'hu': return import('../locales/hu.json');
- case 'id': return import('../locales/id.json');
- case 'it': return import('../locales/it.json');
- case 'nl': return import('../locales/nl.json');
- case 'pl': return import('../locales/pl.json');
- case 'pt': return import('../locales/pt.json');
- case 'ro': return import('../locales/ro.json');
- case 'ru': return import('../locales/ru.json');
- case 'sv': return import('../locales/sv.json');
- case 'uk': return import('../locales/uk.json');
- case 'zh': return import('../locales/zh.json');
- default: return { default: en };
- }
-}
-
-/**
- * Load the translations of one language, English for an unknown code.
- * @param code - the language code
- */
-export async function loadTranslations(code: string): Promise<TranslationTree> {
- return isLanguageCode(code) ? (await importLocale(code)).default : en;
-}
-
/**
* Read a value from a translation tree by its dotted key, e.g. 'common.errors.unknownError'.
* @param tree - the translation tree
diff --git a/core/i18n/src/load.ts b/core/i18n/src/load.ts
new file mode 100644
index 000000000..32e8b2f0d
--- /dev/null
+++ b/core/i18n/src/load.ts
@@ -0,0 +1,46 @@
+/**
+ * Lazy loading of the locale files for hosts with code splitting (the web app).
+ */
+
+import en from '../locales/en.json';
+
+import { isLanguageCode } from './languages';
+
+import type { TranslationTree } from './index';
+
+/**
+ * Import the locale file of a language. One static import per language, so bundlers that support code splitting only
+ * load the language in use.
+ * @param code - the language code
+ */
+async function importLocale(code: string): Promise<{ default: TranslationTree }> {
+ switch (code) {
+ case 'da': return import('../locales/da.json');
+ case 'de': return import('../locales/de.json');
+ case 'es': return import('../locales/es.json');
+ case 'fi': return import('../locales/fi.json');
+ case 'fr': return import('../locales/fr.json');
+ case 'ga': return import('../locales/ga.json');
+ case 'he': return import('../locales/he.json');
+ case 'hu': return import('../locales/hu.json');
+ case 'id': return import('../locales/id.json');
+ case 'it': return import('../locales/it.json');
+ case 'nl': return import('../locales/nl.json');
+ case 'pl': return import('../locales/pl.json');
+ case 'pt': return import('../locales/pt.json');
+ case 'ro': return import('../locales/ro.json');
+ case 'ru': return import('../locales/ru.json');
+ case 'sv': return import('../locales/sv.json');
+ case 'uk': return import('../locales/uk.json');
+ case 'zh': return import('../locales/zh.json');
+ default: return { default: en };
+ }
+}
+
+/**
+ * Load the translations of one language, English for an unknown code.
+ * @param code - the language code
+ */
+export async function loadTranslations(code: string): Promise<TranslationTree> {
+ return isLanguageCode(code) ? (await importLocale(code)).default : en;
+}