【发布时间】:2020-04-04 12:30:34
【问题描述】:
我将 React 与 react-i18next 一起使用,并生成我使用 i18next-scanner 的 i18n json 文件。
正如我所见,react-i18next json 文件需要密钥 "translation":{...} 来处理其他所有内容。
如何自动添加i18next-scanner?
编辑:
i18n.js
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import de from './de/resource.json';
import en from './en/resource.json';
i18n.use(initReactI18next).init({
debug: true,
fallbackLng: 'de',
lng: 'en',
load: 'all',
ns: false,
resources: { de, en },
react: { wait: true },
interpolation: { escapeValue: false },
});
// eslint-disable-next-line
export const t = i18n;
这就是我需要它工作的方式: src/i18n/en/resource.json
{
"translation": {
"component": {
i18next-scanner 是这样处理文件的: src/i18n/en/resource.json:
{
"component": {
而我需要的是 react-next 不需要此翻译或 i18next-scanner 考虑到这一点。
【问题讨论】:
-
不正确,json中不需要这个前缀。
-
@felixmosh 我将添加代码。如果我没有这个
translation密钥,它就不起作用
标签: i18next react-i18next