Hello, is it possible to detect the language from browser in Playcanvas? How do i do that?
https://zzz.buzz/2016/01/13/detect-browser-language-in-javascript/
You will have to get the information from the browser.
Alternatively, you allows the user to change the language in the game as an in game option.
@yaustar yes i already have that option at game start, but i wanted to make it automatic.
I use this code for make it automatic:
var language= 1; // 1-english 2-spanish 3-deutsche
var ln = window.navigator.language||navigator.browserLanguage; //detects the browser language
if (ln[0]+ln[1]==='es') {language=2;}
else { if (ln[0]+ln[1]==='en'){language=1;}
else {if (ln[0]+ln[1]==='de') {language=3;}
else {language=1; }
}
}
and depending on the value of the variable “language” a content is loaded or another content is loaded, being able to create a button to change the language dynamically.
here’s the project where I use it:
https://playcanvas.com/project/494285/overview/computerinside
IP will give you location but not language. Someone may be English speaking but in a foreign country and visa vesa.