javascript - 如何将 html 标签作为 JavaScript 参数的一部分传递
问题描述
第一次必须这样做,所以请多多包涵。
我创建了一个帮助函数,它允许 React 应用程序使用英语和法语版本的文本。例子:
{outputEnFr(
"Currently Availability:",
"Disponibilité actuelle:",
this.props.lang
)}
上面的英文文本在辅助函数(“当前可用性:”)中,我需要传入下面的 html:
<p>
<strong>Yes</strong> = available and ready in our yard
</p>
<p>
<strong>No</strong> = currently on rent, on contract
or being serviced. Please contact us to reserve this
unit.
</p>
如何将这段 html 代码块传递到上面辅助函数英文区域的 JavaScript 参数中?
我尝试过但不起作用的方法:
{outputEnFr(
"
<p>
<strong>Yes</strong> = available and ready in our yard
</p>
<p>
<strong>No</strong> = currently on rent, on contract
or being serviced. Please contact us to reserve this
unit.
</p>
",
"Disponibilité actuelle:",
this.props.lang
)}
解决方案
你的策略很奇怪。如果您需要翻译您的应用程序,只需使用 react-18next 或任何类似的库(Talkr 等),而不是将完整的 html 块作为参数传递。所以它会这样:
<p><strong>{t("yes")}</strong> {t("yard.availability")}</p>
<p> <strong>{t("no")}</strong>{t("rent.contact")}</p>
推荐阅读
- javascript - Getting error: Type 'typeof B' is not assignable to type 'typeof A' for class B that extends A
- javascript - Owl carousel fade not working with bootstrap 4
- datetime - How to get error count from logs for last x hour
- mysql - Dockerfile to install Nginx and MySQL in same image
- java - Java object doesn't seem to be inheriting the variables of it's parent class
- java - 如何使用 Jackson 将字符串反序列化为自定义对象?
- python - Pandas - take() 不接受布尔索引器
- javascript - 渲染数组对象列表(Javascript)
- html - 在单个表格元素中调整图像高度
- php - 如何使用 php regex 执行多个搜索?