DataTables Editor i18n using external file : need complete dynamic solution

DataTables Editor i18n using external file : need complete dynamic solution

ronald.woutersronald.wouters Posts: 9Questions: 4Answers: 0

Hi all,

I have read some old posts on editor i18n external file config but none of them completely answers my questions.

I need complete external i18n configuration for the editor based on a language choice by the end-user.
It seems to me the only way to achieve this right now is to put the complete configuration for the editor in external, language specific json file(s), so also put the complete "i18n" part in there. Then retrieve that complete config doing an ajax call myself first and then create the editor using the "new" constructor stuff.
Something like this

// get complete json editor config object, including fields, buttons, form titles, etc.
var myEditorConfigJSonObject = // return from ajax call
editor = new $.fn.dataTable.Editor(myEditorConfigJSonObject);

For the moment I have the following

            return  $('#myTable').DataTable({
                "dom" : "Bfrti",
                // ...
                "buttons": [
                    { extend: "create", editor: editor },
                    { extend: "edit",   editor: editor },
                    { extend: "remove", editor: editor }
                ],
                "language": {
                    "url" : "/api/dti18n"
                }
            });

and in the json file returned by the url mentioned in the "language" option above I have

{
  {
// ... a lot of unimportant stuff here
  },
  "buttons": {
    "create": "Nouveau",
    "edit": "Modifier",
    "remove" : "Supprimer"
  }
}

This works fine ... but only for the button text obviously. Not for the create, edit or delete form title text and submit button.
Also not for the field labels on the forms.

but if I put something like this in my json

"buttons": {
    "create": {
      "button": "Nouveau",
      "title":  "Créer nouvelle entrée",
      "submit": "Créer"
    },

I get javascript errors when the page is shown in the browser.

Surely there must be an easier way to do this ?
As I mentioned in the beginning of this post, is completely externalizing everything and getting it via ajax myself the only "really" complete and dynamic option ?

Regards,
Ronald Wouters
Belgium

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin
    Answer ✓

    is completely externalizing everything and getting it via ajax myself the only "really" complete and dynamic option ?

    Currently yes. Editor's initialisation is always synchronous at the moment, and an Ajax fetch for the language information would make it async. That's not to say that it isn't something I don't want to include in future (we've got a feature issue for it in fact) its just that it hasn't been implemented yet.

    Currently yes, you would need to make the Ajax call yourself to get Editor language information from a JSON file.

    Allan

This discussion has been closed.