问题
I have tryed to implement react-i18next
to my react application but it doesn't give a f... that I want it to work
Console doesn't show any error. It just doesn't translate.
Anyone had similar problem and can help me figure out why it doesn't translate?
my i18n.js
file content:
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import translationPL from './translations/pl/common.json';
const resources = {
pl: {
translation: translationPL
}
};
i18n
.use(initReactI18next)
.init({
resources: resources,
lng: "pl",
defaultNS: 'common',
keySeparator: false,
interpolation: {
escapeValue: false
}
});
export default i18n;
then my App.js
file
import React from 'react';
import './App.css';
import './i18n';
import { withTranslation } from 'react-i18next';
class App extends React.Component {
.
.
.
render() {
const { t } = this.props;
return (
button className="btn btn-primary" onClick={() => this.endMeeting()}><span className="code-tag">{ t('End meeting') }</span></button>
);
}
}
export default withTranslation('common')(App);
and lastly ./translations/pl/common.json
{
"End meeting": "Zakończ posiedzenie"
}
update
After enabling debug option it gives me this output:
i18next: languageChanged pl
i18next: initialized {debug: true, initImmediate: true, ns: Array(1), defaultNS: "common", fallbackLng: Array(1), …}
i18next::translator: missingKey pl common key_name key_name
i18next::translator: missingKey pl common key_name key_name
来源:https://stackoverflow.com/questions/61753612/react-i18next-doesnt-translate