39

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

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

4

11 回答 11

72

您必须创建一个语言文件,然后使用:

"oLanguage": {
  "sUrl": "media/language/your_file.txt"
}

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

"oLanguage": {
  "sUrl": "media/language/custom_lang_<?php echo $language ?>.txt"
}

Wherelanguage匹配特定语言的文件名。

或更改个人设置:

"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)"
}

有关更多详细信息,请阅读:http ://datatables.net/plug-ins/i18n

于 2012-11-12T11:04:41.547 回答
39
//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"
        }
    }
});

还使用cdn:

//cdn.datatables.net/plug-ins/a5734b29083/i18n/Spanish.json

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

于 2014-10-04T15:02:40.817 回答
12

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

$(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"
            }

    });

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

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

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


为我工作,希望它对任何人都有效。

此致!

于 2016-02-12T14:40:55.043 回答
7

法语翻译:

$('#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"
    }
  }
});

});

于 2016-09-30T21:07:27.003 回答
6

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

https://datatables.net/plug-ins/i18n/西班牙语

$('table.dataTable').DataTable( {
    language: {
        url: '//cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json'
    }
});
于 2017-06-01T21:43:06.277 回答
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": "الأخير"
                            }
                        }
                });

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

作者:奥萨马·哈亚特

于 2016-08-14T14:56:32.307 回答
3

请记住,您必须准确指定您的 language.JSON 路径,如下所示:

language: {
    url: '/mywebsite/js/localisation/German.json'
}
于 2015-07-10T08:49:32.447 回答
2

这的确是

language: {
 url: '//URL_TO_CDN'
}

问题不是所有的数据表(在撰写本文时)都是有效的 JSON。例如繁体中文文件就是其中之一。

为了解决这个问题,我用 JavaScript 编写了以下代码:

  var dataTableLanguages = {
    'es': '//cdn.datatables.net/plug-ins/1.10.21/i18n/Spanish.json',
    'fr': '//cdn.datatables.net/plug-ins/1.10.21/i18n/French.json',
    'ar': '//cdn.datatables.net/plug-ins/1.10.21/i18n/Arabic.json',
    'zh-TW': {
      "processing": "處理中...",
      "loadingRecords": "載入中...",
      "lengthMenu": "顯示 _MENU_ 項結果&quot;,
      "zeroRecords": "沒有符合的結果&quot;,
      "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項&quot;,
      "infoEmpty": "顯示第 0 至 0 項結果,共 0 項&quot;,
      "infoFiltered": "(從 _MAX_ 項結果中過濾)",
      "infoPostFix": "",
      "search": "搜尋:",
      "paginate": {
        "first": "第一頁&quot;,
        "previous": "上一頁&quot;,
        "next": "下一頁&quot;,
        "last": "最後一頁&quot;
      },
      "aria": {
        "sortAscending": ": 升冪排列",
        "sortDescending": ": 降冪排列"
      }
    }
  };
  var language = dataTableLanguages[$('html').attr('lang')];

  var opts = {...};
  
  if (language) {
    if (typeof language === 'string') {
       opts.language = {
         url: language
       };
    } else {
       opts.language = language;
    }
  }

现在使用 opts 作为数据表的选项对象,例如

$('#list-table').DataTable(opts)
于 2020-09-28T17:49:37.053 回答
0

Tradução para Português Brasil

    $('#table_id').DataTable({
    "language": {
        "sProcessing":    "Procesando...",
        "sLengthMenu":    "Exibir _MENU_ registros por página",
        "sZeroRecords":   "Nenhum resultado encontrado",
        "sEmptyTable":    "Nenhum resultado encontrado",
        "sInfo":          "Exibindo do _START_ até _END_ de um total de _TOTAL_ registros",
        "sInfoEmpty":     "Exibindo do 0 até 0 de um total de 0 registros",
        "sInfoFiltered":  "(Filtrado de um total de _MAX_ registros)",
        "sInfoPostFix":   "",
        "sSearch":        "Buscar:",
        "sUrl":           "",
        "sInfoThousands":  ",",
        "sLoadingRecords": "Cargando...",
        "oPaginate": {
            "sFirst":    "Primero",
            "sLast":    "Último",
            "sNext":    "Próximo",
            "sPrevious": "Anterior"
        },
        "oAria": {
            "sSortAscending":  ": Ativar para ordenar a columna de maneira ascendente",
            "sSortDescending": ": Ativar para ordenar a columna de maneira descendente"
        }
    }
});
于 2020-03-27T15:02:20.643 回答
0

如果你使用 Angular 和 Firebase,你也可以使用 DTOptionsBuilder :

angular.module('your_module', [
'ui.router',
'oc.lazyLoad',
'ui.bootstrap',
'ngSanitize',
'firebase']).controller("your_controller", function ($scope, $firebaseArray, DTOptionsBuilder) {

var ref = firebase.database().ref().child("your_database_table");

// create a synchronized array
$scope.your_database_table = $firebaseArray(ref);

ref.on('value', snap => {

    $scope.dtOptions = DTOptionsBuilder.newOptions()
        .withOption('language',
        {
            "sProcessing": "Traitement en cours...",
            "sSearch": "Rechercher&nbsp;:",
            "sLengthMenu": "Afficher _MENU_ &eacute;l&eacute;ments",
            "sInfo": "Affichage de l'&eacute;l&eacute;ment _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
            "sInfoEmpty": "Affichage de l'&eacute;l&eacute;ment 0 &agrave; 0 sur 0 &eacute;l&eacute;ment",
            "sInfoFiltered": "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
            "sInfoPostFix": "",
            "sLoadingRecords": "Chargement en cours...",
            "sZeroRecords": "Aucun &eacute;l&eacute;ment &agrave; afficher",
            "sEmptyTable": "Aucune donn&eacute;e disponible dans le tableau",
            "oPaginate": {
                "sFirst": "Premier",
                "sPrevious": "Pr&eacute;c&eacute;dent",
                "sNext": "Suivant",
                "sLast": "Dernier"
            },
            "oAria": {
                "sSortAscending": ": activer pour trier la colonne par ordre croissant",
                "sSortDescending": ": activer pour trier la colonne par ordre d&eacute;croissant"
            }
        }
        )

});})

我希望这将有所帮助。

于 2018-01-08T18:12:05.640 回答
0

您好,在 wich 文件中我必须将此代码用于法语翻译,我不太了解翻译过程

$('#userList').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"
    }
}

});

于 2017-08-30T14:12:58.050 回答