标签: i18next

i18next-browser-languageDetector 路径不起作用

我在根据路径检测语言时遇到问题,即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 …
Run Code Online (Sandbox Code Playgroud)

internationalization i18next react-i18next

0
推荐指数
1
解决办法
5832
查看次数

p-calendar 的国际化 (primeNg + i18next)

我正在使用名为 i18next 的国际化框架。我的一个组件是 p-calendar,但我不知道如何使用此框架将其国际化。有谁知道我如何使用 i18next 国际化这个组件?如果有人知道不使用 i18next 的另一种解决方案,我也可以使用。

  • 角度版本:8.2
  • PrimeNG 版本:8.1.1

calendar typescript i18next primeng angular

0
推荐指数
1
解决办法
3514
查看次数

使用 i18next React js 进行三元表达式翻译

我是 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 reactjs

0
推荐指数
1
解决办法
1064
查看次数

i18next/react:在元素中显示“未定义”的 Trans

我正在了解 i18next,但当Trans我尝试使用链接时却给了我谜语。到目前为止,一切都与 t{} 配合良好(我正在 React \xe2\x80\x93 JSX 中工作):

\n

这是几乎可以工作的代码(我尝试过的其他方法根本不起作用):

\n
<p className="button"><Trans i18nkey="home.p3" components={{ MyLink: <a href=\'beispiele.html\'>link</a> }}/>{t(\'home.p3\')}</p>\n
Run Code Online (Sandbox Code Playgroud)\n

JSON:\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}\n
Run Code Online (Sandbox Code Playgroud)\n

zh:

\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}\n
Run Code Online (Sandbox Code Playgroud)\n

这就是我初始化 i18next 的方式:

\n
i18next\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)

jsx i18next reactjs

0
推荐指数
1
解决办法
930
查看次数

next-i18next 无法从公用文件夹加载语言环境

我迁移到 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)

internationalization i18next next.js next-i18next

0
推荐指数
1
解决办法
2539
查看次数