Good day, everybody! I want to make multi lang landing page. There will be select with languages, when you select your lang, JS replace text with another lang from JSON file. But I have got problem with JSON and JS, when I trying to load JSON. I read a lot of guides but nothing help me. What I have: There is json file - lang.json. Here is some part of it:
{
"navigation-list" : {
"en" : ["About", "Contacts", "Cases"],
"ru" : ["О нас", "Контакты", "Случаи"],
},
"fb-like" : {
"en" : "Like",
"ru" : "Нравится",
},
"facebook-share" : {
"en" : "Share",
"ru" : "Поделиться",
},
"twitter-tweet" : {
"en" : "Tweet",
"ru" : "Твитнуть",
},
"twitter-follow" : {
"en" : "Follow on twitter",
"ru" : "Читать в twitter",
},
}
and I have main.js file where above JSON file should be imported as var. I used scripts from another guys: Load local JSON file into variable and load json into variable
Here is code:
var json = (function () {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': 'lang.json',
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})();
console.log(json);
But all the day I get in console null.
Also, I tried another ways, such as:
var lang={};
jQuery.getJSON("lang.json", function(data) {
lang.push(data);
});
console.log(lang);
Nothing help me. What do i do wrong?
Thanks in advance!