I came across this module very recently and it suits my requirements in every way, however, I'm not sure how to access the full potential of this module. Apparently the datatable is "fully internationalisable", but I don't know how to access this feature.
I'm working on a drupal 7 website so I've already installed the module and it works fine in terms of searching and sorting entries. However, my website is bilingual (English/French) so I would like the text on the datatable to switch between English and French when I switch to the English or French versions of my website (using Locale/Internationalization modules). By text I mean the words that say "search", "previous", "next", etc.
I've tried importing a French .po file, however, I didn't see any way to specify in drupal that this .po file belongs to this particular module so that didn't really help. Any ideas on how this multilingual feature can be accomplished? Even if I had to enter the translations by hand it would be fine, however, the problem is that the datatable is not "translatable" in drupal meaning that there's no option to enter your own translations as there is for a basic page or article, etc.
Any help is much appreciated.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | multilingual-datatables-1556054-26.patch | 2.96 KB | marrrc |
| #25 | multilingual-datatables-1556054-19.patch | 3.08 KB | mhmd |
| #17 | multilingual-datatables-1556054-18.patch | 1.26 KB | ey |
| #11 | multilingual-datatables-1556054-11.patch | 1.35 KB | ey |
| #9 | multilingual-datatables-1556054-9.patch | 1.17 KB | ey |
Comments
Comment #1
DrupalAddict commentedFor example, it shows here that the datatables can in fact have their user interface translated to another language as seen here in German: http://datatables.net/examples/advanced_init/language_file.html
Can this be done for the module as well? If so which files need to edited or what drupal settings should be selected?
Comment #2
DrupalAddict commentedI found a solution that seems to work. From the Drupal directory go to:
sites/all/modules/datatables/datatables.module
and add to the options on a new line (I added this on line 260):
$datatable_options['oLanguage'] = array("sSearch" => t("Search:"),
"sInfo" => t("Showing _START_ to _END_ of _TOTAL_ entries"),
"oPaginate" => array(
"sPrevious" => t("Previous"),
"sNext" => t("Next"))
);
It solved my problem, but I'm not sure if this is the proper way to do it.
Comment #3
mike27 commentedSubscribing
Comment #4
7wonders commented#2 seems to be a good start
Comment #5
robin van emden commentedTranslations can be found at http://www.datatables.net/plug-ins/i18n.
As text files, they can be added like this in datatables.module:
$datatable_options['oLanguage']['sUrl'] = "path_to_the_file/nl_NL.txt";
Easy to add this as an option field. Switching according to language would be a possible next step.
Comment #6
jehu99 commentedHere's my quick and dirty hack (added to template_preprocess_datatables_view, line 287):
Now i can place the language-files (de.txt, es.txt...) to [my-theme-path]/datatables/languages/
It would be nice to see a generic solution builtin to datatables.module. Perhaps with possibillity to translate datatables from drupals string translation interface.
Comment #7
swas commentedI found another solution without touching the source code of the module. Using the "drupal_add_js function"
This overwrite the JS generated by the datatables module.
Also will be possible specify the translation file:
I think it's a good solution while waiting for an official update that supports natively translations.
Comment #8
dsnoeck commentedMoreover,
in the JavaScript: datatables/js/datatables.js
some text are not translatable, like "Show Details" or "Hide Details".
Please use the Drupal.t() function:
$(this).html(Drupal.t('Show Details'));Comment #9
ey commentedI've created a patch which follows the #2, since I think it's the most proper way to make the internationalization in Drupal way. Please review the patch so that it can be committed to next release.
Comment #10
duellj commentedLooks good pc-wurm! Any reason why you didn't set the translations of some of the entries? I think it's save to pass through t() event though they have tokens that will be interpolated by DataTables.js (as long as the translator doesn't translate the tokens)
Comment #11
ey commentedOh, it is not the complete patch. Here is the complete one. Maybe I shouldn't create patches just before going to bed, sorry :D
Comment #12
duellj commentedLooks good, thanks pc-wurm!
Comment #13
ey commentedThanks for the reviewing, I've committed and pushed the patch to dev.
Comment #14
duellj commentedCongrats on your first commit pc-wurm!
Comment #15
ey commentedThanks duellj :)
Comment #16
dsnoeck commentedSorry, but you forgot to implement the fix from my comment in #8.
Comment #17
ey commented@dnsnoeck, please review the following patch to the latest dev. I just made the changes you proposed, I don't have the time to test now. I'd be glad if you would review and test it.
Comment #19
slashrsm commentedApplied this patch and it works like a charm. Thanks!
Comment #20
qunabu commentedThe proper way without any hacks it to add this code to you JS file
Code above amends DataTables defaults https://datatables.net/examples/advanced_init/defaults.html
You can find all localisations on page https://datatables.net/plug-ins/i18n/
Comment #23
arkener commentedComment #25
mhmd commentedThe issue still exists when using theme function in code attached patch is the fix
Comment #26
marrrc commentedFixed the patch from #25 to apply correctly on any path setup.