2022-06-11 14:52:41 -04:00
|
|
|
import React from 'react';
|
2026-10-05 18:10:18 -04:00
|
|
|
import { Trans, useTranslation } from 'react-i18next';
|
2022-06-11 14:52:41 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
export type TranslationValue =
|
|
|
|
|
| string
|
|
|
|
|
| number
|
|
|
|
|
| boolean
|
|
|
|
|
| null
|
|
|
|
|
| readonly TranslationValue[]
|
|
|
|
|
| { readonly [key: string]: TranslationValue };
|
2022-06-11 14:52:41 -04:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
export type TranslationValues = Record<string, TranslationValue>;
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
ns: string;
|
|
|
|
|
i18nKey: string;
|
|
|
|
|
values?: TranslationValues;
|
|
|
|
|
children?: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function Translate({ ns, children, ...props }: Props) {
|
2022-06-11 14:52:41 -04:00
|
|
|
const { t } = useTranslation(ns);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Trans t={t} {...props}>
|
|
|
|
|
{children}
|
|
|
|
|
</Trans>
|
|
|
|
|
);
|
2026-10-05 18:10:18 -04:00
|
|
|
}
|