Setting up i18n for plugins in the json file with the language url

Setting up i18n for plugins in the json file with the language url

Jean-Francois PouliotJean-Francois Pouliot Posts: 3Questions: 1Answers: 0

Good afternoon!

My question is quite simple. I can setup the i18n for my dataTables this way (and it works fine) :

        "language": {
            "url": "./static/lang/dataTables.french.json",
            "select": {
                "rows": {
                    "_": "%d lignes sélectionnées",
                    "1": "1 ligne sélectionnée"
                }
            }
        }

I was wondering if it was possible to include the i18n messages for the select plugin (or any other plugins) into the i18n json file. This would be cleaner for me since I would have all my i18n messages at the same place. Additionnaly, since I have more than one instance of dataTables to setup, it would prevent me form repeating all the messages for each table.

I gave the example with the select plugin but I have the same question for the editor plugin.

Thank you!

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi,

    Yes indeed you can. Just copy / paste the select property into your language file.

    Regards,
    Allan

  • Jean-Francois PouliotJean-Francois Pouliot Posts: 3Questions: 1Answers: 0

    Hi Allan,

    Thank you for the quick reply. I did as you said for the select plugin and it worked fine.

    Can I do something similar with the editor plugin? Is there a language url equivalent for the datatables editor?

    Thank you again

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited April 2019

    No - unfortunately at this time the only way to get language information from a JSON file is to Ajax load it yourself and then pass that in during the Editor initialisation - for example:

    $.getJSON( 'myLanguage.file', function (json) {
      var editor = new $.fn.dataTable.Editor( {
        fields: ...,
        i18n: json
      } );
    } );
    

    Regards,
    Allan

  • Jean-Francois PouliotJean-Francois Pouliot Posts: 3Questions: 1Answers: 0

    I did as you said and it works great.

    Thank you for your answer Allan.

This discussion has been closed.