Overriding parts of a translation
Overriding parts of a translation
CanisLupus
Posts: 10Questions: 2Answers: 0
I use the Swedish translation found here https://cdn.datatables.net/plug-ins/1.10.15/i18n/Swedish.json
This translation is excellent but I want to override parts of it anyway. I tried like this, but it does not work. Am I doing something wrong, or can't it be done?
"language": {
"url": "https://cdn.datatables.net/plug-ins/1.10.15/i18n/Swedish.json",
"paginate": {
"previous": "<--"
}
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm afraid that at the moment the information from the JSON file will always take priority. In retrospect this was a mistake and I'll correct that in the next major version.
The workaround at the moment is to Ajax load the JSON field yourself using
$.ajax
or$.getJSON
and then modify the language object before then initialising DataTables with it.Allan
Many thanks. I can live with how it works for now and make this change when you release the next major version of DataTables then. (Hope that won't be too far in the future.)
Hi allan,
Could you please ellaborate your workaround with a working code sample?
Thanks.
Allan
Thank allan, but I'm not sure your sample will work.
For example, you are overriding
search
. But the language keyword issSearch
.BTW, if I just put the fetched language without any modification, it does not work at all, nothing is translated.
Also, from where
json.language
comme from? I don't see anylanguage
key on the lang files.sSearch
is the legacy name.language.search
is the current one.I was assuming you'd be loading other data as well. If the json response is only the language object, then only use that.
Allan
I finally manage it like this: