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

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


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

copyright:author[Little Red Riding Hood 2.0],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/266/202209230918127066.html