[javascript] How does js get the language of the browser

Little Red Riding Hood 2.0 2022-09-23 09:19:57 阅读数:348


When you want to implement multilingual, you need to get the current language of the browser

The most direct way is to access the browser's built-in navigator.language property:

var lang = navigator.language

Depending on your browser settings, this code will return different values, such as zh-CN, en-US, zh-TW, zh, etc., as shown below:

This value represents the preferred language of the current browser

版权声明:本文为[Little Red Riding Hood 2.0]所创,转载请带上原文链接,感谢。 https://javamana.com/2022/266/202209230918127066.html