i18n plugin files are not in JSON format

i18n plugin files are not in JSON format

greenflashgreenflash Posts: 58Questions: 5Answers: 0

I was puzzled for a while when upgrading to DataTables 1.10 because I couldn't get the language files to work. The problem of course is that language.url seems to expect a JSON file and the lang files are not valid JSON until you strip out the comments. Is there a set of .json files that I have missed? I want to load the files from my own server rather than use CDN.

The other things that misled me slightly were (a) the statement on https://datatables.net/manual/i18n that the files are "ready to be used" and (b) the fact that DataTables seems to fail silently if it can't use the language file. I don't know if it would be useful to have a console warning?

Campbell

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Is there a set of .json files that I have missed?

    The files on the CDN are all valid JSON. For example on the Afrikanns page it gives you the address:

    //cdn.datatables.net/plug-ins/f2c75b7247b/i18n/Afrikaans.json

    Allan

  • greenflashgreenflash Posts: 58Questions: 5Answers: 0

    Yes, I can do that. But I just wondered if there's an easier way of converting all 50 odd files to JSON? It would be nice to have the JSON files available on GitHub.

    Anyway, thanks for all your help and a great product.

    Campbell

  • greenflashgreenflash Posts: 58Questions: 5Answers: 0

    I've realised that I can just include the appropriate .lang file in the PHP script that generates the JavaScript and this solves my problem. It would still be nice though to have the JSON files available on GitHub just in case I wanted to use the url way of getting the language file. Are there any advantages (performance?) in getting the language file by Ajax, or is it just a matter of convenience which method to use?

    Campbell

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Are there any advantages (performance?) in getting the language file by Ajax

    Actually I would say that getting the language by Ajax is a disadvantage in terms of Ajax since another HTTP request is required. It is only really provides for convenience on multi-language sites.

    Allan

  • greenflashgreenflash Posts: 58Questions: 5Answers: 0

    Ah, OK, I'm with you now I think. You mean a multi-language site where you can switch language on the page itself by clicking a flag or whatever, and then you just dynamically change the language strings using an Ajax request. I have a multi-language site, but the language is determined at load time from the browser language settings and can't be changed once loaded. So in my case doing a PHP include on the appropriate lang file is probably the best best.

    Thanks again for the help.

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Sort of... :-). DataTables doesn't currently have the ability to change language dynamically so it would be a page reload, but the language file URL would be filled in with a session variable or similar that defines the language.

    The Ajax loading option is something I almost regret including. It can be useful, but should certainly be used with care!

    Allan

This discussion has been closed.