Setting language using data- attributes isn't working
Setting language using data- attributes isn't working
fisharebest
Posts: 17Questions: 1Answers: 0
I have the following HTML5 data attributes on a table:
data-language--paginate--next="Suivant"
data-language--paginate--previous="Précédent"
data-length-menu="[[10,25,100,-1],["10","25","100","Tous"]]"
The first two have no effect. The button labels are still in English. The third works, and my length menu is correctly translated.
Is translation supported using data attributes?
Do I have the right syntax, double-dashes, etc.?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
@Allan:
Forum search for "HTML5 data attributes" yields a couple of broken links:
https://editor.datatables.net/examples/advanced_init/html5-data-options
https://editor.datatables.net/examples/advanced_init/html5-data-attributes
@fisharebest:
Those links refer to the Editor, which might not be relevant to you, but it seems that some support for HTML5 data attributes arrived with DataTables 1.10.5. So check your version.
I'm refering to these datatables settings: https://datatables.net/manual/i18n
I've used them sucessfully with javascript initialisation.
I'm now moving the initialisation to HTML5 data attributes.
data-length-menu
works as expected.data-language--paginate--next
does not.I'm using datatables 1.10.13
jQuery doesn't create an object for you -
data-language-paginate-next
is the same aslanguagePaginateNext
, where as we wantlanguage.paginate.next
.So you need to do something like:
http://live.datatables.net/vexehoyu/1/edit
Allan
I was under the impression that the double-dash
--
created the nested objects.I guess it must have been a feature of whatever package I was using last, rather than jQuery or the HTML5/data.
Thanks for your answer.
FYI, to prove I wasn't imagining this, here is a package that uses double-dash to create nested options:
https://select2.github.io/options.html
Is the double dash part of jQuery? I don't see that in their documentation.
Allan
I looked in the docs, and couldn't find it either.
I had just assumed that it was, because it was implemented in select2 (and elsewhere).
It would obviously be neat to do this in DT.
Maybe only if you have lots of spare time and are feeling bored ;-)
Hehe - that was a good one. Go on - pull the other one... ;-).
In all seriousness - I agree, that would be a nice feature to support and would make the config of nested objects much easier with HTML5 attributes. I've added it to my list.
Allan