All files / utils altchaI18n.ts

100% Statements 7/7
75% Branches 3/4
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 334x               4x                   7x               5x 5x 30x   5x    
export const ALTCHA_LANGUAGE = {
  "de-DE": "de",
  "en-US": "en",
} as const satisfies Record<string, "de" | "en">;
 
export type AltchaLanguage =
  (typeof ALTCHA_LANGUAGE)[keyof typeof ALTCHA_LANGUAGE];
 
export const ALTCHA_I18N_KEYS = [
  "error",
  "expired",
  "label",
  "verified",
  "verifying",
  "waitAlert",
] as const;
 
export function resolveAltchaLanguage(vueLocale: string): AltchaLanguage {
  return ALTCHA_LANGUAGE[vueLocale as keyof typeof ALTCHA_LANGUAGE] ?? "de";
}
 
/* Applies vue-i18n altcha strings to the global ALTCHA i18n registry. */
export function applyAltchaStrings(
  translate: (key: string) => string,
  language: string
): void {
  const existing = globalThis.$altcha.i18n.get(language) ?? {};
  const overrides = Object.fromEntries(
    ALTCHA_I18N_KEYS.map((key) => [key, translate(`altcha.${key}`)])
  );
  globalThis.$altcha.i18n.set(language, { ...existing, ...overrides });
}