recover data from JSON file

1

I need to implement a translation in a plugin called pikaday, which is actually a datepicker, and as the site is multilanguage I am trying to implement the i18n. pulling the translations of a JSON: link

and here in jsfiddle the example: link

What is the best way to get each translation at a time? for example, what if I want to get the value "en-br" and move to a variable? what would it be like?

    
asked by anonymous 30.09.2015 / 07:08

1 answer

2

In case you want to get the translated texts you have to use AJAX. You can also do this on the server, but assuming you do with JavaScript you can use $.getJSON . Note that AJAX ( $.getJSON ) is asynchronous, so you need to put the code that needs these texts inside the callback of $.getJSON .

So, an example, using "en-us" :

$.getJSON('https://api.myjson.com/bins/1bazm', function (i18n) {
    var picker = new Pikaday({
        field: $datePicker,
        format: 'DD/MM/YYYY',
        i18n: i18n.langs["en-us"]
    })
});

jsFiddle: link

    
30.09.2015 / 08:49