Using the json file for language + personnal translations in the DT options
Using the json file for language + personnal translations in the DT options
![MelodyNelson](https://secure.gravatar.com/avatar/621dc705365aa283355fb6b813f72a14/?default=https%3A%2F%2Fvanillicon.com%2F621dc705365aa283355fb6b813f72a14_200.png&rating=g&size=120)
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Hi,
I'm using the french json file language for DT and sometimes I just want to change some translation without changing the json file (in case I need to update the file with next versions of DT, I don't want to lose my adaptations).
For example, I have this setting for all my tables with default options and I need to change one string.
I'm using a local json file + one pamaterer for the buttons but it created problems with the other strings.
Is it because we can't mix the 2 methods or I didn't do it right ?
Object.assign(DataTable.defaults, {
// language: { url: '//cdn.datatables.net/plug-ins/2.0.0/i18n/fr-FR.json' },
language: { url: 'js/datatables/fr-FR.json' },
language: {
"buttons": {
"colvisRestore": "tout sélectionner"
}
},
lengthMenu: [5, 10, 25, 50, 100, { label: 'Tout', value: -1 }],
pageLength: 25,
pagingType: 'simple_numbers', // numbers, simple_numbers, full_numbers
processing: true,
layout: {
topStart: 'pageLength',
topEnd: {
search: {
text: '_INPUT_',
placeholder: 'Rechercher dans la liste'
},
},
bottomStart: 'info',
bottomEnd: 'paging'
},
initComplete: function () {
$('nav.pagination').addClass('is-small');
$('div.dtsp-panesContainer button').addClass('is-small');
},
drawCallback: function (settings) {
$('nav.pagination').addClass('is-small');
},
});
Thank you
Replies
The Datatables options are a Javascript object which supports only unique keys. You can combine both language options into one object like this:
Kevin
Thanks Kevin,
I just try but the « personnal translation » for « ColvisRestore » doesn't seems to be used by DT.
I've made a test case :
https://live.datatables.net/bomiwixa/1/edit?html,css,js,output
Did I miss something ?
The issue here is that you are setting the defaults. It is a sequence of events problem.
colvisRestore
so it is setGiven the sequence, although the outcome might not be what is desired, I think it is correct.
If you set the value in the DataTables initialisation, it works without problem: https://live.datatables.net/bomiwixa/3/edit .
Allan
Thanks Allan
I understand. I was putting it in the « general default options » because I didn't want to repeat it for each table.
The website is not finished yet and I probably already have 30 different tables, I'm trying to put a maximum of common settings in the general default options.
Now it works. I have kept the language file in french in my « general default options » :
And change the string for the colvis button in the table initialisation without the link to the json file :