如何使用i18next本地化我的网站? [英] How to use i18next to localise my website?

查看:131
本文介绍了如何使用i18next本地化我的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的网站,没有后端,只有纯HTML页面.

I have a very simple website with no backend, just pure html pages.

我需要为此网站提供英语/中文版本,我需要实现的是在NavBar上有一个按钮,当用户单击此按钮时,整个网站上的措辞将更改为中/英文.

I need to have English/Chinese versions for this website, what I need to achieve is have a button on NavBar, when users click this button, the wording on entire website will be changed to Chinese/English.

我所看到的所有示例都需要这样的东西:

All the examples I have seen that they are all require something like this:

localize(".nav");

这是否意味着我需要执行以下操作:

So does it mean that I need to do something like this:

localize("body");

为了切换整个网站的语言?

in order to get the whole website language switched?

推荐答案

根据文档,这里是支持的框架.由于您的项目是一种基本的HTML,因此您应该使用 https://github.com/mthh/loc- i18next .当您在TAG上初始化模块时,应确保有data-i18n="myKey"属性和需要转换的字符串键.因此,localize("body");应该翻译整个正文,但是您必须使用字符串键将data-i18n属性添加到每个标签

According to the doc here is the list of supported-frameworks. As your project is a basic HTML one you should use this https://github.com/mthh/loc-i18next. When you init the module on a TAG you should me make sure there is the data-i18n="myKey" attribute with the key of string that need to be translated. So localize("body"); should translate the whole body but you must add the data-i18n attribute to each tag with a string key

这篇关于如何使用i18next本地化我的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆