Setting language using data- attributes isn't working

Setting language using data- attributes isn't working

fisharebestfisharebest 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

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    @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.

  • fisharebestfisharebest Posts: 17Questions: 1Answers: 0
    edited January 2017

    Those links refer to the Editor

    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

  • allanallan Posts: 61,734Questions: 1Answers: 10,111 Site admin
    Answer ✓

    jQuery doesn't create an object for you - data-language-paginate-next is the same as languagePaginateNext, where as we want language.paginate.next.

    So you need to do something like:

    data-language='{"paginate":{"next":"Forward!"}}'
    

    http://live.datatables.net/vexehoyu/1/edit

    Allan

  • fisharebestfisharebest Posts: 17Questions: 1Answers: 0

    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.

  • fisharebestfisharebest Posts: 17Questions: 1Answers: 0

    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

  • allanallan Posts: 61,734Questions: 1Answers: 10,111 Site admin

    Is the double dash part of jQuery? I don't see that in their documentation.

    Allan

  • fisharebestfisharebest Posts: 17Questions: 1Answers: 0

    Is the double dash part of jQuery?

    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 ;-)

  • allanallan Posts: 61,734Questions: 1Answers: 10,111 Site admin

    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

This discussion has been closed.