Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

perf(api): read translated catalogs from disk on first use

Hampus672a5e31bbb4
diff --git a/fluxer_api/pkgs/email/src/email_i18n/EmailI18nLocales.ts b/fluxer_api/pkgs/email/src/email_i18n/EmailI18nLocales.ts
index 43ebd0f59..821d88e8a 100644
--- a/fluxer_api/pkgs/email/src/email_i18n/EmailI18nLocales.ts
+++ b/fluxer_api/pkgs/email/src/email_i18n/EmailI18nLocales.ts
@@ -1,72 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {loadStaticLocaleFiles} from '@fluxer/i18n/src/runtime/StaticLocaleFiles';
import type {EmailTemplate, EmailTemplateKey} from '@pkgs/email/src/email_i18n/EmailI18nTypes.generated';
-import EMAIL_I18N_AR_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/ar.json' with {type: 'json'};
-import EMAIL_I18N_BG_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/bg.json' with {type: 'json'};
-import EMAIL_I18N_CS_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/cs.json' with {type: 'json'};
-import EMAIL_I18N_DA_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/da.json' with {type: 'json'};
-import EMAIL_I18N_DE_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/de.json' with {type: 'json'};
-import EMAIL_I18N_EL_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/el.json' with {type: 'json'};
-import EMAIL_I18N_EN_GB_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/en-GB.json' with {type: 'json'};
-import EMAIL_I18N_ES_419_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/es-419.json' with {type: 'json'};
-import EMAIL_I18N_ES_ES_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/es-ES.json' with {type: 'json'};
-import EMAIL_I18N_FI_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/fi.json' with {type: 'json'};
-import EMAIL_I18N_FR_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/fr.json' with {type: 'json'};
-import EMAIL_I18N_HE_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/he.json' with {type: 'json'};
-import EMAIL_I18N_HI_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/hi.json' with {type: 'json'};
-import EMAIL_I18N_HR_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/hr.json' with {type: 'json'};
-import EMAIL_I18N_HU_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/hu.json' with {type: 'json'};
-import EMAIL_I18N_ID_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/id.json' with {type: 'json'};
-import EMAIL_I18N_IT_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/it.json' with {type: 'json'};
-import EMAIL_I18N_JA_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/ja.json' with {type: 'json'};
-import EMAIL_I18N_KO_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/ko.json' with {type: 'json'};
-import EMAIL_I18N_LT_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/lt.json' with {type: 'json'};
-import EMAIL_I18N_NL_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/nl.json' with {type: 'json'};
-import EMAIL_I18N_NO_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/no.json' with {type: 'json'};
-import EMAIL_I18N_PL_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/pl.json' with {type: 'json'};
-import EMAIL_I18N_PT_BR_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/pt-BR.json' with {type: 'json'};
-import EMAIL_I18N_RO_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/ro.json' with {type: 'json'};
-import EMAIL_I18N_RU_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/ru.json' with {type: 'json'};
-import EMAIL_I18N_SV_SE_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/sv-SE.json' with {type: 'json'};
-import EMAIL_I18N_TH_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/th.json' with {type: 'json'};
-import EMAIL_I18N_TR_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/tr.json' with {type: 'json'};
-import EMAIL_I18N_UK_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/uk.json' with {type: 'json'};
-import EMAIL_I18N_VI_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/vi.json' with {type: 'json'};
-import EMAIL_I18N_ZH_CN_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/zh-CN.json' with {type: 'json'};
-import EMAIL_I18N_ZH_TW_MESSAGES from '@pkgs/email/src/email_i18n/weblate/locales/zh-TW.json' with {type: 'json'};
-export const EMAIL_I18N_LOCALE_MESSAGES = {
- ar: EMAIL_I18N_AR_MESSAGES,
- bg: EMAIL_I18N_BG_MESSAGES,
- cs: EMAIL_I18N_CS_MESSAGES,
- da: EMAIL_I18N_DA_MESSAGES,
- de: EMAIL_I18N_DE_MESSAGES,
- el: EMAIL_I18N_EL_MESSAGES,
- 'en-GB': EMAIL_I18N_EN_GB_MESSAGES,
- 'es-419': EMAIL_I18N_ES_419_MESSAGES,
- 'es-ES': EMAIL_I18N_ES_ES_MESSAGES,
- fi: EMAIL_I18N_FI_MESSAGES,
- fr: EMAIL_I18N_FR_MESSAGES,
- he: EMAIL_I18N_HE_MESSAGES,
- hi: EMAIL_I18N_HI_MESSAGES,
- hr: EMAIL_I18N_HR_MESSAGES,
- hu: EMAIL_I18N_HU_MESSAGES,
- id: EMAIL_I18N_ID_MESSAGES,
- it: EMAIL_I18N_IT_MESSAGES,
- ja: EMAIL_I18N_JA_MESSAGES,
- ko: EMAIL_I18N_KO_MESSAGES,
- lt: EMAIL_I18N_LT_MESSAGES,
- nl: EMAIL_I18N_NL_MESSAGES,
- no: EMAIL_I18N_NO_MESSAGES,
- pl: EMAIL_I18N_PL_MESSAGES,
- 'pt-BR': EMAIL_I18N_PT_BR_MESSAGES,
- ro: EMAIL_I18N_RO_MESSAGES,
- ru: EMAIL_I18N_RU_MESSAGES,
- 'sv-SE': EMAIL_I18N_SV_SE_MESSAGES,
- th: EMAIL_I18N_TH_MESSAGES,
- tr: EMAIL_I18N_TR_MESSAGES,
- uk: EMAIL_I18N_UK_MESSAGES,
- vi: EMAIL_I18N_VI_MESSAGES,
- 'zh-CN': EMAIL_I18N_ZH_CN_MESSAGES,
- 'zh-TW': EMAIL_I18N_ZH_TW_MESSAGES,
-} as const satisfies Record<string, Partial<Record<EmailTemplateKey, EmailTemplate>>>;
+export const EMAIL_I18N_LOCALE_MESSAGES = loadStaticLocaleFiles<Partial<Record<EmailTemplateKey, EmailTemplate>>>(
+ 'email',
+ new URL('./weblate/locales/', import.meta.url),
+);
diff --git a/fluxer_api/scripts/build.mjs b/fluxer_api/scripts/build.mjs
index 87be5a669..2a30bcea0 100644
--- a/fluxer_api/scripts/build.mjs
+++ b/fluxer_api/scripts/build.mjs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {readdirSync, readFileSync, rmSync} from 'node:fs';
+import {cpSync, readdirSync, readFileSync, rmSync} from 'node:fs';
import {isBuiltin} from 'node:module';
import {dirname, join, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
@@ -9,6 +9,12 @@ import {build} from 'esbuild';
const API_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const OUT_DIR = join(API_ROOT, 'dist');
const WORKSPACE_PREFIXES = ['@app/', '@pkgs/', '@fluxer/'];
+const BUNDLED_LOCALES_DIR = './locales/';
+const LOCALE_CATALOGS = {
+ errors: join(API_ROOT, '../packages/errors/src/i18n/weblate/locales'),
+ email: join(API_ROOT, 'pkgs/email/src/email_i18n/weblate/locales'),
+ content: join(API_ROOT, 'src/api/content_i18n/weblate/locales'),
+};
function packageNameOf(specifier) {
const segments = specifier.split('/');
@@ -51,9 +57,14 @@ await build({
sourcesContent: false,
logLevel: 'info',
banner: {js: '// SPDX-License-Identifier: AGPL-3.0-or-later'},
+ define: {FLUXER_BUNDLED_LOCALES_DIR: JSON.stringify(BUNDLED_LOCALES_DIR)},
plugins: [workspacePlugin],
});
+for (const [catalog, directory] of Object.entries(LOCALE_CATALOGS)) {
+ cpSync(directory, join(OUT_DIR, BUNDLED_LOCALES_DIR, catalog), {recursive: true});
+}
+
for (const file of readdirSync(OUT_DIR).filter((name) => name.endsWith('.js'))) {
const source = readFileSync(join(OUT_DIR, file), 'utf-8');
const index = source.search(/[\u0080-\uFFFF]/);
diff --git a/fluxer_api/src/api/content_i18n/ContentI18nLocales.ts b/fluxer_api/src/api/content_i18n/ContentI18nLocales.ts
index e6fde377b..012a55fb5 100644
--- a/fluxer_api/src/api/content_i18n/ContentI18nLocales.ts
+++ b/fluxer_api/src/api/content_i18n/ContentI18nLocales.ts
@@ -1,72 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import type {ContentI18nKey} from '@app/api/content_i18n/ContentI18nMessages';
-import CONTENT_I18N_AR_MESSAGES from '@app/api/content_i18n/weblate/locales/ar.json' with {type: 'json'};
-import CONTENT_I18N_BG_MESSAGES from '@app/api/content_i18n/weblate/locales/bg.json' with {type: 'json'};
-import CONTENT_I18N_CS_MESSAGES from '@app/api/content_i18n/weblate/locales/cs.json' with {type: 'json'};
-import CONTENT_I18N_DA_MESSAGES from '@app/api/content_i18n/weblate/locales/da.json' with {type: 'json'};
-import CONTENT_I18N_DE_MESSAGES from '@app/api/content_i18n/weblate/locales/de.json' with {type: 'json'};
-import CONTENT_I18N_EL_MESSAGES from '@app/api/content_i18n/weblate/locales/el.json' with {type: 'json'};
-import CONTENT_I18N_EN_GB_MESSAGES from '@app/api/content_i18n/weblate/locales/en-GB.json' with {type: 'json'};
-import CONTENT_I18N_ES_419_MESSAGES from '@app/api/content_i18n/weblate/locales/es-419.json' with {type: 'json'};
-import CONTENT_I18N_ES_ES_MESSAGES from '@app/api/content_i18n/weblate/locales/es-ES.json' with {type: 'json'};
-import CONTENT_I18N_FI_MESSAGES from '@app/api/content_i18n/weblate/locales/fi.json' with {type: 'json'};
-import CONTENT_I18N_FR_MESSAGES from '@app/api/content_i18n/weblate/locales/fr.json' with {type: 'json'};
-import CONTENT_I18N_HE_MESSAGES from '@app/api/content_i18n/weblate/locales/he.json' with {type: 'json'};
-import CONTENT_I18N_HI_MESSAGES from '@app/api/content_i18n/weblate/locales/hi.json' with {type: 'json'};
-import CONTENT_I18N_HR_MESSAGES from '@app/api/content_i18n/weblate/locales/hr.json' with {type: 'json'};
-import CONTENT_I18N_HU_MESSAGES from '@app/api/content_i18n/weblate/locales/hu.json' with {type: 'json'};
-import CONTENT_I18N_ID_MESSAGES from '@app/api/content_i18n/weblate/locales/id.json' with {type: 'json'};
-import CONTENT_I18N_IT_MESSAGES from '@app/api/content_i18n/weblate/locales/it.json' with {type: 'json'};
-import CONTENT_I18N_JA_MESSAGES from '@app/api/content_i18n/weblate/locales/ja.json' with {type: 'json'};
-import CONTENT_I18N_KO_MESSAGES from '@app/api/content_i18n/weblate/locales/ko.json' with {type: 'json'};
-import CONTENT_I18N_LT_MESSAGES from '@app/api/content_i18n/weblate/locales/lt.json' with {type: 'json'};
-import CONTENT_I18N_NL_MESSAGES from '@app/api/content_i18n/weblate/locales/nl.json' with {type: 'json'};
-import CONTENT_I18N_NO_MESSAGES from '@app/api/content_i18n/weblate/locales/no.json' with {type: 'json'};
-import CONTENT_I18N_PL_MESSAGES from '@app/api/content_i18n/weblate/locales/pl.json' with {type: 'json'};
-import CONTENT_I18N_PT_BR_MESSAGES from '@app/api/content_i18n/weblate/locales/pt-BR.json' with {type: 'json'};
-import CONTENT_I18N_RO_MESSAGES from '@app/api/content_i18n/weblate/locales/ro.json' with {type: 'json'};
-import CONTENT_I18N_RU_MESSAGES from '@app/api/content_i18n/weblate/locales/ru.json' with {type: 'json'};
-import CONTENT_I18N_SV_SE_MESSAGES from '@app/api/content_i18n/weblate/locales/sv-SE.json' with {type: 'json'};
-import CONTENT_I18N_TH_MESSAGES from '@app/api/content_i18n/weblate/locales/th.json' with {type: 'json'};
-import CONTENT_I18N_TR_MESSAGES from '@app/api/content_i18n/weblate/locales/tr.json' with {type: 'json'};
-import CONTENT_I18N_UK_MESSAGES from '@app/api/content_i18n/weblate/locales/uk.json' with {type: 'json'};
-import CONTENT_I18N_VI_MESSAGES from '@app/api/content_i18n/weblate/locales/vi.json' with {type: 'json'};
-import CONTENT_I18N_ZH_CN_MESSAGES from '@app/api/content_i18n/weblate/locales/zh-CN.json' with {type: 'json'};
-import CONTENT_I18N_ZH_TW_MESSAGES from '@app/api/content_i18n/weblate/locales/zh-TW.json' with {type: 'json'};
+import {loadStaticLocaleFiles} from '@fluxer/i18n/src/runtime/StaticLocaleFiles';
-export const CONTENT_I18N_LOCALE_MESSAGES = {
- ar: CONTENT_I18N_AR_MESSAGES,
- bg: CONTENT_I18N_BG_MESSAGES,
- cs: CONTENT_I18N_CS_MESSAGES,
- da: CONTENT_I18N_DA_MESSAGES,
- de: CONTENT_I18N_DE_MESSAGES,
- el: CONTENT_I18N_EL_MESSAGES,
- 'en-GB': CONTENT_I18N_EN_GB_MESSAGES,
- 'es-419': CONTENT_I18N_ES_419_MESSAGES,
- 'es-ES': CONTENT_I18N_ES_ES_MESSAGES,
- fi: CONTENT_I18N_FI_MESSAGES,
- fr: CONTENT_I18N_FR_MESSAGES,
- he: CONTENT_I18N_HE_MESSAGES,
- hi: CONTENT_I18N_HI_MESSAGES,
- hr: CONTENT_I18N_HR_MESSAGES,
- hu: CONTENT_I18N_HU_MESSAGES,
- id: CONTENT_I18N_ID_MESSAGES,
- it: CONTENT_I18N_IT_MESSAGES,
- ja: CONTENT_I18N_JA_MESSAGES,
- ko: CONTENT_I18N_KO_MESSAGES,
- lt: CONTENT_I18N_LT_MESSAGES,
- nl: CONTENT_I18N_NL_MESSAGES,
- no: CONTENT_I18N_NO_MESSAGES,
- pl: CONTENT_I18N_PL_MESSAGES,
- 'pt-BR': CONTENT_I18N_PT_BR_MESSAGES,
- ro: CONTENT_I18N_RO_MESSAGES,
- ru: CONTENT_I18N_RU_MESSAGES,
- 'sv-SE': CONTENT_I18N_SV_SE_MESSAGES,
- th: CONTENT_I18N_TH_MESSAGES,
- tr: CONTENT_I18N_TR_MESSAGES,
- uk: CONTENT_I18N_UK_MESSAGES,
- vi: CONTENT_I18N_VI_MESSAGES,
- 'zh-CN': CONTENT_I18N_ZH_CN_MESSAGES,
- 'zh-TW': CONTENT_I18N_ZH_TW_MESSAGES,
-} as const satisfies Record<string, Partial<Record<ContentI18nKey, string>>>;
+export const CONTENT_I18N_LOCALE_MESSAGES = loadStaticLocaleFiles<Partial<Record<ContentI18nKey, string>>>(
+ 'content',
+ new URL('./weblate/locales/', import.meta.url),
+);
diff --git a/packages/errors/src/i18n/ErrorI18nLocales.ts b/packages/errors/src/i18n/ErrorI18nLocales.ts
index 885ec68e3..606e16f7c 100644
--- a/packages/errors/src/i18n/ErrorI18nLocales.ts
+++ b/packages/errors/src/i18n/ErrorI18nLocales.ts
@@ -1,72 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import type {ErrorI18nKey} from '@fluxer/errors/src/i18n/ErrorI18nMessages';
-import ERROR_I18N_AR_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/ar.json' with {type: 'json'};
-import ERROR_I18N_BG_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/bg.json' with {type: 'json'};
-import ERROR_I18N_CS_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/cs.json' with {type: 'json'};
-import ERROR_I18N_DA_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/da.json' with {type: 'json'};
-import ERROR_I18N_DE_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/de.json' with {type: 'json'};
-import ERROR_I18N_EL_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/el.json' with {type: 'json'};
-import ERROR_I18N_EN_GB_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/en-GB.json' with {type: 'json'};
-import ERROR_I18N_ES_419_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/es-419.json' with {type: 'json'};
-import ERROR_I18N_ES_ES_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/es-ES.json' with {type: 'json'};
-import ERROR_I18N_FI_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/fi.json' with {type: 'json'};
-import ERROR_I18N_FR_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/fr.json' with {type: 'json'};
-import ERROR_I18N_HE_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/he.json' with {type: 'json'};
-import ERROR_I18N_HI_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/hi.json' with {type: 'json'};
-import ERROR_I18N_HR_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/hr.json' with {type: 'json'};
-import ERROR_I18N_HU_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/hu.json' with {type: 'json'};
-import ERROR_I18N_ID_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/id.json' with {type: 'json'};
-import ERROR_I18N_IT_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/it.json' with {type: 'json'};
-import ERROR_I18N_JA_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/ja.json' with {type: 'json'};
-import ERROR_I18N_KO_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/ko.json' with {type: 'json'};
-import ERROR_I18N_LT_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/lt.json' with {type: 'json'};
-import ERROR_I18N_NL_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/nl.json' with {type: 'json'};
-import ERROR_I18N_NO_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/no.json' with {type: 'json'};
-import ERROR_I18N_PL_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/pl.json' with {type: 'json'};
-import ERROR_I18N_PT_BR_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/pt-BR.json' with {type: 'json'};
-import ERROR_I18N_RO_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/ro.json' with {type: 'json'};
-import ERROR_I18N_RU_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/ru.json' with {type: 'json'};
-import ERROR_I18N_SV_SE_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/sv-SE.json' with {type: 'json'};
-import ERROR_I18N_TH_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/th.json' with {type: 'json'};
-import ERROR_I18N_TR_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/tr.json' with {type: 'json'};
-import ERROR_I18N_UK_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/uk.json' with {type: 'json'};
-import ERROR_I18N_VI_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/vi.json' with {type: 'json'};
-import ERROR_I18N_ZH_CN_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/zh-CN.json' with {type: 'json'};
-import ERROR_I18N_ZH_TW_MESSAGES from '@fluxer/errors/src/i18n/weblate/locales/zh-TW.json' with {type: 'json'};
+import {loadStaticLocaleFiles} from '@fluxer/i18n/src/runtime/StaticLocaleFiles';
-export const ERROR_I18N_LOCALE_MESSAGES = {
- ar: ERROR_I18N_AR_MESSAGES,
- bg: ERROR_I18N_BG_MESSAGES,
- cs: ERROR_I18N_CS_MESSAGES,
- da: ERROR_I18N_DA_MESSAGES,
- de: ERROR_I18N_DE_MESSAGES,
- el: ERROR_I18N_EL_MESSAGES,
- 'en-GB': ERROR_I18N_EN_GB_MESSAGES,
- 'es-419': ERROR_I18N_ES_419_MESSAGES,
- 'es-ES': ERROR_I18N_ES_ES_MESSAGES,
- fi: ERROR_I18N_FI_MESSAGES,
- fr: ERROR_I18N_FR_MESSAGES,
- he: ERROR_I18N_HE_MESSAGES,
- hi: ERROR_I18N_HI_MESSAGES,
- hr: ERROR_I18N_HR_MESSAGES,
- hu: ERROR_I18N_HU_MESSAGES,
- id: ERROR_I18N_ID_MESSAGES,
- it: ERROR_I18N_IT_MESSAGES,
- ja: ERROR_I18N_JA_MESSAGES,
- ko: ERROR_I18N_KO_MESSAGES,
- lt: ERROR_I18N_LT_MESSAGES,
- nl: ERROR_I18N_NL_MESSAGES,
- no: ERROR_I18N_NO_MESSAGES,
- pl: ERROR_I18N_PL_MESSAGES,
- 'pt-BR': ERROR_I18N_PT_BR_MESSAGES,
- ro: ERROR_I18N_RO_MESSAGES,
- ru: ERROR_I18N_RU_MESSAGES,
- 'sv-SE': ERROR_I18N_SV_SE_MESSAGES,
- th: ERROR_I18N_TH_MESSAGES,
- tr: ERROR_I18N_TR_MESSAGES,
- uk: ERROR_I18N_UK_MESSAGES,
- vi: ERROR_I18N_VI_MESSAGES,
- 'zh-CN': ERROR_I18N_ZH_CN_MESSAGES,
- 'zh-TW': ERROR_I18N_ZH_TW_MESSAGES,
-} as const satisfies Record<string, Partial<Record<ErrorI18nKey, string>>>;
+export const ERROR_I18N_LOCALE_MESSAGES = loadStaticLocaleFiles<Partial<Record<ErrorI18nKey, string>>>(
+ 'errors',
+ new URL('./weblate/locales/', import.meta.url),
+);
diff --git a/packages/i18n/scripts/SyncStaticI18nCatalogs.ts b/packages/i18n/scripts/SyncStaticI18nCatalogs.ts
index d7a6d8df0..96e7f3cad 100644
--- a/packages/i18n/scripts/SyncStaticI18nCatalogs.ts
+++ b/packages/i18n/scripts/SyncStaticI18nCatalogs.ts
@@ -5,6 +5,7 @@ import * as fs from 'node:fs';
import * as path from 'node:path';
import {fileURLToPath, pathToFileURL} from 'node:url';
import {parseArgs} from 'node:util';
+import {STATIC_I18N_LOCALES, type StaticI18nLocale} from '@fluxer/i18n/src/runtime/StaticLocaleFiles';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -58,7 +59,7 @@ function ensureDir(dir: string): void {
fs.mkdirSync(dir, {recursive: true});
}
-function jsonPath(config: StaticCatalogConfig, locale?: StaticLocale): string {
+function jsonPath(config: StaticCatalogConfig, locale?: StaticI18nLocale): string {
if (!locale) {
return path.join(config.weblateDir, 'messages.json');
}
diff --git a/packages/i18n/src/runtime/StaticLocaleFiles.ts b/packages/i18n/src/runtime/StaticLocaleFiles.ts
new file mode 100644
index 000000000..ea8359d8a
--- /dev/null
+++ b/packages/i18n/src/runtime/StaticLocaleFiles.ts
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import {readFileSync} from 'node:fs';
+
+declare const FLUXER_BUNDLED_LOCALES_DIR: string | undefined;
+
+export const STATIC_I18N_LOCALES = [
+ 'ar',
+ 'bg',
+ 'cs',
+ 'da',
+ 'de',
+ 'el',
+ 'en-GB',
+ 'es-419',
+ 'es-ES',
+ 'fi',
+ 'fr',
+ 'he',
+ 'hi',
+ 'hr',
+ 'hu',
+ 'id',
+ 'it',
+ 'ja',
+ 'ko',
+ 'lt',
+ 'nl',
+ 'no',
+ 'pl',
+ 'pt-BR',
+ 'ro',
+ 'ru',
+ 'sv-SE',
+ 'th',
+ 'tr',
+ 'uk',
+ 'vi',
+ 'zh-CN',
+ 'zh-TW',
+] as const;
+
+export type StaticI18nLocale = (typeof STATIC_I18N_LOCALES)[number];
+
+function catalogDirectory(catalog: string, sourceDirectory: URL): URL {
+ if (typeof FLUXER_BUNDLED_LOCALES_DIR === 'string') {
+ return new URL(`${FLUXER_BUNDLED_LOCALES_DIR}${catalog}/`, import.meta.url);
+ }
+ return sourceDirectory;
+}
+
+export function loadStaticLocaleFiles<T>(catalog: string, sourceDirectory: URL): Record<StaticI18nLocale, T> {
+ const directory = catalogDirectory(catalog, sourceDirectory);
+ const messages = {} as Record<StaticI18nLocale, T>;
+ for (const locale of STATIC_I18N_LOCALES) {
+ Object.defineProperty(messages, locale, {
+ configurable: true,
+ enumerable: true,
+ get() {
+ const value = JSON.parse(readFileSync(new URL(`${locale}.json`, directory), 'utf8')) as T;
+ Object.defineProperty(messages, locale, {enumerable: true, value});
+ return value;
+ },
+ });
+ }
+ return messages;
+}