如何更改DataTable的语言

PHP*_*ari 29 jquery datatables

我在会话变量中存储用户想要翻译的语言,但我不知道将其传递给DataTables

在datatables网站上找到了这个解释,但这并没有真正帮助,我在哪里设置语言参数?

Man*_*eUK 61

您必须创建一个语言文件,然后使用以下方法设置它:

"oLanguage": {
  "sUrl": "media/language/your_file.txt"
}
Run Code Online (Sandbox Code Playgroud)

我不确定你使用的服务器语言,但这样的东西可以在PHP中使用:

"oLanguage": {
  "sUrl": "media/language/custom_lang_<?php echo $language ?>.txt"
}
Run Code Online (Sandbox Code Playgroud)

在哪里language匹配您的特定语言的文件名.

或更改个人设置:

"oLanguage": {
  "sLengthMenu": "Display _MENU_ records per page",
  "sZeroRecords": "Nothing found - sorry",
  "sInfo": "Showing _START_ to _END_ of _TOTAL_ records",
  "sInfoEmpty": "Showing 0 to 0 of 0 records",
  "sInfoFiltered": "(filtered from _MAX_ total records)"
}
Run Code Online (Sandbox Code Playgroud)

欲了解更多详情,请阅读:http://datatables.net/plug-ins/i18n

  • 不错哦!!你可以试试其他语言 `"oLanguage": { "sUrl": "//cdn.datatables.net/plug-ins/1.10.7/i18n/&lt;LANGUAGE&gt;.json" }` 一个打开的 https://www. datatables.net/plug-ins/i18n/ 并查看翻译是单击您的语言稍后获取 CDN 链接:) (2认同)

小智 27

//Spanish
$('#TableName').DataTable({
    "language": {
        "sProcessing":    "Procesando...",
        "sLengthMenu":    "Mostrar _MENU_ registros",
        "sZeroRecords":   "No se encontraron resultados",
        "sEmptyTable":    "Ningún dato disponible en esta tabla",
        "sInfo":          "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
        "sInfoEmpty":     "Mostrando registros del 0 al 0 de un total de 0 registros",
        "sInfoFiltered":  "(filtrado de un total de _MAX_ registros)",
        "sInfoPostFix":   "",
        "sSearch":        "Buscar:",
        "sUrl":           "",
        "sInfoThousands":  ",",
        "sLoadingRecords": "Cargando...",
        "oPaginate": {
            "sFirst":    "Primero",
            "sLast":    "Último",
            "sNext":    "Siguiente",
            "sPrevious": "Anterior"
        },
        "oAria": {
            "sSortAscending":  ": Activar para ordenar la columna de manera ascendente",
            "sSortDescending": ": Activar para ordenar la columna de manera descendente"
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

还使用cdn:

//cdn.datatables.net/plug-ins/a5734b29083/i18n/Spanish.json
Run Code Online (Sandbox Code Playgroud)

更多选择:http://www.datatables.net/plug-ins/i18n/English [| 西班牙语| 等等]


小智 9

抱歉恢复这个线程,我知道有解决方案,但很容易用数据表更改语言.在这里,我给你留下了我自己的数据表示例.

$(document).ready(function ()
// DataTable
        var table = $('#tblUsuarios').DataTable({
            aoColumnDefs: [
                {"aTargets": [0], "bSortable": true},
                {"aTargets": [2], "asSorting": ["asc"], "bSortable": true},
            ],
            "language": {
                "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json"
            }

    });
Run Code Online (Sandbox Code Playgroud)

您从以下链接获得的语言:

http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n

只需将语言选项中的URL值替换为您喜欢的值即可.请记住始终使用逗号


为我工作,希望它对任何人都有用.

最好的祝福!


Ben*_*ier 6

法语翻译:

$('#my_table').DataTable({
  "language": {
    "sProcessing": "Traitement en cours ...",
    "sLengthMenu": "Afficher _MENU_ lignes",
    "sZeroRecords": "Aucun résultat trouvé",
    "sEmptyTable": "Aucune donnée disponible",
    "sInfo": "Lignes _START_ à _END_ sur _TOTAL_",
    "sInfoEmpty": "Aucune ligne affichée",
    "sInfoFiltered": "(Filtrer un maximum de_MAX_)",
    "sInfoPostFix": "",
    "sSearch": "Chercher:",
    "sUrl": "",
    "sInfoThousands": ",",
    "sLoadingRecords": "Chargement...",
    "oPaginate": {
      "sFirst": "Premier", "sLast": "Dernier", "sNext": "Suivant", "sPrevious": "Précédent"
    },
    "oAria": {
      "sSortAscending": ": Trier par ordre croissant", "sSortDescending": ": Trier par ordre décroissant"
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

});


Car*_*aga 6

在 dataTables 网站https://datatables.net/plug-ins/i18n/上的 CDN 中上传了语言文件, 因此您只需将“西班牙语”替换为您在以下示例中使用的任何语言。

https://datatables.net/plug-ins/i18n/Spanish

$('table.dataTable').DataTable( {
    language: {
        url: '//cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json'
    }
});
Run Code Online (Sandbox Code Playgroud)


Bas*_*ANI 5

阿拉伯语

 var table = $('#my_table')
                .DataTable({
                 "columns":{//......}
                 "language": 
                        {
                            "sProcessing": "???? ???????...",
                            "sLengthMenu": "???? _MENU_ ??????",
                            "sZeroRecords": "?? ???? ??? ??? ?????",
                            "sInfo": "????? _START_ ??? _END_ ?? ??? _TOTAL_ ????",
                            "sInfoEmpty": "???? 0 ??? 0 ?? ??? 0 ???",
                            "sInfoFiltered": "(?????? ?? ????? _MAX_ ?????)",
                            "sInfoPostFix": "",
                            "sSearch": "????:",
                            "sUrl": "",
                            "oPaginate": {
                                "sFirst": "?????",
                                "sPrevious": "??????",
                                "sNext": "??????",
                                "sLast": "??????"
                            }
                        }
                });
Run Code Online (Sandbox Code Playgroud)

参考:https : //datatables.net/plug-ins/i18n/Arabic

添加一名作者