5 Replies
Math Notermans

The system language as is is not selectable in all browsers. As far as i know only in IE you can find the system language.

However you can find the user preferred browser language. That doesnot is the same as the system language. Users can have a preferred browser lang that differs from his/her system language. And its not fool proof because a user can change that anytime.

That said... this javascript code detects the browser language...

//detect the language preference of the user's browser
var userLanguage = window.navigator.userLanguage || window.navigator.language;

console.log("language is: "+userLanguage );
alert("language is: "+userLanguage);

I tested this in Chrome only.


Kind regards,
Math



Enrique Reina

Hi Math,
thank you so much for your support.
I tried it and the browser now reports: language is: de
how can I now assign the read out language to a variable?
I created the text variables "language" and "userLanguage" in my project, but nothing happens. The value "de" is not written to the variable

Math Notermans

Hi Enrique,

The variable is now in Javascript set... so userLanguage is a Javascript variable... as is Storyline cannot do much with that.

To assign any given value to a Storyline variable you need to create them in your SL project...
Say your SLvar is 'browserLang'...

You first need to target the SL player...
var player = GetPlayer();

then you can get the variables at will...
player.GetVar("browserLang");

or set the variables at will...
player.SetVar("browserLang",userLanguage);

Added a working sample....

Kind regards,
Math

OWEN HOLT
Math Notermans

That said... this javascript code detects the browser language...

//detect the language preference of the user's browser
var userLanguage = window.navigator.userLanguage || window.navigator.language;

console.log("language is: "+userLanguage );
alert("language is: "+userLanguage);

I tested this in Chrome only.

Just tested in IE and Edge. Works in both.