mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
768 stars 56 forks source link

Elements translation #178

Closed bugriy closed 6 months ago

bugriy commented 1 year ago

Is it possible to translate "Show", "entries", "Next" to other languages?

mwouts commented 1 year ago

Hey @bugriy , great question, thanks for asking. The datatables.net library that we use in itables does support internationalisation, cf. https://datatables.net/plug-ins/i18n/ and https://datatables.net/reference/option/language

Maybe the second one should be easier to use. Can you try passing a language dict to the show method that would be inspired from https://datatables.net/reference/option/language ?

mwouts commented 1 year ago

This seems to work (please translate it according to your needs):

import itables.options as opt

opt.language = {
    "decimal":        "",
    "emptyTable":     "No data available in table",
    "info":           "Showing _START_ to _END_ of _TOTAL_ entries",
    "infoEmpty":      "Showing 0 to 0 of 0 entries",
    "infoFiltered":   "(filtered from _MAX_ total entries)",
    "infoPostFix":    "",
    "thousands":      ",",
    "lengthMenu":     "Show _MENU_ entries",
    "loadingRecords": "Loading...",
    "processing":     "",
    "search":         "Search:",
    "zeroRecords":    "No matching records found",
    "paginate": {
        "first":      "First",
        "last":       "Last",
        "next":       "Next",
        "previous":   "Previous"
    },
    "aria": {
        "sortAscending":  ": activate to sort column ascending",
        "sortDescending": ": activate to sort column descending"
    }
}
s1lvester commented 8 months ago

Datatables already has a huge list of i18n Plugins (see: https://datatables.net/plug-ins/i18n/) and as far as I understand @mwouts put Plugin-Support on the Roadmap for itables v2.

Up until then, one can just copy the Plug-In Code (in my case German: https://datatables.net/plug-ins/i18n/German.html#Plug-in-code) from the plugin website and pass the whole json to itables.options.language as shown above, thereby saving some effort on translating.

mwouts commented 6 months ago

Actually internationalization was the easiest of the plugins! I've just documented this here. I have tested this with itables==2.0 but it might also work with the previous versions.