我尝试过在我的react应用程序中实现react-i18next,但是它没有给出一个f.我希望它能起作用
控制台不显示任何错误。只是无法翻译。
谁有类似的问题,可以帮我找出为什么它不能翻译?
我的i18n.js文件内容:
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;然后我的App.js文件
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);最后是./translations/pl/common.json
{
"End meeting": "Zakończ posiedzenie"
}更新
启用调试选项后,它将为我提供以下输出:
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发布于 2022-03-28 19:12:31
尝试添加“ns‘param”
i18next.init({
ns: ['common', 'moduleA', 'moduleB'],
defaultNS: 'moduleA'
}在你的情况下
ns: ['common']https://stackoverflow.com/questions/61753612
复制相似问题