[英]Switch between different website languages - documentElement.lang
I want to use a switch
and individually target each English version of the website.我想使用一个
switch
并分别定位网站的每个英文版本。
I tried using en/lang
, but it does not work...我尝试使用
en/lang
,但它不起作用......
The variable populates a div
with the string.该变量用字符串填充一个
div
。
I could not use just the case 'en'
since the English text is different for both SE and NO, so I need to target the English version of SE and NO individually.我不能只使用
case 'en'
因为 SE 和 NO 的英文文本不同,所以我需要分别针对 SE 和 NO 的英文版本。
switch (document.documentElement.lang) { // ------------------------------ SE ----------------------------------- case 'en/se': var heroTitle = 'This is an se english title'; break; case 'se': var heroTitle = 'This is a swedish title'; break; // ------------------------------ NO ----------------------------------- case 'no/en': var heroTitle = 'This is a no english title'; break; case 'no': var heroTitle = 'This is a no title'; break; }
Look into i18next -- its by far the best way to do translations in JS.查看 i18next——它是迄今为止在 JS 中进行翻译的最佳方式。
https://www.i18next.com/ https://www.i18next.com/
But to answer your question you'll want the full country code and lang.但要回答您的问题,您需要完整的国家代码和语言。 like
en_US
and en_SE
I suppose.我想像
en_US
和en_SE
。 You can get the user's language with navigator.language
您可以使用
navigator.language
获取用户的语言
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.