Reputation: 15616
I store, in a session variable, which language does user wants to translate but I don't know to pass it DataTables
I found this explanation on the datatables website but that didn't really help, where do I set language param ?
Upvotes: 43
Views: 163347
Reputation: 357
datatables translation for romanian
$(document).ready(function() {
$('#example').dataTable( {
"oLanguage": {
"sLengthMenu": "_MENU_ înregistrări pe pagina",
"sZeroRecords": "Nici un rezultat",
"sInfo": "Afișare de la _START_ la _END_ din _TOTAL_ înregistrări",
"sInfoEmpty": "Afișare de la 0 la 0 din 0 înregistrări",
"sInfoFiltered": "(filtrare din _MAX_ total înregistrări)",
"sSearch": "Căutare"
}
} );
} );
Upvotes: 0
Reputation: 1
for lao language
"oLanguage": {
"sEmptyTable": "ຍັງບໍ່ມີຂໍ້ມູນ",
"sLengthMenu": "ສະແດງ _MENU_ ແຖວຕໍ່ຫນ້າ",
"sZeroRecords": "ບໍ່ພົບຂໍ້ມູນໃດໆ",
"sInfo": "ສະແດງ _START_ ຫາ _END_ ຈາກ _TOTAL_ ແຖວ",
"sInfoEmpty": "ສະແດງ 0 ຫາ 0 ຈາກ 0 ແຖວ",
"sInfoFiltered": "(ກັ່ນຕອງຈາກ _MAX_ ບັນທຶກທັງໝົດ)"
}
Upvotes: 0
Reputation: 11
Make new copy from file table.js on js\custom\apps\user-management\users\list
and rename it to tableAr.js here in this file tableAr.js you can change English text to Arabic.
Upvotes: 0
Reputation: 8027
It is indeed
language: {
url: '//URL_TO_CDN'
}
The problem is not all of the DataTables (As of this writing) are valid JSON. The Traditional Chinese file for instance is one of them.
To get around this I wrote the following code in 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_ 項結果",
"zeroRecords": "沒有符合的結果",
"info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
"infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
"infoFiltered": "(從 _MAX_ 項結果中過濾)",
"infoPostFix": "",
"search": "搜尋:",
"paginate": {
"first": "第一頁",
"previous": "上一頁",
"next": "下一頁",
"last": "最後一頁"
},
"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;
}
}
Now use the opts as option object for data table like
$('#list-table').DataTable(opts)
Upvotes: 2
Reputation: 566
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"
}
}
});
Upvotes: 1
Reputation: 461
There are language files uploaded in a CDN on the dataTables website https://datatables.net/plug-ins/i18n/ So you only have to replace "Spanish" with whatever language you are using in the following example.
https://datatables.net/plug-ins/i18n/Spanish
$('table.dataTable').DataTable( {
language: {
url: '//cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json'
}
});
Upvotes: 6
Reputation: 38147
You have to either create a language file and then set it using :
"oLanguage": {
"sUrl": "media/language/your_file.txt"
}
Im not sure what server language you are using but something like this would work in PHP :
"oLanguage": {
"sUrl": "media/language/custom_lang_<?php echo $language ?>.txt"
}
Where language
matches the file name for a specific language.
or change individual settings :
"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)"
}
For more details read this : http://datatables.net/plug-ins/i18n
Upvotes: 82
Reputation: 2199
If you are using Angular and Firebase, you can also use the 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 :",
"sLengthMenu": "Afficher _MENU_ éléments",
"sInfo": "Affichage de l'élément _START_ à _END_ sur _TOTAL_ éléments",
"sInfoEmpty": "Affichage de l'élément 0 à 0 sur 0 élément",
"sInfoFiltered": "(filtré de _MAX_ éléments au total)",
"sInfoPostFix": "",
"sLoadingRecords": "Chargement en cours...",
"sZeroRecords": "Aucun élément à afficher",
"sEmptyTable": "Aucune donnée disponible dans le tableau",
"oPaginate": {
"sFirst": "Premier",
"sPrevious": "Précédent",
"sNext": "Suivant",
"sLast": "Dernier"
},
"oAria": {
"sSortAscending": ": activer pour trier la colonne par ordre croissant",
"sSortDescending": ": activer pour trier la colonne par ordre décroissant"
}
}
)
});})
I hope this will help.
Upvotes: 0
Reputation: 41905
French translations:
$('#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"
}
}
});
});
Upvotes: 7
Reputation: 15327
for Arabic language
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": "الأخير"
}
}
});
Ref: https://datatables.net/plug-ins/i18n/Arabic
Author: Ossama Khayat
Upvotes: 9
Reputation: 301
sorry to revive this thread, i know there is the solution, but it is easy to change the language with the datatables. Here, i leave you with my own datatable example.
$(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"
}
});
The language you get from the following link:
http://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n
Just replace the URL value in the language option with the one you like. Remember to always use the comma
Worked for me, hope it will work for anyone.
Best regards!
Upvotes: 18
Reputation: 3777
Keep in mind that you have to exactly specify your path to your language.JSON like this:
language: {
url: '/mywebsite/js/localisation/German.json'
}
Upvotes: 3
Reputation: 1175
//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"
}
}
});
Also using a cdn:
//cdn.datatables.net/plug-ins/a5734b29083/i18n/Spanish.json
More options: http://www.datatables.net/plug-ins/i18n/English [| Spanish | etc]
Upvotes: 46