added inputOptionLabelsI18nPrefix when looking up label (#31577)

fixes: #31111

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-07-24 17:48:59 +02:00 committed by GitHub
parent 3139b82e3c
commit c8d64f2891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 3 deletions

View file

@ -18,6 +18,9 @@ export const OptionComponent = (props: UserProfileFieldProps) => {
const optionLabel = const optionLabel =
(attribute.annotations?.["inputOptionLabels"] as OptionLabel) || {}; (attribute.annotations?.["inputOptionLabels"] as OptionLabel) || {};
const prefix = attribute.annotations?.[
"inputOptionLabelsI18nPrefix"
] as string;
return ( return (
<UserProfileGroup {...props}> <UserProfileGroup {...props}>
@ -32,7 +35,7 @@ export const OptionComponent = (props: UserProfileFieldProps) => {
key={option} key={option}
id={option} id={option}
data-testid={option} data-testid={option}
label={label(props.t, optionLabel[option], option)} label={label(props.t, optionLabel[option], option, prefix)}
value={option} value={option}
isChecked={field.value.includes(option)} isChecked={field.value.includes(option)}
onChange={() => { onChange={() => {

View file

@ -40,9 +40,12 @@ export const SelectComponent = (props: UserProfileFieldProps) => {
const optionLabel = const optionLabel =
(attribute.annotations?.["inputOptionLabels"] as OptionLabel) || {}; (attribute.annotations?.["inputOptionLabels"] as OptionLabel) || {};
const prefix = attribute.annotations?.[
"inputOptionLabelsI18nPrefix"
] as string;
const fetchLabel = (option: string) => const fetchLabel = (option: string) =>
label(props.t, optionLabel[option], option); label(props.t, optionLabel[option], option, prefix);
const convertOptions = (selected: string) => const convertOptions = (selected: string) =>
options options

View file

@ -20,6 +20,8 @@ export const TextComponent = (props: UserProfileFieldProps) => {
placeholder={label( placeholder={label(
props.t, props.t,
attribute.annotations?.["inputTypePlaceholder"] as string, attribute.annotations?.["inputTypePlaceholder"] as string,
attribute.name,
attribute.annotations?.["inputOptionLabelsI18nPrefix"] as string,
)} )}
readOnly={attribute.readOnly} readOnly={attribute.readOnly}
isRequired={isRequired} isRequired={isRequired}

View file

@ -31,7 +31,13 @@ export const label = (
t: TFunction, t: TFunction,
text: string | undefined, text: string | undefined,
fallback?: string, fallback?: string,
) => (isBundleKey(text) ? t(unWrap(text!)) : text) || fallback; prefix?: string,
) => {
const value = text || fallback;
const bundleKey = isBundleKey(value) ? unWrap(value!) : value;
const key = prefix ? `${prefix}.${bundleKey}` : bundleKey;
return t(key || "");
};
export const labelAttribute = ( export const labelAttribute = (
t: TFunction, t: TFunction,