Skip to content

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

Add shared language references (#776)

Leendert de Borstbb5fac1df0b4
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordConfigForm.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordConfigForm.tsx
index f2691ae19..b64b0d46f 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordConfigForm.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/PasswordConfigForm.tsx
@@ -1,8 +1,7 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
-import { getDicewareLanguageDisplay, DEFAULT_DICEWARE_LANGUAGE } from '@/utils/DicewareLanguages';
-import { MIN_WORD_COUNT, MAX_WORD_COUNT, DEFAULT_WORD_COUNT } from '@/utils/dist/core/models/defaults';
+import { MIN_WORD_COUNT, MAX_WORD_COUNT, DEFAULT_WORD_COUNT, DEFAULT_LANGUAGE_CODE, getLanguageInfo } from '@/utils/dist/core/models/defaults';
import type {
PasswordSettings,
PasswordGeneratorType,
@@ -104,7 +103,7 @@ const PasswordConfigForm: React.FC<IPasswordConfigFormProps> = ({
const { t } = useTranslation();
const isDiceware = (settings.Type ?? 'basic') === 'diceware';
- const currentLanguage = settings.Language ?? DEFAULT_DICEWARE_LANGUAGE;
+ const currentLanguage = settings.Language ?? DEFAULT_LANGUAGE_CODE;
/**
* Human label for a Diceware option value (used in button tooltips).
@@ -306,7 +305,7 @@ const PasswordConfigForm: React.FC<IPasswordConfigFormProps> = ({
className="w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md text-gray-900 dark:text-white focus:ring-primary-500 focus:border-primary-500"
>
{dicewareLanguages.map((code) => {
- const { flag, label } = getDicewareLanguageDisplay(code);
+ const { flag, label } = getLanguageInfo(code);
return (
<option key={code} value={code}>
{flag} {label}
diff --git a/apps/browser-extension/src/utils/RustCore.ts b/apps/browser-extension/src/utils/RustCore.ts
index 5d7059413..010d75694 100644
--- a/apps/browser-extension/src/utils/RustCore.ts
+++ b/apps/browser-extension/src/utils/RustCore.ts
@@ -75,13 +75,13 @@ export async function generatePassword(settings: PasswordSettings, seed?: string
}
/**
- * Get the list of bundled Diceware wordlist language codes (first is the default, English).
+ * Get the list of bundled Diceware wordlist language ISO codes (first is the default, 'en').
* The set is owned by the Rust core; unknown codes fall back to English during generation.
*/
export async function getDicewareLanguages(): Promise<string[]> {
await initRustCore();
const languages = core.getDicewareLanguages() as string[];
- return languages.length > 0 ? languages : ['English'];
+ return languages.length > 0 ? languages : ['en'];
}
/**
diff --git a/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts b/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts
index b24e533e8..8e7a88d4e 100644
--- a/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts
+++ b/apps/browser-extension/src/utils/db/repositories/SettingsRepository.ts
@@ -1,5 +1,4 @@
-import { defaultDicewareLanguageForApp } from '@/utils/DicewareLanguages';
-import { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT } from '@/utils/dist/core/models/defaults';
+import { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, DEFAULT_LANGUAGE_CODE } from '@/utils/dist/core/models/defaults';
import type { EncryptionKey, PasswordSettings, TotpCode, Attachment } from '@/utils/dist/core/models/vault';
import { BaseRepository } from '../BaseRepository';
@@ -70,7 +69,7 @@ export class SettingsRepository extends BaseRepository {
UseNonAmbiguousChars: false,
Type: 'basic',
WordCount: DEFAULT_WORD_COUNT,
- Language: defaultDicewareLanguageForApp(navigator.language),
+ Language: DEFAULT_LANGUAGE_CODE,
Capitalization: 'Lowercase',
Separator: 'Dash',
Salt: 'None'
diff --git a/apps/browser-extension/src/utils/dist/core/models/defaults/index.d.ts b/apps/browser-extension/src/utils/dist/core/models/defaults/index.d.ts
index 9a56cdf42..2c5e628a2 100644
--- a/apps/browser-extension/src/utils/dist/core/models/defaults/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/core/models/defaults/index.d.ts
@@ -21,4 +21,49 @@ declare const MIN_WORD_COUNT = 3;
/** Maximum number of words (also the hard cap enforced by the generator). */
declare const MAX_WORD_COUNT = 10;
-export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
+/**
+ * Generic, cross-platform language reference: maps a two-letter ISO 639-1 code to a flag and a
+ * native display label.
+ */
+/**
+ * Display metadata for a single language.
+ */
+interface ILanguageInfo {
+ /** Two-letter ISO 639-1 language code (e.g. 'en', 'nl'). */
+ code: string;
+ /** Emoji flag for the language. */
+ flag: string;
+ /** Native display label. */
+ label: string;
+}
+/** Default ISO language code used as the universal fallback. */
+declare const DEFAULT_LANGUAGE_CODE = "en";
+/**
+ * Known languages keyed by ISO 639-1 code, with a flag and native label.
+ * Covers the AliasVault app UI languages so this list can be reused beyond a single feature.
+ */
+declare const LANGUAGES: ILanguageInfo[];
+/**
+ * Normalize an app/UI language tag to a two-letter lowercase ISO code (e.g. 'nl-NL' -> 'nl').
+ * @param code The language tag.
+ * @returns The two-letter lowercase code.
+ */
+declare function normalizeLanguageCode(code: string | null | undefined): string;
+/**
+ * Look up the display metadata for an ISO language code.
+ * Falls back to a globe flag and the raw code for unknown languages.
+ * @param code The ISO language code (case-insensitive).
+ * @returns The flag + label info for the code.
+ */
+declare function getLanguageInfo(code: string): ILanguageInfo;
+/**
+ * Resolve a default language code for an app/UI language, restricted to a set of available codes
+ * (e.g. the Diceware wordlist languages returned by the Rust core). Returns the app language when it
+ * is available, otherwise the first available code, otherwise English.
+ * @param appLanguage The app/UI language tag.
+ * @param availableCodes The codes the feature actually supports.
+ * @returns The resolved ISO code.
+ */
+declare function resolveDefaultLanguage(appLanguage: string | null | undefined, availableCodes: string[]): string;
+
+export { DEFAULT_LANGUAGE_CODE, DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, type ILanguageInfo, LANGUAGES, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT, getLanguageInfo, normalizeLanguageCode, resolveDefaultLanguage };
diff --git a/apps/browser-extension/src/utils/dist/core/models/defaults/index.js b/apps/browser-extension/src/utils/dist/core/models/defaults/index.js
index fa6095500..a261ea496 100644
--- a/apps/browser-extension/src/utils/dist/core/models/defaults/index.js
+++ b/apps/browser-extension/src/utils/dist/core/models/defaults/index.js
@@ -10,4 +10,40 @@ var DEFAULT_WORD_COUNT = 5;
var MIN_WORD_COUNT = 3;
var MAX_WORD_COUNT = 10;
-export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
+// src/defaults/Languages.ts
+var DEFAULT_LANGUAGE_CODE = "en";
+var LANGUAGES = [
+ { code: "en", flag: "\u{1F1EC}\u{1F1E7}", label: "English" },
+ { code: "nl", flag: "\u{1F1F3}\u{1F1F1}", label: "Nederlands" },
+ { code: "de", flag: "\u{1F1E9}\u{1F1EA}", label: "Deutsch" },
+ { code: "fr", flag: "\u{1F1EB}\u{1F1F7}", label: "Fran\xE7ais" },
+ { code: "es", flag: "\u{1F1EA}\u{1F1F8}", label: "Espa\xF1ol" },
+ { code: "it", flag: "\u{1F1EE}\u{1F1F9}", label: "Italiano" },
+ { code: "da", flag: "\u{1F1E9}\u{1F1F0}", label: "Dansk" },
+ { code: "fi", flag: "\u{1F1EB}\u{1F1EE}", label: "Suomi" },
+ { code: "he", flag: "\u{1F1EE}\u{1F1F1}", label: "\u05E2\u05D1\u05E8\u05D9\u05EA" },
+ { code: "pl", flag: "\u{1F1F5}\u{1F1F1}", label: "Polski" },
+ { code: "pt", flag: "\u{1F1E7}\u{1F1F7}", label: "Portugu\xEAs" },
+ { code: "ro", flag: "\u{1F1F7}\u{1F1F4}", label: "Rom\xE2n\u0103" },
+ { code: "ru", flag: "\u{1F1F7}\u{1F1FA}", label: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439" },
+ { code: "sv", flag: "\u{1F1F8}\u{1F1EA}", label: "Svenska" },
+ { code: "uk", flag: "\u{1F1FA}\u{1F1E6}", label: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430" },
+ { code: "zh", flag: "\u{1F1E8}\u{1F1F3}", label: "\u4E2D\u6587" }
+];
+function normalizeLanguageCode(code) {
+ return (code ?? "").slice(0, 2).toLowerCase();
+}
+function getLanguageInfo(code) {
+ const iso = normalizeLanguageCode(code);
+ const match = LANGUAGES.find((l) => l.code === iso);
+ return match ?? { code, flag: "\u{1F310}", label: code };
+}
+function resolveDefaultLanguage(appLanguage, availableCodes) {
+ const iso = normalizeLanguageCode(appLanguage);
+ if (availableCodes.some((c) => c.toLowerCase() === iso)) {
+ return iso;
+ }
+ return availableCodes[0] ?? DEFAULT_LANGUAGE_CODE;
+}
+
+export { DEFAULT_LANGUAGE_CODE, DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, LANGUAGES, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT, getLanguageInfo, normalizeLanguageCode, resolveDefaultLanguage };
diff --git a/apps/mobile-app/utils/dist/core/models/defaults/index.d.ts b/apps/mobile-app/utils/dist/core/models/defaults/index.d.ts
index 9a56cdf42..2c5e628a2 100644
--- a/apps/mobile-app/utils/dist/core/models/defaults/index.d.ts
+++ b/apps/mobile-app/utils/dist/core/models/defaults/index.d.ts
@@ -21,4 +21,49 @@ declare const MIN_WORD_COUNT = 3;
/** Maximum number of words (also the hard cap enforced by the generator). */
declare const MAX_WORD_COUNT = 10;
-export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
+/**
+ * Generic, cross-platform language reference: maps a two-letter ISO 639-1 code to a flag and a
+ * native display label.
+ */
+/**
+ * Display metadata for a single language.
+ */
+interface ILanguageInfo {
+ /** Two-letter ISO 639-1 language code (e.g. 'en', 'nl'). */
+ code: string;
+ /** Emoji flag for the language. */
+ flag: string;
+ /** Native display label. */
+ label: string;
+}
+/** Default ISO language code used as the universal fallback. */
+declare const DEFAULT_LANGUAGE_CODE = "en";
+/**
+ * Known languages keyed by ISO 639-1 code, with a flag and native label.
+ * Covers the AliasVault app UI languages so this list can be reused beyond a single feature.
+ */
+declare const LANGUAGES: ILanguageInfo[];
+/**
+ * Normalize an app/UI language tag to a two-letter lowercase ISO code (e.g. 'nl-NL' -> 'nl').
+ * @param code The language tag.
+ * @returns The two-letter lowercase code.
+ */
+declare function normalizeLanguageCode(code: string | null | undefined): string;
+/**
+ * Look up the display metadata for an ISO language code.
+ * Falls back to a globe flag and the raw code for unknown languages.
+ * @param code The ISO language code (case-insensitive).
+ * @returns The flag + label info for the code.
+ */
+declare function getLanguageInfo(code: string): ILanguageInfo;
+/**
+ * Resolve a default language code for an app/UI language, restricted to a set of available codes
+ * (e.g. the Diceware wordlist languages returned by the Rust core). Returns the app language when it
+ * is available, otherwise the first available code, otherwise English.
+ * @param appLanguage The app/UI language tag.
+ * @param availableCodes The codes the feature actually supports.
+ * @returns The resolved ISO code.
+ */
+declare function resolveDefaultLanguage(appLanguage: string | null | undefined, availableCodes: string[]): string;
+
+export { DEFAULT_LANGUAGE_CODE, DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, type ILanguageInfo, LANGUAGES, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT, getLanguageInfo, normalizeLanguageCode, resolveDefaultLanguage };
diff --git a/apps/mobile-app/utils/dist/core/models/defaults/index.js b/apps/mobile-app/utils/dist/core/models/defaults/index.js
index fa6095500..a261ea496 100644
--- a/apps/mobile-app/utils/dist/core/models/defaults/index.js
+++ b/apps/mobile-app/utils/dist/core/models/defaults/index.js
@@ -10,4 +10,40 @@ var DEFAULT_WORD_COUNT = 5;
var MIN_WORD_COUNT = 3;
var MAX_WORD_COUNT = 10;
-export { DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT };
+// src/defaults/Languages.ts
+var DEFAULT_LANGUAGE_CODE = "en";
+var LANGUAGES = [
+ { code: "en", flag: "\u{1F1EC}\u{1F1E7}", label: "English" },
+ { code: "nl", flag: "\u{1F1F3}\u{1F1F1}", label: "Nederlands" },
+ { code: "de", flag: "\u{1F1E9}\u{1F1EA}", label: "Deutsch" },
+ { code: "fr", flag: "\u{1F1EB}\u{1F1F7}", label: "Fran\xE7ais" },
+ { code: "es", flag: "\u{1F1EA}\u{1F1F8}", label: "Espa\xF1ol" },
+ { code: "it", flag: "\u{1F1EE}\u{1F1F9}", label: "Italiano" },
+ { code: "da", flag: "\u{1F1E9}\u{1F1F0}", label: "Dansk" },
+ { code: "fi", flag: "\u{1F1EB}\u{1F1EE}", label: "Suomi" },
+ { code: "he", flag: "\u{1F1EE}\u{1F1F1}", label: "\u05E2\u05D1\u05E8\u05D9\u05EA" },
+ { code: "pl", flag: "\u{1F1F5}\u{1F1F1}", label: "Polski" },
+ { code: "pt", flag: "\u{1F1E7}\u{1F1F7}", label: "Portugu\xEAs" },
+ { code: "ro", flag: "\u{1F1F7}\u{1F1F4}", label: "Rom\xE2n\u0103" },
+ { code: "ru", flag: "\u{1F1F7}\u{1F1FA}", label: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439" },
+ { code: "sv", flag: "\u{1F1F8}\u{1F1EA}", label: "Svenska" },
+ { code: "uk", flag: "\u{1F1FA}\u{1F1E6}", label: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430" },
+ { code: "zh", flag: "\u{1F1E8}\u{1F1F3}", label: "\u4E2D\u6587" }
+];
+function normalizeLanguageCode(code) {
+ return (code ?? "").slice(0, 2).toLowerCase();
+}
+function getLanguageInfo(code) {
+ const iso = normalizeLanguageCode(code);
+ const match = LANGUAGES.find((l) => l.code === iso);
+ return match ?? { code, flag: "\u{1F310}", label: code };
+}
+function resolveDefaultLanguage(appLanguage, availableCodes) {
+ const iso = normalizeLanguageCode(appLanguage);
+ if (availableCodes.some((c) => c.toLowerCase() === iso)) {
+ return iso;
+ }
+ return availableCodes[0] ?? DEFAULT_LANGUAGE_CODE;
+}
+
+export { DEFAULT_LANGUAGE_CODE, DEFAULT_PASSWORD_LENGTH, DEFAULT_WORD_COUNT, LANGUAGES, MAX_PASSWORD_LENGTH, MAX_WORD_COUNT, MIN_PASSWORD_LENGTH, MIN_WORD_COUNT, getLanguageInfo, normalizeLanguageCode, resolveDefaultLanguage };
diff --git a/core/models/build.sh b/core/models/build.sh
index 0f3bfb16c..b3afdcd56 100755
--- a/core/models/build.sh
+++ b/core/models/build.sh
@@ -23,6 +23,9 @@ node scripts/generate-field-keys.cjs
echo "๐Ÿ”„ Generating password-generator defaults (Rust, C#)..."
node scripts/generate-password-defaults.cjs
+echo "๐Ÿ”„ Generating language reference (C#)..."
+node scripts/generate-languages.cjs
+
dist_path="dist"
files_to_copy=("webapi" "vault" "defaults" "metadata" "icons")
diff --git a/core/models/scripts/generate-languages.cjs b/core/models/scripts/generate-languages.cjs
new file mode 100644
index 000000000..6983f5886
--- /dev/null
+++ b/core/models/scripts/generate-languages.cjs
@@ -0,0 +1,145 @@
+#!/usr/bin/env node
+/**
+ * Generates the generic language reference (ISO code -> flag + label) for the C# (Blazor) client.
+ *
+ * Input: core/models/src/defaults/Languages.ts (compiled to dist/defaults/index.js)
+ * Output: apps/server/AliasVault.Client/Main/Models/Languages.cs (C#)
+ *
+ * The TypeScript clients (browser extension + mobile) import the metadata directly from the
+ * distributed `@/utils/dist/core/models/defaults`, so only the C# variant needs to be generated.
+ */
+
+const fs = require('fs');
+const path = require('path');
+const { pathToFileURL } = require('url');
+
+const REPO_ROOT = path.join(__dirname, '../../..');
+const TS_SOURCE_REL = 'core/models/src/defaults/Languages.ts';
+const DIST_ENTRY = path.join(__dirname, '../dist/defaults/index.js');
+const CS_OUTPUT = path.join(REPO_ROOT, 'apps/server/AliasVault.Client/Main/Models/Languages.cs');
+
+/** Escape a string for embedding inside a C# double-quoted literal. */
+function csString(value) {
+ return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
+}
+
+function generateCSharp(languages, defaultCode) {
+ const tuples = languages
+ .map((l) => ` ("${csString(l.code)}", "${l.flag}", "${csString(l.label)}"),`)
+ .join('\n');
+
+ return `// <auto-generated />
+// This file is auto-generated from ${TS_SOURCE_REL}
+// Do not edit this file directly. Run 'core/models/build.sh' (or
+// 'node core/models/scripts/generate-languages.cjs') to regenerate.
+
+#nullable enable
+
+namespace AliasVault.Client.Main.Models;
+
+/// <summary>
+/// Generic language reference shared across all AliasVault clients: maps a two-letter ISO 639-1
+/// code to a flag and native label.
+/// </summary>
+public static class Languages
+{
+ /// <summary>
+ /// Default ISO language code used as the universal fallback.
+ /// </summary>
+ public const string DefaultLanguageCode = "${csString(defaultCode)}";
+
+ /// <summary>
+ /// Known languages keyed by ISO 639-1 code, with a flag and native label.
+ /// </summary>
+ private static readonly (string Code, string Flag, string Label)[] Meta =
+ [
+${tuples}
+ ];
+
+ /// <summary>
+ /// Normalize an app/UI language tag to a two-letter lowercase ISO code (e.g. "nl-NL" -> "nl").
+ /// </summary>
+ /// <param name="code">The language tag.</param>
+ /// <returns>The two-letter lowercase code.</returns>
+ public static string Normalize(string? code)
+ {
+ var value = code ?? string.Empty;
+ return (value.Length >= 2 ? value.Substring(0, 2) : value).ToLowerInvariant();
+ }
+
+ /// <summary>
+ /// Get the display label (flag + native name) for an ISO language code. Falls back to a globe
+ /// flag and the raw code for unknown languages.
+ /// </summary>
+ /// <param name="code">The ISO language code (case-insensitive).</param>
+ /// <returns>A display string such as "๐Ÿ‡ณ๐Ÿ‡ฑ Nederlands".</returns>
+ public static string GetDisplayLabel(string code)
+ {
+ var iso = Normalize(code);
+ foreach (var (metaCode, flag, label) in Meta)
+ {
+ if (metaCode == iso)
+ {
+ return $"{flag} {label}";
+ }
+ }
+
+ return $"๐ŸŒ {code}";
+ }
+
+ /// <summary>
+ /// Resolve a default language code for an app/UI language, restricted to a set of available
+ /// codes. Returns the app language when available, otherwise the first available code,
+ /// otherwise English.
+ /// </summary>
+ /// <param name="appLanguage">The app/UI language tag.</param>
+ /// <param name="availableCodes">The codes the feature actually supports.</param>
+ /// <returns>The resolved ISO code.</returns>
+ public static string ResolveDefaultLanguage(string? appLanguage, System.Collections.Generic.IReadOnlyList<string> availableCodes)
+ {
+ var iso = Normalize(appLanguage);
+ foreach (var code in availableCodes)
+ {
+ if (string.Equals(code, iso, System.StringComparison.OrdinalIgnoreCase))
+ {
+ return iso;
+ }
+ }
+
+ return availableCodes.Count > 0 ? availableCodes[0] : DefaultLanguageCode;
+ }
+}
+`;
+}
+
+function writeIfChanged(filePath, contents) {
+ const existing = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : null;
+ if (existing === contents) {
+ console.log(` โœ“ up to date: ${path.relative(REPO_ROOT, filePath)}`);
+ return;
+ }
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
+ fs.writeFileSync(filePath, contents);
+ console.log(` โœŽ wrote: ${path.relative(REPO_ROOT, filePath)}`);
+}
+
+async function main() {
+ // The dist bundle is ESM, so load it via dynamic import.
+ const mod = await import(pathToFileURL(DIST_ENTRY).href);
+ const languages = mod.LANGUAGES;
+ const defaultCode = mod.DEFAULT_LANGUAGE_CODE;
+
+ if (!Array.isArray(languages) || languages.length === 0) {
+ throw new Error(`LANGUAGES not found or empty in ${DIST_ENTRY}. Run 'npm run build' first.`);
+ }
+
+ console.log(`Generating language reference from ${TS_SOURCE_REL}:`);
+ console.log(` ${languages.map((l) => l.code).join(', ')}`);
+
+ writeIfChanged(CS_OUTPUT, generateCSharp(languages, defaultCode));
+}
+
+main().catch((err) => {
+ console.error(err);
+ process.exit(1);
+});
diff --git a/core/models/src/defaults/Languages.ts b/core/models/src/defaults/Languages.ts
new file mode 100644
index 000000000..18c5d8e85
--- /dev/null
+++ b/core/models/src/defaults/Languages.ts
@@ -0,0 +1,79 @@
+/**
+ * Generic, cross-platform language reference: maps a two-letter ISO 639-1 code to a flag and a
+ * native display label.
+ */
+
+/**
+ * Display metadata for a single language.
+ */
+export interface ILanguageInfo {
+ /** Two-letter ISO 639-1 language code (e.g. 'en', 'nl'). */
+ code: string;
+ /** Emoji flag for the language. */
+ flag: string;
+ /** Native display label. */
+ label: string;
+}
+
+/** Default ISO language code used as the universal fallback. */
+export const DEFAULT_LANGUAGE_CODE = 'en';
+
+/**
+ * Known languages keyed by ISO 639-1 code, with a flag and native label.
+ * Covers the AliasVault app UI languages so this list can be reused beyond a single feature.
+ */
+export const LANGUAGES: ILanguageInfo[] = [
+ { code: 'en', flag: '๐Ÿ‡ฌ๐Ÿ‡ง', label: 'English' },
+ { code: 'nl', flag: '๐Ÿ‡ณ๐Ÿ‡ฑ', label: 'Nederlands' },
+ { code: 'de', flag: '๐Ÿ‡ฉ๐Ÿ‡ช', label: 'Deutsch' },
+ { code: 'fr', flag: '๐Ÿ‡ซ๐Ÿ‡ท', label: 'Franรงais' },
+ { code: 'es', flag: '๐Ÿ‡ช๐Ÿ‡ธ', label: 'Espaรฑol' },
+ { code: 'it', flag: '๐Ÿ‡ฎ๐Ÿ‡น', label: 'Italiano' },
+ { code: 'da', flag: '๐Ÿ‡ฉ๐Ÿ‡ฐ', label: 'Dansk' },
+ { code: 'fi', flag: '๐Ÿ‡ซ๐Ÿ‡ฎ', label: 'Suomi' },
+ { code: 'he', flag: '๐Ÿ‡ฎ๐Ÿ‡ฑ', label: 'ืขื‘ืจื™ืช' },
+ { code: 'pl', flag: '๐Ÿ‡ต๐Ÿ‡ฑ', label: 'Polski' },
+ { code: 'pt', flag: '๐Ÿ‡ง๐Ÿ‡ท', label: 'Portuguรชs' },
+ { code: 'ro', flag: '๐Ÿ‡ท๐Ÿ‡ด', label: 'Romรขnฤƒ' },
+ { code: 'ru', flag: '๐Ÿ‡ท๐Ÿ‡บ', label: 'ะ ัƒััะบะธะน' },
+ { code: 'sv', flag: '๐Ÿ‡ธ๐Ÿ‡ช', label: 'Svenska' },
+ { code: 'uk', flag: '๐Ÿ‡บ๐Ÿ‡ฆ', label: 'ะฃะบั€ะฐั—ะฝััŒะบะฐ' },
+ { code: 'zh', flag: '๐Ÿ‡จ๐Ÿ‡ณ', label: 'ไธญๆ–‡' },
+];
+
+/**
+ * Normalize an app/UI language tag to a two-letter lowercase ISO code (e.g. 'nl-NL' -> 'nl').
+ * @param code The language tag.
+ * @returns The two-letter lowercase code.
+ */
+export function normalizeLanguageCode(code: string | null | undefined): string {
+ return (code ?? '').slice(0, 2).toLowerCase();
+}
+
+/**
+ * Look up the display metadata for an ISO language code.
+ * Falls back to a globe flag and the raw code for unknown languages.
+ * @param code The ISO language code (case-insensitive).
+ * @returns The flag + label info for the code.
+ */
+export function getLanguageInfo(code: string): ILanguageInfo {
+ const iso = normalizeLanguageCode(code);
+ const match = LANGUAGES.find((l) => l.code === iso);
+ return match ?? { code, flag: '๐ŸŒ', label: code };
+}
+
+/**
+ * Resolve a default language code for an app/UI language, restricted to a set of available codes
+ * (e.g. the Diceware wordlist languages returned by the Rust core). Returns the app language when it
+ * is available, otherwise the first available code, otherwise English.
+ * @param appLanguage The app/UI language tag.
+ * @param availableCodes The codes the feature actually supports.
+ * @returns The resolved ISO code.
+ */
+export function resolveDefaultLanguage(appLanguage: string | null | undefined, availableCodes: string[]): string {
+ const iso = normalizeLanguageCode(appLanguage);
+ if (availableCodes.some((c) => c.toLowerCase() === iso)) {
+ return iso;
+ }
+ return availableCodes[0] ?? DEFAULT_LANGUAGE_CODE;
+}
diff --git a/core/models/src/defaults/index.ts b/core/models/src/defaults/index.ts
index d0b836519..989c97f73 100644
--- a/core/models/src/defaults/index.ts
+++ b/core/models/src/defaults/index.ts
@@ -2,3 +2,4 @@
* Export all shared cross-platform default/constant values.
*/
export * from './PasswordGeneratorDefaults';
+export * from './Languages';
diff --git a/core/rust/src/password_generator/mod.rs b/core/rust/src/password_generator/mod.rs
index c7980e60a..8626701de 100644
--- a/core/rust/src/password_generator/mod.rs
+++ b/core/rust/src/password_generator/mod.rs
@@ -160,7 +160,7 @@ fn default_true() -> bool {
}
fn default_language() -> String {
- "English".to_string()
+ "en".to_string()
}
/// List the language codes of all bundled Diceware wordlists (first is the default, English).
diff --git a/core/rust/src/password_generator/tests.rs b/core/rust/src/password_generator/tests.rs
index 7dfc30463..1ef724ae8 100644
--- a/core/rust/src/password_generator/tests.rs
+++ b/core/rust/src/password_generator/tests.rs
@@ -15,7 +15,7 @@ fn empty_json_uses_defaults() {
assert!(s.use_lowercase && s.use_uppercase && s.use_numbers && s.use_special_chars);
assert!(!s.use_non_ambiguous_chars);
assert_eq!(s.word_count, 5);
- assert_eq!(s.language, "English");
+ assert_eq!(s.language, "en");
assert_eq!(s.capitalization, Capitalization::Lowercase);
assert_eq!(s.separator, Separator::Dash);
assert_eq!(s.salt, Salt::None);
@@ -201,9 +201,9 @@ fn all_wordlists_have_7776_words() {
#[test]
fn unknown_language_falls_back_to_english() {
- // Case-insensitive match, and an unknown code must not error.
- assert_eq!(wordlists::list("english"), wordlists::list("English"));
- assert_eq!(wordlists::list("doesnotexist"), wordlists::list("English"));
+ // Case-insensitive match, and an unknown code must not error (falls back to 'en').
+ assert_eq!(wordlists::list("en"), wordlists::list("EN"));
+ assert_eq!(wordlists::list("doesnotexist"), wordlists::list("en"));
let pw = generate_password(r#"{"Type":"diceware","Language":"Klingon"}"#).unwrap();
assert!(!pw.is_empty());
}
diff --git a/core/rust/src/password_generator/wordlists/mod.rs b/core/rust/src/password_generator/wordlists/mod.rs
index cb8620e59..4db04f5d1 100644
--- a/core/rust/src/password_generator/wordlists/mod.rs
+++ b/core/rust/src/password_generator/wordlists/mod.rs
@@ -8,16 +8,16 @@
//! the `WORDLISTS` registry below โ€” no changes are needed in the TypeScript model or the
//! apps. Unknown codes fall back to English.
-/// The registry of bundled wordlists, as `(code, raw text)`. The first entry is the
-/// default/fallback (English). To add a language, add one line here plus the `.diceware`
-/// file โ€” nothing else needs to change.
+/// The registry of bundled wordlists, as `(code, raw text)`. The code is the normalized two-letter
+/// ISO 639-1 language code; the first entry is the default/fallback (English). To add a language,
+/// add one line here plus the matching `.diceware` file.
static WORDLISTS: &[(&str, &str)] = &[
- ("English", include_str!("en.diceware")),
- ("Dutch", include_str!("nl.diceware")),
- ("German", include_str!("de.diceware")),
- ("French", include_str!("fr.diceware")),
- ("Spanish", include_str!("es.diceware")),
- ("Italian", include_str!("it.diceware")),
+ ("en", include_str!("en.diceware")),
+ ("nl", include_str!("nl.diceware")),
+ ("de", include_str!("de.diceware")),
+ ("fr", include_str!("fr.diceware")),
+ ("es", include_str!("es.diceware")),
+ ("it", include_str!("it.diceware")),
];
/// Resolve a language code (case-insensitive) to its raw wordlist text, falling back to
diff --git a/core/rust/src/uniffi_api.rs b/core/rust/src/uniffi_api.rs
index 8c55ca762..645dbdab2 100644
--- a/core/rust/src/uniffi_api.rs
+++ b/core/rust/src/uniffi_api.rs
@@ -114,6 +114,32 @@ pub fn extract_root_domain(domain: String) -> String {
crate::credential_matcher::extract_root_domain(&domain)
}
+// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
+// Password Generator Functions
+// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
+
+/// Generate a password or passphrase from a JSON-serialized `PasswordSettings` object.
+///
+/// The `Type` field selects the generator ("basic" or "diceware"). An optional `Seed`
+/// field (64-character hex string) makes generation deterministic for UI previews.
+///
+/// # Arguments
+/// * `settings_json` - JSON string containing the password settings.
+///
+/// # Returns
+/// The generated password/passphrase string, or a [`VaultError`] if the settings JSON
+/// is invalid.
+#[uniffi::export]
+pub fn generate_password(settings_json: String) -> Result<String, VaultError> {
+ crate::password_generator::generate_password(&settings_json)
+}
+
+/// List the language codes of all bundled Diceware wordlists (first is the default, English).
+#[uniffi::export]
+pub fn get_diceware_languages() -> Vec<String> {
+ crate::password_generator::available_languages()
+}
+
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// SRP (Secure Remote Password) Functions
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•