Translate langauage option strings on button click
Translate langauage option strings on button click
Antriksh
Posts: 33Questions: 5Answers: 0
Hi, I have a dataTable with language option as -
language: {
"search": "INPUT",
"paginate": {
"previous": '‹',
"next": '›'
},
"info": "TOTAL Results",
"lengthMenu": "Show MENU",
}
I want to translate the strings which are static. Like "Results", "Show" on some function call because i have three languages to be chosen from. Please if you can help. @kthorngren
This discussion has been closed.
Replies
You would need to re-initialise the table with the new language settings, as they can't be changed dynamically. You would either call
destroy()
, or usedestroy
when re-initialising,Colin
But i have a plug in feature for Jump to page number as a add on pagination. I wanted to have translation for that Jump to string.
Feature -
$.fn.dataTable.ext.feature.push( {
fnInit: function ( settings ) {
var select = new $.fn.dataTable.SelectPager( settings );
return select.node();
},
cFeature: 'S'
} );
This code is in separate file though as a extension.
function selectPagination($) {
$.fn.dataTable.SelectPager = function ( context ) {
var tableId = context.nTable.id;
}
This is the code for Jump to pagination plugin.
@colin
Yep, so you could
pop
that feature off, and then add the new one with apush()
with the necessary translation,Colin
Thanks colin. Also one small query. I have language.info = "TOTAL Results".
But I want to have it conditional. Like if there is only on record in the dataTable it should be "TOTAL Result" otherwise Results.
@colin
language.info
is a fixed string, so that's not possible with the configuration. You could change the string in the element in adrawCallback
, you'd have more control of it there.Colin
Ok, Like i used infoCallback function to customize it. But it overrides the infoFiltered string also. Do we have any similar function for infoFiltered also ?
InfoCallback worked fine for INFO string.
@colin
And please can you give example, it will be a great help.
Again, that's a fixed string, so you'll need to do something in the callback - and you're right,
infoCallback
would be the place to do it, ignore what I said beforeColin
Ok, yes infoCallback is working for INFO string. But this callback is overriding the INFOFILTERED string behavior which shows in case of filtering only.
So any solution for this ?
I can append string to infoCallback but it will not detect when filtering is done or not.
@colin
See if Gyrocode's example code in this thread.
Kevin
Thanks @kthorngren . It worked