Overriding language strings

Overriding language strings

princeofnaxosprinceofnaxos Posts: 26Questions: 9Answers: 0

Is there a possibility to override the language strings when use language.url? I would like to use the translations provided, but just change one of them to another string.

E.g.:

language: {
     url: 'de.json',
     search: 'Suche etwas hier'
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,520Questions: 1Answers: 10,664 Site admin
    Answer ✓

    No sorry. The strings from the de.json file would be used in preference to the local ones.

    I recognise that this isn't particularly useful and it will be corrected in the next major version.

    In the mean time you would need to make the Ajax call to get the language file yourself, modify the object as needed and then pass it into language.

    Allan

  • halloeihalloei Posts: 23Questions: 6Answers: 0

    I'm needing the exact same thing right now. Will use the workaround then. Thanks.

  • Kar.maKar.ma Posts: 1Questions: 0Answers: 0
    edited May 2017

    I needed the same. The workaround was a bit complicated to find, but the final solution is pretty straightforward.

    My previous javascript code was:

    dataTableMesi = $('#tabellaMesi').DataTable({
      "searching": false,
      "language": {
        "url": "datatables/italian.lang",
        "sLengthMenu": "Visualizza _MENU_ mesi",
      },
      data: dataSetMesi,
      columns: myColumnsMesi
    });
    

    Now I replaced it with:

    function doDataTableMesi(lang_ita_mod){
      dataTableMesi = $('#tabellaMesi').DataTable({
        "searching": false,
        "language": lang_ita_mod,
        data: dataSetMesi,
        columns: myColumnsMesi
      });
    }
    $.ajax({
      dataType: "json",
      url: "datatables/italian.lang",
      data: "",
      success: function(data){
        var lang_ita_mod = data;
        lang_ita_mod.sLengthMenu = "Visualizza _MENU_ mesi";
        doDataTableMesi(lang_ita_mod);
      }
    });
    
  • allanallan Posts: 64,520Questions: 1Answers: 10,664 Site admin

    That's a good way of doing it - thanks for posting your solution.

    Allan

This discussion has been closed.