将i18next值放在变量JS中

发布于 2025-01-26 10:51:00 字数 851 浏览 4 评论 0原文

我有一个JS代码,该代码在一段时间后会更改文本,并且我想使用I18Next翻译,以使“性能,灵活性”等单词超过1个语言。我必须解决的想法是将i18next值放在变量中,并用变量将JS代码中的单词替换。但是我不知道如何使用i18next将他的翻译单词放入变量中,如果有人可以帮助我,我会非常感激!

JSON文件

EN-US

"index" : {
    "performance" : " performance",
    "flexibility" : "flexibility"
}

PT-PT

"index" : {
    "performance" : " Desempenho",
    "flexibility" : "Flexibilidade"
}

JS代码

var typed1 = new Typed('#typed1', {
    strings: ["performance", "flexibility", "scalability."],
    typeSpeed: 50,
    backSpeed: 20,
    smartBackspace: true,
    loop: true
});
var typed1 = new Typed('#typed2', {
    strings: ["Protection", "Sophisticated", "Flexibility"],
    typeSpeed: 100,
    backSpeed: 50,
    smartBackspace: true,
    loop: true
});

I have a JS code that changes the text after some time and I want to use i18next translations in that to make the words "performance, flexibility" etc.. be in more than 1 language. the idea I had to solve this was putting the i18next value inside a variable and substitue the words in the JS code with the variables. but I don't know how to use i18next to put his translated words inside a variable, if someone could help me I would be very grateful!

Json files

en-US

"index" : {
    "performance" : " performance",
    "flexibility" : "flexibility"
}

pt-PT

"index" : {
    "performance" : " Desempenho",
    "flexibility" : "Flexibilidade"
}

JS code

var typed1 = new Typed('#typed1', {
    strings: ["performance", "flexibility", "scalability."],
    typeSpeed: 50,
    backSpeed: 20,
    smartBackspace: true,
    loop: true
});
var typed1 = new Typed('#typed2', {
    strings: ["Protection", "Sophisticated", "Flexibility"],
    typeSpeed: 100,
    backSpeed: 50,
    smartBackspace: true,
    loop: true
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文