Skip to content

fix(PasswordCreationField): translations for char rules, correct behaviour for showing min or max rule #1728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { RuleValidationResult } from "@mittwald/password-tools-js/rules";
import {
RuleType,
type RuleValidationResult,
} from "@mittwald/password-tools-js/rules";

const generateTranslationString = (
rule: Partial<RuleValidationResult> & { translationKey?: string },
Expand All @@ -10,10 +13,12 @@ const generateTranslationString = (
const translateString = `validation.${rule.ruleType ?? "general"}`;
let finalTranslationString = "";

if ("min" in rule || "max" in rule) {
if (("min" in rule && rule.min) || ("max" in rule && rule.max)) {
const breakingBoundaryProperty = rule.failingBoundary
? rule.failingBoundary
: "min";
: rule.min
? "min"
: "max";

if (rule.identifier) {
finalTranslationString = `${translateString}.${rule.identifier}.${breakingBoundaryProperty}`;
Expand All @@ -37,6 +42,13 @@ export const generateValidationTranslation = (
): [string, Record<string, string | number | boolean> | undefined] => {
const translationKey = generateTranslationString(r, shotVersion);

if (r.ruleType === RuleType.char && r.chars) {
return [
translationKey,
{ ...r, chars: r.chars.map((c) => c.char).join("") },
];
}

return [
translationKey,
r as unknown as Record<string, string | number | boolean> | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"validation.blocklist": "{isValid, select, true {Das Passwort enthält keine verbotenen Wörter.} other {Das Passwort enthält ein verbotenes Wort \"{blockedSubstrings}\".}}",
"validation.blocklist.short": "{isValid, select, true {Keine verbotenen Wörter} other {Verbotenes Wort \"{blockedSubstrings}\"}}",
"validation.canNotStartWithSpecialCharacter": "Darf nicht mit Sonderzeichen anfangen",
"validation.char.max": "{max, plural, one {Bitte verwende maximal eins von den Zeichen {chars}.} other {Bitte verwende maximal {max} von den Zeichen {chars}.}}",
"validation.char.max.short": "{max, plural, one {Maximal ein Zeichen von {chars}.} other {Maximal {max} Zeichen von {chars}.}}",
"validation.char.min": "{max, plural, one {Bitte verwende maximal eins von den Zeichen {chars}.} other {Bitte verwende maximal {min} von den Zeichen {chars}.}}",
"validation.char.min.short": "{max, plural, one {Maximal ein Zeichen von {chars}.} other {Maximal {min} Zeichen von {chars}.}}",
"validation.charPool.numbers.max": "{max, plural, one {Bitte verwende maximal eine Zahl.} other {Bitte verwende maximal {max} Zahlen.}}",
"validation.charPool.numbers.max.short": "{max, plural, one {Maximal eine Zahl} other {Maximal {max} Zahlen}}",
"validation.charPool.numbers.min": "{min, plural, one {Bitte verwende mindestens eine Zahl.} other {Bitte verwende mindestens {min} Zahlen.}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"validation.blocklist": "{isValid, select, true {The password does not contain any forbidden words.} other {The password contains a forbidden word \"{blockedSubstrings}\".}}",
"validation.blocklist.short": "{isValid, select, true {No forbidden words} other {Forbidden word \"{blockedSubstrings}\"}}",
"validation.canNotStartWithSpecialCharacter": "Can not start with special character",
"validation.char.max": "{max, plural, one {Please use a maximum of one of the characters {chars}.} other {Please use a maximum of {max} of the characters {chars}.}}",
"validation.char.max.short": "{max, plural, one {Maximum one of {chars}} other {Maximum {max} of {chars}}}",
"validation.char.min": "{max, plural, one {Please use at least one of the characters {chars}.} other {Please use at least {min} of the characters {chars}.}}",
"validation.char.min.short": "{max, plural, one {At least one of {chars}} other {At least {min} of {chars}}}",
"validation.charPool.numbers.max": "{max, plural, one {Please use a maximum of one number.} other {Please use a maximum of {max} numbers.}}",
"validation.charPool.numbers.max.short": "{max, plural, one {Maximum one number} other {Maximum {max} numbers}}",
"validation.charPool.numbers.min": "{min, plural, one {Please use at least one number.} other {Please use at least {min} numbers.}}",
Expand Down
Loading