我的 React 应用程序使用next-i18next
包。我想在我的插值中加入一些 React 组件:
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']),
}
});
并且reviews.json
:
{
"footer": "By {{author}}, all rights reserved"
}
尝试使用 JSX 元素填充插值无法按预期工作。我得到的结果是:
作者:[object Object],保留所有权利
我也尝试使用 未转义插值By {{- author}}, all rights reserved
,但结果相同。
我可以使用 JSX 元素来填充我的插值吗?