我正在按照react.i18next逐步指南[xx | https://react.i18next.com/guides/step-by-step-guide],但翻译未执行。
i18n.js(/src/i18n.js)
import i18n from 'i18next';
import { reactI18nextModule } from 'react-i18next';
const aResources = {
en: {
translation: {
test: 'a test'
}
},
pt: {
translation: {
test: 'um teste'
}
}
};
i18n
.use(reactI18nextModule) // passes i18n down to react-i18next
.init({
resources,
lng: "en",
keySeparator: false, // we do not use keys in form messages.welcome
interpolation: {
escapeValue: false // react already safes from xss
}
});
export default i18n;
index.js ...
import './i18n';
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<BrowserRouter>
<Switch>
<Route exact={true} path="/login" component={Login} />
<SecuredRoute component={App} />
</Switch>
</BrowserRouter>
</PersistGate>
</Provider>,
document.getElementById('root') as HTMLElement
);
registerServiceWorker();
使用翻译的组件:
public render(): JSX.Element {
const { t } = this.props;
return(
<div>
{t('test')}
</div>
);
}
export default withRouter(connect(
null,
mapDispatchToProps
)(withNamespaces()(SearchTemplate)) as any);
我正在按照分步指南进行操作,这应该很简单,但是它不起作用,我必须丢失一些我看不见的细节...