diff --git a/fittrackee_client/src/utils/password.ts b/fittrackee_client/src/utils/password.ts index 03ec60c8..6d0bdb5f 100644 --- a/fittrackee_client/src/utils/password.ts +++ b/fittrackee_client/src/utils/password.ts @@ -1,37 +1,38 @@ import { zxcvbnOptions } from '@zxcvbn-ts/core' +export const loadLanguagePackage = async (language: string) => { + // no package available for norwegian bokmal and dutch (Nederlands) + // fallback to english + switch (language) { + case 'fr': + return await import( + /* webpackChunkName: "password.fr" */ '@zxcvbn-ts/language-fr' + ) + case 'de': + return await import( + /* webpackChunkName: "password.de" */ '@zxcvbn-ts/language-de' + ) + case 'it': + return await import( + /* webpackChunkName: "password.it" */ '@zxcvbn-ts/language-it' + ) + default: + return await import( + /* webpackChunkName: "password.en" */ '@zxcvbn-ts/language-en' + ) + } +} + export const setZxcvbnOptions = async (language: string) => { const zxcvbnCommonPackage = await import( /* webpackChunkName: "password" */ '@zxcvbn-ts/language-common' ) - const zxcvbnEnPackage = await import( - /* webpackChunkName: "password" */ '@zxcvbn-ts/language-en' - ) - const zxcvbnFrPackage = await import( - /* webpackChunkName: "password" */ '@zxcvbn-ts/language-fr' - ) - const zxcvbnDePackage = await import( - /* webpackChunkName: "password" */ '@zxcvbn-ts/language-de' - ) - const zxcvbnItPackage = await import( - /* webpackChunkName: "password" */ '@zxcvbn-ts/language-it' - ) - const zxcvbnLangPackages: Record = { - de: zxcvbnDePackage, - en: zxcvbnEnPackage, - fr: zxcvbnFrPackage, - it: zxcvbnItPackage, - // no package available for norwegian bokmal, fallback on english - nb: zxcvbnEnPackage, - // no package available for dutch (Nederlands), fallback on english - nl: zxcvbnEnPackage, - } - const zxcvbnPackage = zxcvbnLangPackages[language] + const zxcvbnLanguagePackage = await loadLanguagePackage(language) const options = { graphs: zxcvbnCommonPackage.default.adjacencyGraphs, dictionary: { ...zxcvbnCommonPackage.default.dictionary, - ...zxcvbnPackage.default.dictionary, + ...zxcvbnLanguagePackage.default.dictionary, }, } zxcvbnOptions.setOptions(options)