简体   繁体   English

React JS i18next 使用 JSX 插值进行翻译

[英]React JS i18next translate with JSX interpolation

I want to pass a JSX object as an item in interpolation object of i18next translate method.我想通过 JSX object 作为 i18next 翻译方法的插值 object 中的项目。

Please consider following code and result:请考虑以下代码和结果:

import React            from "react";
import {useTranslation} from "react-i18next";
import MoneyDisplay     from "../../../components/_generals/MoneyDisplay";

const minAmount = 1000;
const MyCompo   = () => {
    const {t} = useTranslation();
    const result = t('expr:Minimum amount for issue a new pre-invoice is {{minAmount}}', {minAmount: <MoneyDisplay value={minAmount} longUnit/>});
    return <div>{result}</div>;
};
export default MyCompo;

result is:结果是:

<div>[object Object]</div>

How can I have the right result in this situation without using Trans component?在不使用Trans组件的情况下,如何在这种情况下获得正确的结果?

They have a legacy option: https://react.i18next.com/legacy-v9/interpolate but it's deprecated so I wouldn't use that.他们有一个旧选项: https://react.i18next.com/legacy-v9/interpolate但它已被弃用,所以我不会使用它。

I think Trans is your best option我认为 Trans 是你最好的选择

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM