我在根据路径检测语言时遇到问题,即http://localhost:3000/en或http://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 …Run Code Online (Sandbox Code Playgroud) 我正在使用名为 i18next 的国际化框架。我的一个组件是 p-calendar,但我不知道如何使用此框架将其国际化。有谁知道我如何使用 i18next 国际化这个组件?如果有人知道不使用 i18next 的另一种解决方案,我也可以使用。
我是 React js 的新手。我想为三元表达式中的文本创建键。
import {useTransaltion} from "react-i18next"
function dummy(){
const {t} = useTranslation();
<Typography color="white" variant="h4">
{restartLoading ? <LinearProgress /> : "Restart"}
</Typography>
Run Code Online (Sandbox Code Playgroud)
我该如何翻译“重新启动”..因为以下代码给了我一个错误:
<Typography color="white" variant="h4">
{restartLoading ? <LinearProgress /> : {t("Restart")}}
</Typography>
Run Code Online (Sandbox Code Playgroud)
{t("Restart")} :这里有错误:需要标识符。提前致谢。
我正在了解 i18next,但当Trans我尝试使用链接时却给了我谜语。到目前为止,一切都与 t{} 配合良好(我正在 React \xe2\x80\x93 JSX 中工作):
这是几乎可以工作的代码(我尝试过的其他方法根本不起作用):
\n<p className="button"><Trans i18nkey="home.p3" components={{ MyLink: <a href=\'beispiele.html\'>link</a> }}/>{t(\'home.p3\')}</p>\nRun Code Online (Sandbox Code Playgroud)\nJSON:\nde:
\n{\n (\xe2\x80\xa6)\n "home": {\n (\xe2\x80\xa6)\n "p3": "Durchst\xc3\xb6bern Sie unsere <5>Beispiele</5>.",\n (\xe2\x80\xa6)\n\n }\n}\nRun Code Online (Sandbox Code Playgroud)\nzh:
\n{\n (\xe2\x80\xa6)\n "home": {\n (\xe2\x80\xa6)\n "p3": "View <MyLink>samples</MyLink> of our work.",\n (\xe2\x80\xa6)\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n这就是我初始化 i18next 的方式:
\ni18next\n // detect user language\n // learn more: https://github.com/i18next/i18next-browser-languageDetector\n .use(LanguageDetector)\n // pass the i18n instance to react-i18next.\n .use(initReactI18next)\n // init i18next\n // for …Run Code Online (Sandbox Code Playgroud) 我迁移到 next.js 并开始使用 next-i18next。我想知道,如何使 next-i18next 从公共文件夹加载语言环境?仅当我将 locales 文件夹放在根目录中而不是公开时,它才有效。
i18n.json ;
{
"locales": ["en", "fr", "ar"],
"defaultLocale": "en",
"pages": {
"*": ["common"]
}
}
Run Code Online (Sandbox Code Playgroud)
next.config.js ;
// next.config.js
const nextTranslate = require("next-translate");
module.exports = {
...nextTranslate(),
};
Run Code Online (Sandbox Code Playgroud) i18next ×5
reactjs ×2
angular ×1
calendar ×1
jsx ×1
next-i18next ×1
next.js ×1
primeng ×1
typescript ×1