Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor languages.json to separate UI languages from total list used for e.g. identity generator as well (#2437)
Leendert de Borstf065466d4131
diff --git a/core/i18n/languages.json b/core/i18n/languages.jsonindex 0ad8a31c5..b4c63b614 100644--- a/core/i18n/languages.json+++ b/core/i18n/languages.json@@ -1,23 +1,26 @@-[- {"code": "en", "flag": "🇺🇸", "label": "English", "ui": true, "alternativeCodes": ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]},- {"code": "da", "flag": "🇩🇰", "label": "Dansk", "ui": true, "alternativeCodes": ["da-DK"]},- {"code": "de", "flag": "🇩🇪", "label": "Deutsch", "ui": true, "alternativeCodes": ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]},- {"code": "es", "flag": "🇪🇸", "label": "Español", "ui": true, "alternativeCodes": ["es-ES", "es-MX", "es-AR", "es-CO", "es-CL", "es-PE", "es-VE", "es-EC", "es-GT", "es-CU", "es-BO", "es-DO", "es-HN", "es-PY", "es-SV", "es-NI", "es-CR", "es-PA", "es-UY", "es-PR"]},- {"code": "fa", "flag": "🇮🇷", "label": "فارسی", "ui": false, "alternativeCodes": ["fa-IR", "fa-AF"]},- {"code": "fi", "flag": "🇫🇮", "label": "Suomi", "ui": true, "alternativeCodes": ["fi-FI"]},- {"code": "fr", "flag": "🇫🇷", "label": "Français", "ui": true, "alternativeCodes": ["fr-FR", "fr-CA", "fr-BE", "fr-CH", "fr-LU", "fr-MC"]},- {"code": "ga", "flag": "🇮🇪", "label": "Gaeilge", "ui": true, "alternativeCodes": ["ga-IE"]},- {"code": "he", "flag": "🇮🇱", "label": "עברית", "ui": true, "alternativeCodes": ["he-IL"]},- {"code": "hu", "flag": "🇭🇺", "label": "Magyar", "ui": true, "alternativeCodes": ["hu-HU"]},- {"code": "id", "flag": "🇮🇩", "label": "Bahasa Indonesia", "ui": true, "alternativeCodes": ["id-ID"]},- {"code": "it", "flag": "🇮🇹", "label": "Italiano", "ui": true, "alternativeCodes": ["it-IT", "it-CH", "it-SM", "it-VA"]},- {"code": "nl", "flag": "🇳🇱", "label": "Nederlands", "ui": true, "alternativeCodes": ["nl-NL", "nl-BE"]},- {"code": "pl", "flag": "🇵🇱", "label": "Polski", "ui": true, "alternativeCodes": ["pl-PL"]},- {"code": "pt", "flag": "🇧🇷", "label": "Português Brasileiro", "ui": true, "alternativeCodes": ["pt-BR", "pt-PT"]},- {"code": "ro", "flag": "🇷🇴", "label": "Română", "ui": true, "alternativeCodes": ["ro-RO", "ro-MD"]},- {"code": "ru", "flag": "🇷🇺", "label": "Русский", "ui": true, "alternativeCodes": ["ru-RU", "ru-BY", "ru-KZ", "ru-UA"]},- {"code": "sv", "flag": "🇸🇪", "label": "Svenska", "ui": true, "alternativeCodes": ["sv-SE", "sv-FI"]},- {"code": "uk", "flag": "🇺🇦", "label": "Українська", "ui": true, "alternativeCodes": ["uk-UA"]},- {"code": "ur", "flag": "🇵🇰", "label": "اردو", "ui": false, "alternativeCodes": ["ur-PK", "ur-IN"]},- {"code": "zh", "flag": "🇨🇳", "label": "简体中文", "ui": true, "alternativeCodes": ["zh-CN", "zh-SG", "zh-Hans", "zh-TW", "zh-HK", "zh-MO", "zh-Hant"]}-]+{+ "uiLanguages": ["en", "da", "de", "es", "fi", "fr", "ga", "he", "hu", "id", "it", "nl", "pl", "pt", "ro", "ru", "sv", "uk", "zh"],+ "languages": [+ {"code": "en", "flag": "🇺🇸", "label": "English", "alternativeCodes": ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]},+ {"code": "da", "flag": "🇩🇰", "label": "Dansk", "alternativeCodes": ["da-DK"]},+ {"code": "de", "flag": "🇩🇪", "label": "Deutsch", "alternativeCodes": ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]},+ {"code": "es", "flag": "🇪🇸", "label": "Español", "alternativeCodes": ["es-ES", "es-MX", "es-AR", "es-CO", "es-CL", "es-PE", "es-VE", "es-EC", "es-GT", "es-CU", "es-BO", "es-DO", "es-HN", "es-PY", "es-SV", "es-NI", "es-CR", "es-PA", "es-UY", "es-PR"]},+ {"code": "fa", "flag": "🇮🇷", "label": "فارسی", "alternativeCodes": ["fa-IR", "fa-AF"]},+ {"code": "fi", "flag": "🇫🇮", "label": "Suomi", "alternativeCodes": ["fi-FI"]},+ {"code": "fr", "flag": "🇫🇷", "label": "Français", "alternativeCodes": ["fr-FR", "fr-CA", "fr-BE", "fr-CH", "fr-LU", "fr-MC"]},+ {"code": "ga", "flag": "🇮🇪", "label": "Gaeilge", "alternativeCodes": ["ga-IE"]},+ {"code": "he", "flag": "🇮🇱", "label": "עברית", "alternativeCodes": ["he-IL"]},+ {"code": "hu", "flag": "🇭🇺", "label": "Magyar", "alternativeCodes": ["hu-HU"]},+ {"code": "id", "flag": "🇮🇩", "label": "Bahasa Indonesia", "alternativeCodes": ["id-ID"]},+ {"code": "it", "flag": "🇮🇹", "label": "Italiano", "alternativeCodes": ["it-IT", "it-CH", "it-SM", "it-VA"]},+ {"code": "nl", "flag": "🇳🇱", "label": "Nederlands", "alternativeCodes": ["nl-NL", "nl-BE"]},+ {"code": "pl", "flag": "🇵🇱", "label": "Polski", "alternativeCodes": ["pl-PL"]},+ {"code": "pt", "flag": "🇧🇷", "label": "Português Brasileiro", "alternativeCodes": ["pt-BR", "pt-PT"]},+ {"code": "ro", "flag": "🇷🇴", "label": "Română", "alternativeCodes": ["ro-RO", "ro-MD"]},+ {"code": "ru", "flag": "🇷🇺", "label": "Русский", "alternativeCodes": ["ru-RU", "ru-BY", "ru-KZ", "ru-UA"]},+ {"code": "sv", "flag": "🇸🇪", "label": "Svenska", "alternativeCodes": ["sv-SE", "sv-FI"]},+ {"code": "uk", "flag": "🇺🇦", "label": "Українська", "alternativeCodes": ["uk-UA"]},+ {"code": "ur", "flag": "🇵🇰", "label": "اردو", "alternativeCodes": ["ur-PK", "ur-IN"]},+ {"code": "zh", "flag": "🇨🇳", "label": "简体中文", "alternativeCodes": ["zh-CN", "zh-SG", "zh-Hans", "zh-TW", "zh-HK", "zh-MO", "zh-Hant"]}+ ]+}diff --git a/core/i18n/scripts/export-native.mjs b/core/i18n/scripts/export-native.mjsindex 42e22d79b..6f91b762c 100644--- a/core/i18n/scripts/export-native.mjs+++ b/core/i18n/scripts/export-native.mjs@@ -6,7 +6,7 @@* node core/i18n/scripts/export-native.mjs # write the files* node core/i18n/scripts/export-native.mjs --check # exit 1 when a generated file is out of date*- * Languages are the UI languages (`ui: true`) in core/i18n/languages.json. A missing translation falls back to English.+ * Languages are the `uiLanguages` in core/i18n/languages.json. A missing translation falls back to English.*/import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';@@ -18,7 +18,7 @@ const REPO_ROOT = path.resolve(I18N_DIR, '../..');const CHECK = process.argv.includes('--check');const GENERATED_NOTE = 'Generated from core/i18n/locales by core/i18n/scripts/export-native.mjs. Do not edit, change core/i18n instead.';-const languages = JSON.parse(readFileSync(path.join(I18N_DIR, 'languages.json'), 'utf8')).filter((language) => language.ui).map((language) => language.code);+const languages = JSON.parse(readFileSync(path.join(I18N_DIR, 'languages.json'), 'utf8')).uiLanguages;const { targets } = JSON.parse(readFileSync(path.join(I18N_DIR, 'exports/mobile-native.json'), 'utf8'));const locales = Object.fromEntries(languages.map((lang) => [lang, JSON.parse(readFileSync(path.join(I18N_DIR, `locales/${lang}.json`), 'utf8'))]));diff --git a/core/i18n/src/__tests__/registry.test.ts b/core/i18n/src/__tests__/registry.test.tsindex 521714b38..13517ef79 100644--- a/core/i18n/src/__tests__/registry.test.ts+++ b/core/i18n/src/__tests__/registry.test.ts@@ -4,7 +4,7 @@ import path from 'node:path';import { describe, expect, it } from 'vitest';import { ALL_TRANSLATIONS } from '../all';-import { DEFAULT_LANGUAGE, LANGUAGE_CODES, LANGUAGES, loadTranslations } from '../index';+import { DEFAULT_LANGUAGE, LANGUAGE_CODES, LANGUAGES, UI_LANGUAGES, loadTranslations } from '../index';const localesDir = path.resolve(import.meta.dirname, '../../locales');@@ -12,6 +12,14 @@ describe('language registry', () => {it('lists English first and every code once', () => {expect(LANGUAGE_CODES[0]).toBe(DEFAULT_LANGUAGE);expect(new Set(LANGUAGES.map((l) => l.code)).size).toBe(LANGUAGES.length);+ expect(new Set(LANGUAGE_CODES).size).toBe(LANGUAGE_CODES.length);+ });++ it('has display info for every UI language', () => {+ for (const code of LANGUAGE_CODES) {+ expect(LANGUAGES.some((l) => l.code === code), `languages entry for ${code}`).toBe(true);+ }+ expect(UI_LANGUAGES.map((l) => l.code)).toEqual(LANGUAGE_CODES);});it('has a locale file, a loader and a bundled entry for every UI language', async () => {diff --git a/core/i18n/src/languages.ts b/core/i18n/src/languages.tsindex 2654ef123..c26fd4922 100644--- a/core/i18n/src/languages.ts+++ b/core/i18n/src/languages.ts@@ -1,10 +1,11 @@/**- * Language reference shared by all AliasVault clients. ../languages.json is the single list of known languages:- * flag, native label, the BCP-47 region variants that map onto each code, and whether the apps offer it as a UI- * language (`ui`). Languages with `ui: false` are only used by features such as the identity generator.+ * Language reference shared by all AliasVault clients, read from ../languages.json:+ * - `languages`: display info (flag, native label, BCP-47 region variants) for every language code any feature can+ * return, e.g. the identity generator and Diceware languages that come from the Rust core.+ * - `uiLanguages`: the languages the apps are translated into (a locale file in ../locales), English first.*/-import languages from '../languages.json' with { type: 'json' };+import languageData from '../languages.json' with { type: 'json' };/*** Display metadata for a single language.@@ -16,8 +17,6 @@ export interface ILanguageInfo {flag: string;/** Native display label. */label: string;- /** Whether the apps offer this language as UI language (translated in Crowdin). */- ui?: boolean;/** Alternative locale codes (BCP-47 language-region tags) that map onto this language. */alternativeCodes?: string[];}@@ -28,20 +27,20 @@ export interface ILanguageInfo {export const DEFAULT_LANGUAGE = 'en';/**- * Every known language.+ * Display info of every known language, UI language or not.*/-export const LANGUAGES: ILanguageInfo[] = languages;+export const LANGUAGES: ILanguageInfo[] = languageData.languages;/**- * The UI languages the apps offer, English first. Keep in sync with the target languages in the Crowdin project+ * The codes of the UI languages the apps offer, English first. Keep in sync with the target languages in the Crowdin project* settings.*/-export const UI_LANGUAGES: ILanguageInfo[] = LANGUAGES.filter((language) => language.ui);+export const LANGUAGE_CODES: string[] = languageData.uiLanguages;/**- * The codes of the UI languages.+ * Display info of the UI languages, in {@link LANGUAGE_CODES} order.*/-export const LANGUAGE_CODES: string[] = UI_LANGUAGES.map((language) => language.code);+export const UI_LANGUAGES: ILanguageInfo[] = LANGUAGE_CODES.map((code) => LANGUAGES.find((language) => language.code === code) ?? { code, flag: '🌐', label: code });/*** Whether a code is one of the UI languages.