data prop for i18n

This commit is contained in:
Max Peintner
2025-06-19 15:00:44 +02:00
parent 07f91f94b0
commit 0889d1e043
3 changed files with 15 additions and 6 deletions

View File

@@ -74,7 +74,11 @@ export function ConsentScreen({
</ul> </ul>
<p className="ztdl-p text-xs text-left"> <p className="ztdl-p text-xs text-left">
{t("device.request.disclaimer", { appName: appName })} <Translated
i18nKey="request.disclaimer"
namespace="device"
data={{ appName: appName }}
/>
</p> </p>
{error && ( {error && (

View File

@@ -71,10 +71,13 @@ export function SessionClearItem({
</span> </span>
{valid ? ( {valid ? (
<span className="text-xs opacity-80 text-ellipsis"> <span className="text-xs opacity-80 text-ellipsis">
{verifiedAt && {verifiedAt && (
t("verfiedAt", { <Translated
time: moment(timestampDate(verifiedAt)).fromNow(), i18nKey="verfiedAt"
})} namespace="logout"
data={{ time: moment(timestampDate(verifiedAt)).fromNow() }}
/>
)}
</span> </span>
) : ( ) : (
verifiedAt && ( verifiedAt && (

View File

@@ -4,18 +4,20 @@ export function Translated({
i18nKey, i18nKey,
children, children,
namespace, namespace,
data,
...props ...props
}: { }: {
i18nKey: string; i18nKey: string;
children?: React.ReactNode; children?: React.ReactNode;
namespace?: string; namespace?: string;
data?: any;
} & React.HTMLAttributes<HTMLSpanElement>) { } & React.HTMLAttributes<HTMLSpanElement>) {
const t = useTranslations(namespace); const t = useTranslations(namespace);
const helperKey = `${namespace ? `${namespace}.` : ""}${i18nKey}`; const helperKey = `${namespace ? `${namespace}.` : ""}${i18nKey}`;
return ( return (
<span data-i18n-key={helperKey} {...props}> <span data-i18n-key={helperKey} {...props}>
{t(i18nKey)} {t(i18nKey, data)}
</span> </span>
); );
} }