From e69e466b92f2e7df3518a4068564c2ad42bf813b Mon Sep 17 00:00:00 2001 From: Carter <35710697+cmintey@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:29:30 -0600 Subject: [PATCH] add german language (#192) --- package.json | 1 + pnpm-lock.yaml | 8 ++++++++ src/i18n/de.json | 1 + src/lib/i18n.ts | 6 ++++++ src/lib/zxcvbn.ts | 8 +++++--- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/i18n/de.json diff --git a/package.json b/package.json index 19da48c..c8631eb 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@prisma/client": "^6.0.1", "@zxcvbn-ts/core": "^3.0.4", "@zxcvbn-ts/language-common": "^3.0.4", + "@zxcvbn-ts/language-de": "^3.0.2", "@zxcvbn-ts/language-en": "^3.0.2", "@zxcvbn-ts/language-es-es": "^3.0.2", "@zxcvbn-ts/language-fr": "^3.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d627267..4838fe9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: '@zxcvbn-ts/language-common': specifier: ^3.0.4 version: 3.0.4 + '@zxcvbn-ts/language-de': + specifier: ^3.0.2 + version: 3.0.2 '@zxcvbn-ts/language-en': specifier: ^3.0.2 version: 3.0.2 @@ -1796,6 +1799,9 @@ packages: '@zxcvbn-ts/language-common@3.0.4': resolution: {integrity: sha512-viSNNnRYtc7ULXzxrQIVUNwHAPSXRtoIwy/Tq4XQQdIknBzw4vz36lQLF6mvhMlTIlpjoN/Z1GFu/fwiAlUSsw==} + '@zxcvbn-ts/language-de@3.0.2': + resolution: {integrity: sha512-CPl2314qWtnJl4EkeEqFbL4unP6yEAHO976ER+df8CQcKsF4FxdZYEahkleWU66dhNI2VKnmJKNMzq8QtHQKcw==} + '@zxcvbn-ts/language-en@3.0.2': resolution: {integrity: sha512-Zp+zL+I6Un2Bj0tRXNs6VUBq3Djt+hwTwUz4dkt2qgsQz47U0/XthZ4ULrT/RxjwJRl5LwiaKOOZeOtmixHnjg==} @@ -5984,6 +5990,8 @@ snapshots: '@zxcvbn-ts/language-common@3.0.4': {} + '@zxcvbn-ts/language-de@3.0.2': {} + '@zxcvbn-ts/language-en@3.0.2': {} '@zxcvbn-ts/language-es-es@3.0.2': {} diff --git a/src/i18n/de.json b/src/i18n/de.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/i18n/de.json @@ -0,0 +1 @@ +{} diff --git a/src/lib/i18n.ts b/src/lib/i18n.ts index bff41d7..061e547 100644 --- a/src/lib/i18n.ts +++ b/src/lib/i18n.ts @@ -20,6 +20,7 @@ export const initLang = async () => { register("es", () => import("../i18n/es.json")); register("fr", () => import("../i18n/fr.json")); register("sv", () => import("../i18n/sv.json")); + register("de", () => import("../i18n/de.json")); await init({ fallbackLocale: defaultLocale, @@ -50,3 +51,8 @@ export const getClosestAvailableLocale = (langs: readonly string[]) => { const $locales = get(locales); return langs.find((lang) => $locales.find(($locale) => $locale === lang)); }; + +export const getPrimaryLang = () => { + const lang = get(locale); + return lang?.toLowerCase().split("-")[0]; +}; diff --git a/src/lib/zxcvbn.ts b/src/lib/zxcvbn.ts index 7f7dc2e..4767f2e 100644 --- a/src/lib/zxcvbn.ts +++ b/src/lib/zxcvbn.ts @@ -1,15 +1,17 @@ import { get } from "svelte/store"; import { locale } from "svelte-i18n"; +import { getPrimaryLang } from "./i18n"; export const loadOptions = async () => { - const lang = get(locale); const langCommon = await import("@zxcvbn-ts/language-common"); const langEn = await import("@zxcvbn-ts/language-en"); let langUser: any; - if (lang?.toLowerCase() === "es-es") { + if (get(locale)?.toLowerCase() === "es-es") { langUser = await import("@zxcvbn-ts/language-es-es"); - } else if (lang?.toLowerCase().split("-")[0]) { + } else if (getPrimaryLang() === "fr") { langUser = await import("@zxcvbn-ts/language-fr"); + } else if (getPrimaryLang() === "de") { + langUser = await import("@zxcvbn-ts/language-de"); } return {