I am using datatables from datatables.net within a multi-language application. I know how to switch the language of the table with simply passing the language file or customizing the strings by myself.
"language": {
"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/lang.json"
}
But is there a possibility to change the language according to the users browser settings?
DataTables has an extensive API which can be used to access the data contained in a table and otherwise manipulate the table after the table initialisation has completed. The DataTables API is designed to reflect the structure of the data in the table and how you will typically interact with the table through the API.
u can try other language "oLanguage": { "sUrl": "//cdn.datatables.net/plug-ins/1.10.7/i18n/<LANGUAGE>. json" } a open datatables.net/plug-ins/i18n and look translation is click ur language later take CDN links :) This does not seem to work any more in 1.10.
The best alternative is jQuery Dynatable. It's not free, so if you're looking for a free alternative, you could try List. js or Webix DataTable. Other great apps like DataTables are Frappe DataTable, Dash DataTable, wpDataTables and Essential JS 2 for JavaScript by Syncfusion.
Unfortunetaly, the langauge packages are named by language names, not by language codes :
//cdn.datatables.net/plug-ins/1.10.7/i18n/Finnish.json
//cdn.datatables.net/plug-ins/1.10.7/i18n/French.json
etc. So you must built a map that translates language codes to language names :
var langMap = {
'en' : 'English',
'da' : 'Danish',
'se' : 'Swedish'
//etc, the languages you want to support
}
Now you can pass the correct language package URL to dataTables that corresponds to the current browser language :
function getLanguage() {
var lang = navigator.language || navigator.userLanguage;
return '//cdn.datatables.net/plug-ins/1.10.7/i18n/'+langMap[lang]+'.json'
}
var table = $('#example').DataTable({
language : {
url: getLanguage()
}
});
demo -> http://jsfiddle.net/3er6f4w6/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With