用 "translation" 包裹扫描的 json |国际化扫描仪
wrap scanned json with "translation" | i18n-scanner
我将 React 与 react-i18next
一起使用并生成 i18n json 文件我使用 i18next-scanner
.
如我所见,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
考虑到这一点。
由于你使用的是内联资源,所以需要加上"translations"前缀,你可以在usage里做。
// 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: ["translation"], // <-- specify the NS's exists
defaultNS: "translation", // <-- what is the default namespace
resources: { de: {translation: de}, en: {translation: en} }, // <-- this is the change
react: { wait: true },
interpolation: { escapeValue: false },
});
// eslint-disable-next-line
export const t = i18n;
这个"translation"前缀在i18nextspace中叫做namespace。这意味着您的翻译文件可以拆分成单独的文件。
注意,当您使用内联资源时,这意味着当用户只使用一种语言时,您的包文件将包含所有翻译。
查看 i18next-xhr-backend,它将在运行时获取用户所需的语言。
我将 React 与 react-i18next
一起使用并生成 i18n json 文件我使用 i18next-scanner
.
如我所见,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
考虑到这一点。
由于你使用的是内联资源,所以需要加上"translations"前缀,你可以在usage里做。
// 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: ["translation"], // <-- specify the NS's exists
defaultNS: "translation", // <-- what is the default namespace
resources: { de: {translation: de}, en: {translation: en} }, // <-- this is the change
react: { wait: true },
interpolation: { escapeValue: false },
});
// eslint-disable-next-line
export const t = i18n;
这个"translation"前缀在i18nextspace中叫做namespace。这意味着您的翻译文件可以拆分成单独的文件。
注意,当您使用内联资源时,这意味着当用户只使用一种语言时,您的包文件将包含所有翻译。 查看 i18next-xhr-backend,它将在运行时获取用户所需的语言。