数据表翻译不起作用

时间:2016-11-07 21:10:21

标签: javascript datatables

我正在努力完成Datatables翻译。据我所知documentation,它应该通过Ajax加载语言文件。

我根本没有看到对文件/static/assets/js/datatables_de.json的HTTP请求(不在Chrome的开发人员工具栏中,也没有在服务器上)。我做错了什么?

$(document).ready(function() {
    var hitstable = $('#hitstable').DataTable({
        "ajax": '/customer/ajax_get_hits',
        "stateSave": true,
        "aoColumnDefs": [
            { aTargets: [0], bSortable: false },
            { aTargets: [1], bSortable: true },
            { aTargets: [2], bSortable: true },
            { aTargets: [3], bSortable: true },
            { aTargets: [4], bSortable: true },
            { aTargets: [5], bSortable: true },
            { aTargets: [6], bSortable: true },
            { aTargets: [7], bSortable: true },
            { aTargets: [8], bSortable: false },
        ],
        "bServerSide": true,
        "order": [[ 1, "asc" ]],
        "oLanguage": {
            sProcessing: '<img src="/static/assets/img/loading.gif">'
        },
        "language": {
            "url": "/static/assets/js/datatables_de.json"
        }
    });
});

1 个答案:

答案 0 :(得分:2)

我想我已经弄明白了。

似乎oLanguage和语言不兼容。 oLanguage被认为是遗留的,只需将其添加到配置中,它就会覆盖语言字段。

sProcessing包含在语言文件中,因此您无需将其添加到配置中。

尝试删除oLanguage: https://jsfiddle.net/fzg38jta/1/

或者在oLanguage中添加语言:

{
    "sProcessing":   "Próiseáil...",
    "sLengthMenu":   "Taispeáin iontrálacha _MENU_",
    "sZeroRecords":  "Gan aon taifead meaitseáil aimsithe",
    "sInfo":         "_START_ Showing a _END_ na n-iontrálacha  _TOTAL_",
    "sInfoEmpty":    "Showing 0-0 na n-iontrálacha  0",
    "sInfoFiltered": "(scagtha ó _MAX_ iontrálacha iomlán)",
    "sInfoPostFix":  "",
    "sSearch":       "Cuardaigh:",
    "sUrl":          "",
    "oPaginate": {
        "sFirst":    "An Chéad",
        "sPrevious": "Roimhe Seo",
        "sNext":     "Ar Aghaidh",
        "sLast":     "Last"
    }
}