My React app uses next-i18next
package. I'd like to put some React component inside my interpolation:
import React from 'react';
import { useTranslation } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
export default function Review({ text, author }) {
const { t } = useTranslation('reviews');
return (
<article>
<p>{text}</p>
<footer>
{t('footer', { author: <a href={author.url}>{author.name}</a> })}
</footer>
</article>
);
}
export const getStaticProps = async ({ locale }) => ({
props: {
...await serverSideTranslations(locale, ['reviews']),
}
});
And reviews.json
:
{
"footer": "By , all rights reserved"
}
Trying to use JSX element to fill the interpolation doesn't work as expected. The result I'm getting is:
By [object Object], all rights reserved
I also tried with unescaped interpolation with By , all rights reserved
, but it ends up being the same result.
Can I use JSX element to fill my interpolation?
from React components in i18next interpolation display as [object Object]
No comments:
Post a Comment