Irrelon / jquery-lang-js

i18n Allow instant language switching on HTML pages without reloading the page.
https://www.irrelon.com
362 stars 132 forks source link

Question about lang.dynamic #137

Closed KevinKurosaki closed 3 years ago

KevinKurosaki commented 3 years ago

I have a method which makes a call to my API where the json data is located and I want to load that data into the webpage without using a file. I was wondering if I could load json data from other source which is not a file.json but it has the same structure.

I have tried a couple of things but it didn't work: lang.dynamic('th', 'link to API call'); lang.dynamic('th', functionRetreivesJSONFromAPI());

Irrelon commented 3 years ago

That should be very easy.

The lanugage packs are defined in lang.pack which is an object where the key is the name of the language e.g. "en" and the value is the JSON data for the language pack.

Take a look at the source code here to see how it works after a pack is loaded: https://github.com/Irrelon/jquery-lang-js/blob/00dec9dc726f45f47ef3f9cb4b96888213845495/js/jquery-lang.js#L178