yo-next-auth/components/TranslateClientFragment.tsx

27 lines
500 B
TypeScript

import { useI18n } from '@/locales/client'
type Props = {
message: string
}
const _ = (message: string): string => {
const t = useI18n()
if (message.startsWith('["')) {
const data = JSON.parse(message)
if (data.length > 1) {
message = data.shift()
// @ts-ignore
return t(message, ...data)
}
}
// @ts-ignore
return t(message)
}
const TranslateClientFragment = ({ message }: Props) => {
return <>{_(message)}</>
}
export default TranslateClientFragment