react-i18next doesn't translate

允我心安 提交于 2021-01-29 05:59:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!