How do I translate custom buttons and custom buttons in a collection?

How do I translate custom buttons and custom buttons in a collection?

adjenksadjenks Posts: 22Questions: 6Answers: 0

How do I translate custom buttons and custom buttons in a collection?

Here is an example:
http://live.datatables.net/jetucedi/1/

How do I get the "Untranslated" elements to show up as "Translated".

Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    I'm afraid I don't understand your question. Do you mean you want to translate the column titles in the column visibility collection? If so, that isn't something that is built into Buttons since it is just showing the title text from the columns in your table. You'd need to translate the text there and it would automatically be reflected in the buttons.

    Allan

  • adjenksadjenks Posts: 22Questions: 6Answers: 0

    No, nothing about the column titles, or the column data.
    I'm referring to the text on the buttons, custom buttons in particular.

    If you look in this example:
    http://live.datatables.net/jetucedi/2/edit

    • The custom button "Collection Demo Untranslated" should say "Collection Demo Translated" but it does not.
    • The custom button "Test Untranslated" should say "Test Translated" but it does not.
    • Column visibility button "Column Visibility" should say "Visibilité des colonnes" and it does. It successfully translated, but it is not a custom button.
    • If you click the collection button and look at the sub buttons, "Copy" and "Column Visibility" successfully translated, but the "Test Untranslated" button did not translate.

    What configuration do I need to translate the untranslated custom buttons? I thought that the "name" key of a button was the translation reference key. But it appears not to be.

    Thank you for your feedback.

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin
    Answer ✓

    The custom button "Collection Demo Untranslated" should say "Collection Demo Translated" but it does not.

    No, it shouldn't since you have explicitly set it to be: text: "Colection Demo Untranslated", .

    If you want it to take the value from your language.buttons object, you should use:

              text: function (dt) {
                return dt.i18n("buttons.coldemo")
              },
    

    http://live.datatables.net/jetucedi/3/edit

    The same applies to the other points.

    Regards,
    Allan

  • adjenksadjenks Posts: 22Questions: 6Answers: 0

    Oh! Fabulous. I didn't realize that it could accept a function. I was wondering how to use the i18n function if the table didn't exist yet, but now I understand.
    I now see: https://datatables.net/reference/option/buttons.buttons.text
    I thought that text was the fallback text if i18n text was not available and name was the key. My mistake, I don't know why I thought that.
    Thank you very much.

This discussion has been closed.