react-i18next
содержит довольно хорошую документацию, а также предлагает примеров .
Вам необходимо обернуть ваш компонент в оболочку withTranslation
и использовать реквизиты t
:
import { useTranslation, withTranslation, Trans } from 'react-i18next';
import logo from './logo.svg';
import './App.css';
// use hoc for class based components
class LegacyWelcomeClass extends Component {
render() {
const { t, i18n } = this.props;
return <h2>{t('title')}</h2>;
}
}
const Welcome = withTranslation()(LegacyWelcomeClass);
Вы не опубликовали свой полный код компонента, но вот как он должен выглядеть:
class CompClass extends Component {
render() {
const { t, i18n } = this.props;
return (
<ParentComponent>
<button type="button">
{this.props.placeholder}
</button>
{this.props.values.map(value => (
<Item
key={value[this.props.value_prop]}
value={value}
on_select={this.change}>
{t(value[this.props.label_prop])} // i want to translate this
</Item>
))}
</ParentComponent>
);
}
}
const Comp = withTranslation()(CompClass);