This console.log(lang);
statement is executed before the lanugage file is loaded, the problem is about concept of asynchronous code.
You will have to access the lang
object after language file is loaded.
Here is how you can fix this.
(function(win,d,id){
if(!d.getElementById(id)){
var fjs = d.createElement('script');
fjs.id=id;
fjs.src="lang.js";//this is where the language code is inserted
document.head.appendChild(fjs);
fjs.onload = function (){
//console.log(lang);
//here your lang object is accessable after load file.
}
//console.log(lang);
//here lang object is not accessible
//because it executes before the language file is loaded
}
})(window,document,'support_lang');