Skip to content

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

Add langcode definitions to identitty-generator languages (#1383)

Leendert de Borst51dc4d2844b5
diff --git a/apps/browser-extension/src/utils/dist/shared/identity-generator/index.d.ts b/apps/browser-extension/src/utils/dist/shared/identity-generator/index.d.ts
index 1b187b88b..3b56246f0 100644
--- a/apps/browser-extension/src/utils/dist/shared/identity-generator/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/shared/identity-generator/index.d.ts
@@ -242,6 +242,12 @@ interface ILanguageOption {
* The flag emoji for the language (e.g., "πŸ‡¬πŸ‡§", "πŸ‡³πŸ‡±", "πŸ‡©πŸ‡ͺ")
*/
flag: string;
+ /**
+ * Alternative language codes that map to this identity generator language.
+ * Used for matching UI locale codes to identity generator languages.
+ * For example, "en-US", "en-GB", "en-CA" all map to "en"
+ */
+ alternativeCodes?: string[];
}
/**
* Gets all available languages for identity generation.
@@ -249,6 +255,20 @@ interface ILanguageOption {
* @returns Array of language options
*/
declare function getAvailableLanguages(): ILanguageOption[];
+/**
+ * Maps a UI language code to an identity generator language code.
+ * If no explicit match is found, returns null to indicate no preference.
+ *
+ * @param uiLanguageCode - The UI language code (e.g., "en", "en-US", "nl-NL", "de-DE", "fr")
+ * @returns The matching identity generator language code or null if no match
+ *
+ * @example
+ * mapUiLanguageToIdentityLanguage("en-US") // returns "en"
+ * mapUiLanguageToIdentityLanguage("nl") // returns "nl"
+ * mapUiLanguageToIdentityLanguage("de-CH") // returns "de"
+ * mapUiLanguageToIdentityLanguage("fr") // returns null (no French identity generator)
+ */
+declare function mapUiLanguageToIdentityLanguage(uiLanguageCode: string | null | undefined): string | null;
/**
* Creates a new identity generator based on the language.
@@ -265,4 +285,4 @@ declare const CreateIdentityGenerator: (language: string) => IdentityGenerator;
*/
declare const CreateUsernameEmailGenerator: () => UsernameEmailGenerator;
-export { CreateIdentityGenerator, CreateUsernameEmailGenerator, Gender, type IAgeRangeOption, type IBirthdateOptions, type IDecadeFirstnames, type IIdentityGenerator, type ILanguageOption, type Identity, IdentityGenerator, IdentityGeneratorDe, IdentityGeneratorEn, IdentityGeneratorNl, IdentityHelperUtils, UsernameEmailGenerator, convertAgeRangeToBirthdateOptions, getAvailableAgeRanges, getAvailableLanguages };
+export { CreateIdentityGenerator, CreateUsernameEmailGenerator, Gender, type IAgeRangeOption, type IBirthdateOptions, type IDecadeFirstnames, type IIdentityGenerator, type ILanguageOption, type Identity, IdentityGenerator, IdentityGeneratorDe, IdentityGeneratorEn, IdentityGeneratorNl, IdentityHelperUtils, UsernameEmailGenerator, convertAgeRangeToBirthdateOptions, getAvailableAgeRanges, getAvailableLanguages, mapUiLanguageToIdentityLanguage };
diff --git a/apps/browser-extension/src/utils/dist/shared/identity-generator/index.js b/apps/browser-extension/src/utils/dist/shared/identity-generator/index.js
index 56676233b..0207d241c 100644
--- a/apps/browser-extension/src/utils/dist/shared/identity-generator/index.js
+++ b/apps/browser-extension/src/utils/dist/shared/identity-generator/index.js
@@ -34,7 +34,8 @@ __export(index_exports, {
UsernameEmailGenerator: () => UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions: () => convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges: () => getAvailableAgeRanges,
- getAvailableLanguages: () => getAvailableLanguages
+ getAvailableLanguages: () => getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage: () => mapUiLanguageToIdentityLanguage
});
module.exports = __toCommonJS(index_exports);
@@ -5926,11 +5927,49 @@ function convertAgeRangeToBirthdateOptions(ageRange) {
// src/utils/LanguageProvider.ts
function getAvailableLanguages() {
return [
- { value: "en", label: "English", flag: "\u{1F1EC}\u{1F1E7}" },
- { value: "nl", label: "Nederlands", flag: "\u{1F1F3}\u{1F1F1}" },
- { value: "de", label: "Deutsch", flag: "\u{1F1E9}\u{1F1EA}" }
+ {
+ value: "en",
+ label: "English",
+ flag: "\u{1F1EC}\u{1F1E7}",
+ alternativeCodes: ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]
+ },
+ {
+ value: "nl",
+ label: "Nederlands",
+ flag: "\u{1F1F3}\u{1F1F1}",
+ alternativeCodes: ["nl-NL", "nl-BE"]
+ },
+ {
+ value: "de",
+ label: "Deutsch",
+ flag: "\u{1F1E9}\u{1F1EA}",
+ alternativeCodes: ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]
+ }
];
}
+function mapUiLanguageToIdentityLanguage(uiLanguageCode) {
+ if (!uiLanguageCode) {
+ return null;
+ }
+ const normalizedCode = uiLanguageCode.toLowerCase();
+ const availableLanguages = getAvailableLanguages();
+ const exactMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === normalizedCode);
+ if (exactMatch) {
+ return exactMatch.value;
+ }
+ const alternativeMatch = availableLanguages.find(
+ (lang) => lang.alternativeCodes?.some((code) => code.toLowerCase() === normalizedCode)
+ );
+ if (alternativeMatch) {
+ return alternativeMatch.value;
+ }
+ const baseCode = normalizedCode.split("-")[0];
+ const baseMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === baseCode);
+ if (baseMatch) {
+ return baseMatch.value;
+ }
+ return null;
+}
// src/factories/IdentityGeneratorFactory.ts
var CreateIdentityGenerator = (language) => {
@@ -5964,5 +6003,6 @@ var CreateUsernameEmailGenerator = () => {
UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges,
- getAvailableLanguages
+ getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage
});
diff --git a/apps/browser-extension/src/utils/dist/shared/identity-generator/index.mjs b/apps/browser-extension/src/utils/dist/shared/identity-generator/index.mjs
index aefea095a..db4e8cef8 100644
--- a/apps/browser-extension/src/utils/dist/shared/identity-generator/index.mjs
+++ b/apps/browser-extension/src/utils/dist/shared/identity-generator/index.mjs
@@ -5890,11 +5890,49 @@ function convertAgeRangeToBirthdateOptions(ageRange) {
// src/utils/LanguageProvider.ts
function getAvailableLanguages() {
return [
- { value: "en", label: "English", flag: "\u{1F1EC}\u{1F1E7}" },
- { value: "nl", label: "Nederlands", flag: "\u{1F1F3}\u{1F1F1}" },
- { value: "de", label: "Deutsch", flag: "\u{1F1E9}\u{1F1EA}" }
+ {
+ value: "en",
+ label: "English",
+ flag: "\u{1F1EC}\u{1F1E7}",
+ alternativeCodes: ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]
+ },
+ {
+ value: "nl",
+ label: "Nederlands",
+ flag: "\u{1F1F3}\u{1F1F1}",
+ alternativeCodes: ["nl-NL", "nl-BE"]
+ },
+ {
+ value: "de",
+ label: "Deutsch",
+ flag: "\u{1F1E9}\u{1F1EA}",
+ alternativeCodes: ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]
+ }
];
}
+function mapUiLanguageToIdentityLanguage(uiLanguageCode) {
+ if (!uiLanguageCode) {
+ return null;
+ }
+ const normalizedCode = uiLanguageCode.toLowerCase();
+ const availableLanguages = getAvailableLanguages();
+ const exactMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === normalizedCode);
+ if (exactMatch) {
+ return exactMatch.value;
+ }
+ const alternativeMatch = availableLanguages.find(
+ (lang) => lang.alternativeCodes?.some((code) => code.toLowerCase() === normalizedCode)
+ );
+ if (alternativeMatch) {
+ return alternativeMatch.value;
+ }
+ const baseCode = normalizedCode.split("-")[0];
+ const baseMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === baseCode);
+ if (baseMatch) {
+ return baseMatch.value;
+ }
+ return null;
+}
// src/factories/IdentityGeneratorFactory.ts
var CreateIdentityGenerator = (language) => {
@@ -5927,5 +5965,6 @@ export {
UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges,
- getAvailableLanguages
+ getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage
};
diff --git a/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts b/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts
index 1b187b88b..3b56246f0 100644
--- a/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts
+++ b/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts
@@ -242,6 +242,12 @@ interface ILanguageOption {
* The flag emoji for the language (e.g., "πŸ‡¬πŸ‡§", "πŸ‡³πŸ‡±", "πŸ‡©πŸ‡ͺ")
*/
flag: string;
+ /**
+ * Alternative language codes that map to this identity generator language.
+ * Used for matching UI locale codes to identity generator languages.
+ * For example, "en-US", "en-GB", "en-CA" all map to "en"
+ */
+ alternativeCodes?: string[];
}
/**
* Gets all available languages for identity generation.
@@ -249,6 +255,20 @@ interface ILanguageOption {
* @returns Array of language options
*/
declare function getAvailableLanguages(): ILanguageOption[];
+/**
+ * Maps a UI language code to an identity generator language code.
+ * If no explicit match is found, returns null to indicate no preference.
+ *
+ * @param uiLanguageCode - The UI language code (e.g., "en", "en-US", "nl-NL", "de-DE", "fr")
+ * @returns The matching identity generator language code or null if no match
+ *
+ * @example
+ * mapUiLanguageToIdentityLanguage("en-US") // returns "en"
+ * mapUiLanguageToIdentityLanguage("nl") // returns "nl"
+ * mapUiLanguageToIdentityLanguage("de-CH") // returns "de"
+ * mapUiLanguageToIdentityLanguage("fr") // returns null (no French identity generator)
+ */
+declare function mapUiLanguageToIdentityLanguage(uiLanguageCode: string | null | undefined): string | null;
/**
* Creates a new identity generator based on the language.
@@ -265,4 +285,4 @@ declare const CreateIdentityGenerator: (language: string) => IdentityGenerator;
*/
declare const CreateUsernameEmailGenerator: () => UsernameEmailGenerator;
-export { CreateIdentityGenerator, CreateUsernameEmailGenerator, Gender, type IAgeRangeOption, type IBirthdateOptions, type IDecadeFirstnames, type IIdentityGenerator, type ILanguageOption, type Identity, IdentityGenerator, IdentityGeneratorDe, IdentityGeneratorEn, IdentityGeneratorNl, IdentityHelperUtils, UsernameEmailGenerator, convertAgeRangeToBirthdateOptions, getAvailableAgeRanges, getAvailableLanguages };
+export { CreateIdentityGenerator, CreateUsernameEmailGenerator, Gender, type IAgeRangeOption, type IBirthdateOptions, type IDecadeFirstnames, type IIdentityGenerator, type ILanguageOption, type Identity, IdentityGenerator, IdentityGeneratorDe, IdentityGeneratorEn, IdentityGeneratorNl, IdentityHelperUtils, UsernameEmailGenerator, convertAgeRangeToBirthdateOptions, getAvailableAgeRanges, getAvailableLanguages, mapUiLanguageToIdentityLanguage };
diff --git a/apps/mobile-app/utils/dist/shared/identity-generator/index.js b/apps/mobile-app/utils/dist/shared/identity-generator/index.js
index 56676233b..0207d241c 100644
--- a/apps/mobile-app/utils/dist/shared/identity-generator/index.js
+++ b/apps/mobile-app/utils/dist/shared/identity-generator/index.js
@@ -34,7 +34,8 @@ __export(index_exports, {
UsernameEmailGenerator: () => UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions: () => convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges: () => getAvailableAgeRanges,
- getAvailableLanguages: () => getAvailableLanguages
+ getAvailableLanguages: () => getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage: () => mapUiLanguageToIdentityLanguage
});
module.exports = __toCommonJS(index_exports);
@@ -5926,11 +5927,49 @@ function convertAgeRangeToBirthdateOptions(ageRange) {
// src/utils/LanguageProvider.ts
function getAvailableLanguages() {
return [
- { value: "en", label: "English", flag: "\u{1F1EC}\u{1F1E7}" },
- { value: "nl", label: "Nederlands", flag: "\u{1F1F3}\u{1F1F1}" },
- { value: "de", label: "Deutsch", flag: "\u{1F1E9}\u{1F1EA}" }
+ {
+ value: "en",
+ label: "English",
+ flag: "\u{1F1EC}\u{1F1E7}",
+ alternativeCodes: ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]
+ },
+ {
+ value: "nl",
+ label: "Nederlands",
+ flag: "\u{1F1F3}\u{1F1F1}",
+ alternativeCodes: ["nl-NL", "nl-BE"]
+ },
+ {
+ value: "de",
+ label: "Deutsch",
+ flag: "\u{1F1E9}\u{1F1EA}",
+ alternativeCodes: ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]
+ }
];
}
+function mapUiLanguageToIdentityLanguage(uiLanguageCode) {
+ if (!uiLanguageCode) {
+ return null;
+ }
+ const normalizedCode = uiLanguageCode.toLowerCase();
+ const availableLanguages = getAvailableLanguages();
+ const exactMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === normalizedCode);
+ if (exactMatch) {
+ return exactMatch.value;
+ }
+ const alternativeMatch = availableLanguages.find(
+ (lang) => lang.alternativeCodes?.some((code) => code.toLowerCase() === normalizedCode)
+ );
+ if (alternativeMatch) {
+ return alternativeMatch.value;
+ }
+ const baseCode = normalizedCode.split("-")[0];
+ const baseMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === baseCode);
+ if (baseMatch) {
+ return baseMatch.value;
+ }
+ return null;
+}
// src/factories/IdentityGeneratorFactory.ts
var CreateIdentityGenerator = (language) => {
@@ -5964,5 +6003,6 @@ var CreateUsernameEmailGenerator = () => {
UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges,
- getAvailableLanguages
+ getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage
});
diff --git a/apps/mobile-app/utils/dist/shared/identity-generator/index.mjs b/apps/mobile-app/utils/dist/shared/identity-generator/index.mjs
index aefea095a..db4e8cef8 100644
--- a/apps/mobile-app/utils/dist/shared/identity-generator/index.mjs
+++ b/apps/mobile-app/utils/dist/shared/identity-generator/index.mjs
@@ -5890,11 +5890,49 @@ function convertAgeRangeToBirthdateOptions(ageRange) {
// src/utils/LanguageProvider.ts
function getAvailableLanguages() {
return [
- { value: "en", label: "English", flag: "\u{1F1EC}\u{1F1E7}" },
- { value: "nl", label: "Nederlands", flag: "\u{1F1F3}\u{1F1F1}" },
- { value: "de", label: "Deutsch", flag: "\u{1F1E9}\u{1F1EA}" }
+ {
+ value: "en",
+ label: "English",
+ flag: "\u{1F1EC}\u{1F1E7}",
+ alternativeCodes: ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]
+ },
+ {
+ value: "nl",
+ label: "Nederlands",
+ flag: "\u{1F1F3}\u{1F1F1}",
+ alternativeCodes: ["nl-NL", "nl-BE"]
+ },
+ {
+ value: "de",
+ label: "Deutsch",
+ flag: "\u{1F1E9}\u{1F1EA}",
+ alternativeCodes: ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]
+ }
];
}
+function mapUiLanguageToIdentityLanguage(uiLanguageCode) {
+ if (!uiLanguageCode) {
+ return null;
+ }
+ const normalizedCode = uiLanguageCode.toLowerCase();
+ const availableLanguages = getAvailableLanguages();
+ const exactMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === normalizedCode);
+ if (exactMatch) {
+ return exactMatch.value;
+ }
+ const alternativeMatch = availableLanguages.find(
+ (lang) => lang.alternativeCodes?.some((code) => code.toLowerCase() === normalizedCode)
+ );
+ if (alternativeMatch) {
+ return alternativeMatch.value;
+ }
+ const baseCode = normalizedCode.split("-")[0];
+ const baseMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === baseCode);
+ if (baseMatch) {
+ return baseMatch.value;
+ }
+ return null;
+}
// src/factories/IdentityGeneratorFactory.ts
var CreateIdentityGenerator = (language) => {
@@ -5927,5 +5965,6 @@ export {
UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges,
- getAvailableLanguages
+ getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage
};
diff --git a/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.d.ts b/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.d.ts
index 1b187b88b..3b56246f0 100644
--- a/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.d.ts
+++ b/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.d.ts
@@ -242,6 +242,12 @@ interface ILanguageOption {
* The flag emoji for the language (e.g., "πŸ‡¬πŸ‡§", "πŸ‡³πŸ‡±", "πŸ‡©πŸ‡ͺ")
*/
flag: string;
+ /**
+ * Alternative language codes that map to this identity generator language.
+ * Used for matching UI locale codes to identity generator languages.
+ * For example, "en-US", "en-GB", "en-CA" all map to "en"
+ */
+ alternativeCodes?: string[];
}
/**
* Gets all available languages for identity generation.
@@ -249,6 +255,20 @@ interface ILanguageOption {
* @returns Array of language options
*/
declare function getAvailableLanguages(): ILanguageOption[];
+/**
+ * Maps a UI language code to an identity generator language code.
+ * If no explicit match is found, returns null to indicate no preference.
+ *
+ * @param uiLanguageCode - The UI language code (e.g., "en", "en-US", "nl-NL", "de-DE", "fr")
+ * @returns The matching identity generator language code or null if no match
+ *
+ * @example
+ * mapUiLanguageToIdentityLanguage("en-US") // returns "en"
+ * mapUiLanguageToIdentityLanguage("nl") // returns "nl"
+ * mapUiLanguageToIdentityLanguage("de-CH") // returns "de"
+ * mapUiLanguageToIdentityLanguage("fr") // returns null (no French identity generator)
+ */
+declare function mapUiLanguageToIdentityLanguage(uiLanguageCode: string | null | undefined): string | null;
/**
* Creates a new identity generator based on the language.
@@ -265,4 +285,4 @@ declare const CreateIdentityGenerator: (language: string) => IdentityGenerator;
*/
declare const CreateUsernameEmailGenerator: () => UsernameEmailGenerator;
-export { CreateIdentityGenerator, CreateUsernameEmailGenerator, Gender, type IAgeRangeOption, type IBirthdateOptions, type IDecadeFirstnames, type IIdentityGenerator, type ILanguageOption, type Identity, IdentityGenerator, IdentityGeneratorDe, IdentityGeneratorEn, IdentityGeneratorNl, IdentityHelperUtils, UsernameEmailGenerator, convertAgeRangeToBirthdateOptions, getAvailableAgeRanges, getAvailableLanguages };
+export { CreateIdentityGenerator, CreateUsernameEmailGenerator, Gender, type IAgeRangeOption, type IBirthdateOptions, type IDecadeFirstnames, type IIdentityGenerator, type ILanguageOption, type Identity, IdentityGenerator, IdentityGeneratorDe, IdentityGeneratorEn, IdentityGeneratorNl, IdentityHelperUtils, UsernameEmailGenerator, convertAgeRangeToBirthdateOptions, getAvailableAgeRanges, getAvailableLanguages, mapUiLanguageToIdentityLanguage };
diff --git a/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.js b/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.js
index 56676233b..0207d241c 100644
--- a/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.js
+++ b/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.js
@@ -34,7 +34,8 @@ __export(index_exports, {
UsernameEmailGenerator: () => UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions: () => convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges: () => getAvailableAgeRanges,
- getAvailableLanguages: () => getAvailableLanguages
+ getAvailableLanguages: () => getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage: () => mapUiLanguageToIdentityLanguage
});
module.exports = __toCommonJS(index_exports);
@@ -5926,11 +5927,49 @@ function convertAgeRangeToBirthdateOptions(ageRange) {
// src/utils/LanguageProvider.ts
function getAvailableLanguages() {
return [
- { value: "en", label: "English", flag: "\u{1F1EC}\u{1F1E7}" },
- { value: "nl", label: "Nederlands", flag: "\u{1F1F3}\u{1F1F1}" },
- { value: "de", label: "Deutsch", flag: "\u{1F1E9}\u{1F1EA}" }
+ {
+ value: "en",
+ label: "English",
+ flag: "\u{1F1EC}\u{1F1E7}",
+ alternativeCodes: ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]
+ },
+ {
+ value: "nl",
+ label: "Nederlands",
+ flag: "\u{1F1F3}\u{1F1F1}",
+ alternativeCodes: ["nl-NL", "nl-BE"]
+ },
+ {
+ value: "de",
+ label: "Deutsch",
+ flag: "\u{1F1E9}\u{1F1EA}",
+ alternativeCodes: ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]
+ }
];
}
+function mapUiLanguageToIdentityLanguage(uiLanguageCode) {
+ if (!uiLanguageCode) {
+ return null;
+ }
+ const normalizedCode = uiLanguageCode.toLowerCase();
+ const availableLanguages = getAvailableLanguages();
+ const exactMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === normalizedCode);
+ if (exactMatch) {
+ return exactMatch.value;
+ }
+ const alternativeMatch = availableLanguages.find(
+ (lang) => lang.alternativeCodes?.some((code) => code.toLowerCase() === normalizedCode)
+ );
+ if (alternativeMatch) {
+ return alternativeMatch.value;
+ }
+ const baseCode = normalizedCode.split("-")[0];
+ const baseMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === baseCode);
+ if (baseMatch) {
+ return baseMatch.value;
+ }
+ return null;
+}
// src/factories/IdentityGeneratorFactory.ts
var CreateIdentityGenerator = (language) => {
@@ -5964,5 +6003,6 @@ var CreateUsernameEmailGenerator = () => {
UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges,
- getAvailableLanguages
+ getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage
});
diff --git a/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.mjs b/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.mjs
index aefea095a..db4e8cef8 100644
--- a/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.mjs
+++ b/apps/server/AliasVault.Client/wwwroot/js/dist/shared/identity-generator/index.mjs
@@ -5890,11 +5890,49 @@ function convertAgeRangeToBirthdateOptions(ageRange) {
// src/utils/LanguageProvider.ts
function getAvailableLanguages() {
return [
- { value: "en", label: "English", flag: "\u{1F1EC}\u{1F1E7}" },
- { value: "nl", label: "Nederlands", flag: "\u{1F1F3}\u{1F1F1}" },
- { value: "de", label: "Deutsch", flag: "\u{1F1E9}\u{1F1EA}" }
+ {
+ value: "en",
+ label: "English",
+ flag: "\u{1F1EC}\u{1F1E7}",
+ alternativeCodes: ["en-US", "en-GB", "en-CA", "en-AU", "en-NZ", "en-IE", "en-ZA", "en-SG", "en-IN"]
+ },
+ {
+ value: "nl",
+ label: "Nederlands",
+ flag: "\u{1F1F3}\u{1F1F1}",
+ alternativeCodes: ["nl-NL", "nl-BE"]
+ },
+ {
+ value: "de",
+ label: "Deutsch",
+ flag: "\u{1F1E9}\u{1F1EA}",
+ alternativeCodes: ["de-DE", "de-AT", "de-CH", "de-LU", "de-LI"]
+ }
];
}
+function mapUiLanguageToIdentityLanguage(uiLanguageCode) {
+ if (!uiLanguageCode) {
+ return null;
+ }
+ const normalizedCode = uiLanguageCode.toLowerCase();
+ const availableLanguages = getAvailableLanguages();
+ const exactMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === normalizedCode);
+ if (exactMatch) {
+ return exactMatch.value;
+ }
+ const alternativeMatch = availableLanguages.find(
+ (lang) => lang.alternativeCodes?.some((code) => code.toLowerCase() === normalizedCode)
+ );
+ if (alternativeMatch) {
+ return alternativeMatch.value;
+ }
+ const baseCode = normalizedCode.split("-")[0];
+ const baseMatch = availableLanguages.find((lang) => lang.value.toLowerCase() === baseCode);
+ if (baseMatch) {
+ return baseMatch.value;
+ }
+ return null;
+}
// src/factories/IdentityGeneratorFactory.ts
var CreateIdentityGenerator = (language) => {
@@ -5927,5 +5965,6 @@ export {
UsernameEmailGenerator,
convertAgeRangeToBirthdateOptions,
getAvailableAgeRanges,
- getAvailableLanguages
+ getAvailableLanguages,
+ mapUiLanguageToIdentityLanguage
};
diff --git a/shared/identity-generator/src/__tests__/LanguageProvider.test.ts b/shared/identity-generator/src/__tests__/LanguageProvider.test.ts
new file mode 100644
index 000000000..c2451fa99
--- /dev/null
+++ b/shared/identity-generator/src/__tests__/LanguageProvider.test.ts
@@ -0,0 +1,88 @@
+import { describe, it, expect } from 'vitest';
+import { getAvailableLanguages, mapUiLanguageToIdentityLanguage } from '../utils/LanguageProvider';
+
+describe('LanguageProvider', () => {
+ describe('getAvailableLanguages', () => {
+ it('should return a list of available languages', () => {
+ const languages = getAvailableLanguages();
+
+ expect(languages).toBeDefined();
+ expect(languages.length).toBeGreaterThan(0);
+ expect(languages[0]).toHaveProperty('value');
+ expect(languages[0]).toHaveProperty('label');
+ expect(languages[0]).toHaveProperty('flag');
+ });
+ });
+
+ describe('mapUiLanguageToIdentityLanguage', () => {
+ describe('Dutch mappings', () => {
+ it('should map "nl" to "nl"', () => {
+ expect(mapUiLanguageToIdentityLanguage('nl')).toBe('nl');
+ });
+
+ it('should map "nl-NL" to "nl"', () => {
+ expect(mapUiLanguageToIdentityLanguage('nl-NL')).toBe('nl');
+ });
+
+ it('should map "nl-BE" to "nl" (Belgian Dutch)', () => {
+ expect(mapUiLanguageToIdentityLanguage('nl-BE')).toBe('nl');
+ });
+
+ it('should be case-insensitive for "NL"', () => {
+ expect(mapUiLanguageToIdentityLanguage('NL')).toBe('nl');
+ });
+
+ it('should be case-insensitive for "NL-NL"', () => {
+ expect(mapUiLanguageToIdentityLanguage('NL-NL')).toBe('nl');
+ });
+
+ it('should be case-insensitive for "NL-BE"', () => {
+ expect(mapUiLanguageToIdentityLanguage('NL-BE')).toBe('nl');
+ });
+ });
+
+ describe('Edge cases', () => {
+ it('should return null for null input', () => {
+ expect(mapUiLanguageToIdentityLanguage(null)).toBe(null);
+ });
+
+ it('should return null for undefined input', () => {
+ expect(mapUiLanguageToIdentityLanguage(undefined)).toBe(null);
+ });
+
+ it('should return null for empty string', () => {
+ expect(mapUiLanguageToIdentityLanguage('')).toBe(null);
+ });
+
+ it('should return null for whitespace', () => {
+ expect(mapUiLanguageToIdentityLanguage(' ')).toBe(null);
+ });
+
+ it('should return null for invalid format', () => {
+ expect(mapUiLanguageToIdentityLanguage('invalid')).toBe(null);
+ });
+
+ it('should return null for numbers', () => {
+ expect(mapUiLanguageToIdentityLanguage('123')).toBe(null);
+ });
+ });
+
+ describe('Mixed case and locale variants', () => {
+ it('should handle mixed case "En-Us"', () => {
+ expect(mapUiLanguageToIdentityLanguage('En-Us')).toBe('en');
+ });
+
+ it('should handle mixed case "nL-Nl"', () => {
+ expect(mapUiLanguageToIdentityLanguage('nL-Nl')).toBe('nl');
+ });
+
+ it('should extract base language from unknown locale "en-ZZ"', () => {
+ expect(mapUiLanguageToIdentityLanguage('en-ZZ')).toBe('en');
+ });
+
+ it('should extract base language from unknown locale "nl-ZZ"', () => {
+ expect(mapUiLanguageToIdentityLanguage('nl-ZZ')).toBe('nl');
+ });
+ });
+ });
+});
diff --git a/shared/identity-generator/src/utils/LanguageProvider.ts b/shared/identity-generator/src/utils/LanguageProvider.ts
index 4540224dd..c083923ee 100644
--- a/shared/identity-generator/src/utils/LanguageProvider.ts
+++ b/shared/identity-generator/src/utils/LanguageProvider.ts
@@ -16,6 +16,13 @@ export interface ILanguageOption {
* The flag emoji for the language (e.g., "πŸ‡¬πŸ‡§", "πŸ‡³πŸ‡±", "πŸ‡©πŸ‡ͺ")
*/
flag: string;
+
+ /**
+ * Alternative language codes that map to this identity generator language.
+ * Used for matching UI locale codes to identity generator languages.
+ * For example, "en-US", "en-GB", "en-CA" all map to "en"
+ */
+ alternativeCodes?: string[];
}
/**
@@ -25,8 +32,69 @@ export interface ILanguageOption {
*/
export function getAvailableLanguages(): ILanguageOption[] {
return [
- { value: 'en', label: 'English', flag: 'πŸ‡¬πŸ‡§' },
- { value: 'nl', label: 'Nederlands', flag: 'πŸ‡³πŸ‡±' },
- { value: 'de', label: 'Deutsch', flag: 'πŸ‡©πŸ‡ͺ' }
+ {
+ value: 'en',
+ label: 'English',
+ flag: 'πŸ‡¬πŸ‡§',
+ alternativeCodes: ['en-US', 'en-GB', 'en-CA', 'en-AU', 'en-NZ', 'en-IE', 'en-ZA', 'en-SG', 'en-IN']
+ },
+ {
+ value: 'nl',
+ label: 'Nederlands',
+ flag: 'πŸ‡³πŸ‡±',
+ alternativeCodes: ['nl-NL', 'nl-BE']
+ },
+ {
+ value: 'de',
+ label: 'Deutsch',
+ flag: 'πŸ‡©πŸ‡ͺ',
+ alternativeCodes: ['de-DE', 'de-AT', 'de-CH', 'de-LU', 'de-LI']
+ }
];
}
+
+/**
+ * Maps a UI language code to an identity generator language code.
+ * If no explicit match is found, returns null to indicate no preference.
+ *
+ * @param uiLanguageCode - The UI language code (e.g., "en", "en-US", "nl-NL", "de-DE", "fr")
+ * @returns The matching identity generator language code or null if no match
+ *
+ * @example
+ * mapUiLanguageToIdentityLanguage("en-US") // returns "en"
+ * mapUiLanguageToIdentityLanguage("nl") // returns "nl"
+ * mapUiLanguageToIdentityLanguage("de-CH") // returns "de"
+ * mapUiLanguageToIdentityLanguage("fr") // returns null (no French identity generator)
+ */
+export function mapUiLanguageToIdentityLanguage(uiLanguageCode: string | null | undefined): string | null {
+ if (!uiLanguageCode) {
+ return null;
+ }
+
+ const normalizedCode = uiLanguageCode.toLowerCase();
+ const availableLanguages = getAvailableLanguages();
+
+ // First, try exact match with the primary value
+ const exactMatch = availableLanguages.find(lang => lang.value.toLowerCase() === normalizedCode);
+ if (exactMatch) {
+ return exactMatch.value;
+ }
+
+ // Then, try matching with alternative codes
+ const alternativeMatch = availableLanguages.find(lang =>
+ lang.alternativeCodes?.some(code => code.toLowerCase() === normalizedCode)
+ );
+ if (alternativeMatch) {
+ return alternativeMatch.value;
+ }
+
+ // Finally, try matching the base language code (e.g., "en" from "en-US")
+ const baseCode = normalizedCode.split('-')[0];
+ const baseMatch = availableLanguages.find(lang => lang.value.toLowerCase() === baseCode);
+ if (baseMatch) {
+ return baseMatch.value;
+ }
+
+ // No match found
+ return null;
+}