Export datatble in translated language when using a 3rd party Translator.
Export datatble in translated language when using a 3rd party Translator.
chsxe
Posts: 8Questions: 3Answers: 0
Hi,
If I am using a 3rd party plugin to translate my page, how can I get the datatable to export the data in the chosen languag e.g If i translate my page to German and I export the datatable to excel, it's exported in English (I would like to have it in the chosen language "German").
Thanks
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Does the 3rd party plug-in update the DOM? Or does it do something else? You would need to call
rows().invalidate()
if it updates the DOM so DataTables can read in the translations (the exported data comes from cache).Allan
It translates all text in the DOM. It detects and translates content, much like a standard browser translator.
How would I implement that on Export, say for example inside exportOptions?
Thanks
Sounds like Allan's suggestion of using
rows().invalidate()
might be the correct option. You will want to use that after the translation is complete. The API will tell Datatables to re-read the DOM to update its data cache which is what is used for exporting.Kevin
@kthorngren I have a function that is called when the language is changed, inside it I have done what was suggested. When I Export the table to Excel after I have translated it to another language, it is still exported in English.
How would i have it Cache the translated table data as it currently sits (translated) based on this code snippet:
Without seeing it its hard to say. Can you provide a link to your page or a test case replicating the issue?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Do you get any errors in your browser's console?
Kevin
@kthorngren I apologise, it is working. I just didn't notice because instead of exporting just the visible 10 rows, it had been exporting all of them. The 10 visible rows where at the bottom of my spreadsheet. My next problem is to export only the 10 visible translated rows.
Thanks
See if this works:
Kevin
@kthorngren To get this working this what needs to happen when the Language changed function is called, only use invalidate('dom'). Do not use draw() as this obscures the table data.
In ExportOptions, if you don't specify rows: visible, you will end up with the visible rows translated, and the rest of the data in the default language.
Thanks for your help.
Great, thanks for the update. Glad you got it working.
Kevin