简体   繁体   English

React Lingui - 翻译输入占位符

[英]React Lingui - translate input placeholder

I have a problem with translation placeholder prop for input.我对输入的翻译placeholder具有问题。 I have a wrapper component <Text /> which renders <input> one.我有一个包装组件<Text />它呈现<input>一个。 I've tried to translate placholder this way:我试过这样翻译 placholder:

 import { Trans, t } from '@lingui/macro' const passwordPlaceholder = t('password.placeholder')`Enter password` // this doesn't works <Text as='input' type='password' name='password' placeholder={t(passwordPlaceholder)} required /> // neither <Text as='input' type='password' name='password' placeholder={<Trans id={passwordPlaceholder} />} /> // not <Text as='input' type='password' name='password' placeholder={passwordPlaceholder} />

I tried a lot of time to solve this problem, no solution found...我尝试了很多时间来解决这个问题,没有找到解决方案......

The solution was suggested by my former colleague, using render function with object parameter contains 'translation' property.解决方案是我以前的同事建议的,使用带有对象参数的渲染函数包含“翻译”属性。 I hope this answer helps someone.我希望这个答案对某人有所帮助。

 <Trans id={passwordPlaceholder} render={({translation}) => ( <Text as='input' type='password' name='password' placeholder={translation} required />)} />

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

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