简体   繁体   English

如何将 react-i18next 与 Semantic UI 标签标签结合起来?

[英]How to combine react-i18next with Semantic UI label tag?

I am using Semantic UI with the combination of [react-i18next][2] and need to make label string translatable , but this label has a HTML tag in it, for example span .我正在使用语义 UI 与 [react-i18next][2] 的组合,需要使标签字符串可翻译,但该标签中有一个 HTML 标签,例如span However, it only accepts string which is hardcoded or variable.但是,它只接受硬编码或可变的字符串。

This is not possible这不可能

The props for the FormControlLabel state that the label prop is The text to be used in an enclosing label element. FormControlLabel 的道具声明标签道具是The text to be used in an enclosing label element.

Check it here 在这里检查

You will have to make a custom label control for this element or extend FormControlLabel (highly suggest you don't extend)您必须为此元素制作自定义标签控件或扩展FormControlLabel (强烈建议您不要扩展)

Custom Label自定义标签

Put your checkbox in as children add it should work, but you need to expand on the controls.将您的复选框作为孩子添加它应该可以工作,但您需要扩展控件。

const CustomLabel = (props) => (
  <div dangerouslySetInnerHTML={{__html: t('login.accept')}} />
)

// implementation

<CustomLable />
<Checkbox />

Workaround解决方法

What you could do is strip the tags from your strings so that you get the plain text.您可以做的是从字符串中去除标签,以便获得纯文本。

cleanText = strInputCode.replace(/<\\/?[^>]+(>|$)/g, "");

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

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