i18next-browser-languageDetector路径不起作用

问题描述 投票:0回答:1

我在检测基于路径的语言时遇到问题,即http://localhost:3000/enhttp://localhost:3000/en/subpage应该将我的页面翻译成英语。我可以通过单击按钮并调用i18n.changeLanguage('en')来翻译它,但探测器似乎无法正常工作。

import i18n from "i18next";
import { reactI18nextModule } from "react-i18next";
import LngDetector from "i18next-browser-languagedetector";
import backend from "i18next-xhr-backend";


const detectionOptions = {
    order: ['path', 'cookie', 'navigator', 'localStorage', 'subdomain', 'queryString', 'htmlTag'],
    lookupFromPathIndex: 0

}


i18n
    .use(LngDetector)
    .use(backend)
    .use(reactI18nextModule) // passes i18n down to react-i18next
    .init({
        ns: ['translation', 'main'],
        defaultNS: 'translation',
        lng: "pl",
        fallbackLng: 'pl',
        detection: detectionOptions,
        keySeparator: false, // we do not use keys in form messages.welcome

        interpolation: {
            escapeValue: false // react already safes from xss
        },
        debug: true,
        react: {
            wait: true
        }
    }, (err, t) => {
        if (err)
            console.error(err)
    });


export default i18n;
internationalization i18next react-i18next
1个回答
0
投票

解决方案:使用语言检测器时,不应将i18n.lng属性设置为

© www.soinside.com 2019 - 2024. All rights reserved.