Closed bluetch closed 9 years ago
The code snippet that you've given does indeed assign the return value of some method to a variable, but I guess that you're looking for something else. What's the problem you're trying to solve?
thank for your reply.
I would like to do some UI change via language. ex: language=zn-cn, show 3 div with google map language=en-us, show 5 div width video so I need var language variable to change my web content.
var language = document.webL10n.getLanguage();
Or, without this library:
var language = navigator.language || navigator.userLanguage;
I tried, but didn't get anything.
var language = document.webL10n.getLanguage(); console.log(language);
and I get another bug ..below
Could you get the latest version of l10n.js? It includes several fixes, including a solution to that synchronous XMLHttpRequest warning.
I have just updated l10n.js, it fix synchronous XMLHttpRequest warning~ but my variable still unavailable.
getLanguage
only returns something useful after loadLocale has been invoked. This happens after DOMContentLoaded.
Add an event listener for the "localized" event, and you will get a correct value.
Or, if you are only interested in the user's locale, use the snippet at the end of my first reply.
Got it, thank u :)
Excuse me, I am a beginner for JS. Is possible to load variable in other script with webL10n?
ex: var myLanguage = getLanguage();
thank you.