Override default texts for buttons, title
Override default texts for buttons, title
Started to use central translations for our site that is in swedish.
For DataTables everything works like a charm, but for Editor there is a strange behaviour when trying to overrule the defaults on a editor to editor basis.
Defaults settings:
"editor": {
"close": "Stäng",
"create": {
"button": "Ny",
"title": "Skapa ny post",
"submit": "Skapa"
},
"edit": {
"button": "Redigera",
"title": "Redigera post",
"submit": "Uppdatera"
},
"remove": {
"button": "Radera",
"title": "Radera",
"submit": "Radera",
"confirm": {
"_": "Är du säker på att du vill ta bort %d rader?",
"1": "Är du säker på att du vill ta bort 1 rad?"
}
},
"error": {
"system": "Ett systemfel har inträffat (<a target=\"\\\" rel=\"nofollow\" href=\"\\\">Mer information<\/a>)."
},
"multi": {
"title": "Flera värden",
"info": "De valda objekten har olika värden för detta fält. För att redigera och sätta alla objekt för detta fält till samma värde, klicka eller tryck här, annars behåller de sina individuella värden.",
"restore": "Ångra ändringar",
"noMulti": "Detta fält kan redigeras individuellt, men inte som en del av en grupp."
}
},
Overrides in editor definition:
i18n: {
edit: {
button: '<i class="bi bi-plus-square-fill"></i> Lasta upp fil från XXX i Excel-format (xlsx)',
title: 'Läs in fil',
submit: 'Spara'
}
}
The submit is overridden, i.e. "Uppdatera" becomes "Spara", but the button and title entries stays the same.
I can provide login to page demonstrating the behaviour at request.
Editor version 2.4.2.
KR;
Björn H
This question has accepted answers - jump to:
Answers
At what point are you setting these values? Are they coming from a Ajax loaded i18n file via DataTables? If so, that is probably the same as this thread.
Setting the translation values as defaults before initialisation of Editor is the way to work around this at the moment. I'm going to have to put a queuing mechanism of some sort to allow dynamic updating of the strings.
Allan
To quick to mark it answered...
I left the ajax load and set it in "$.extend( $.fn.dataTable.defaults" without ajax.
Same behaviour...
KR;
Björn H
You probably need to use
DataTable.Editor.defaults.i18n
. If you useDataTable.defaults
, then Editor will only see the translations when DataTables triggersi18n
, which happens only when DataTables is initialised. By the time that happens, Editor will have already created various elements.Allan
That works, thanks.
But, I think it is a pity not being able to use
"url: '//cdn.datatables.net/plug-ins/2.3.1/i18n/sv-SE.json'"
in DataTables defaults as it contains an "editor" section that overrules your suggestion.
Guess I will have to maintain a local one without the "editor" section in it.
KR,
björn H
Yes it isn't ideal. As I mentioned, the issue is that the elements have already been created by the time the language strings have loaded - so they'd need to be updated in some way, and there currently isn't a way to do that.
What I'm thinking of doing is having some kind of register function that will maintain a list of all elements that have a language string in them, then update them when a new language string is loaded. That will use some more memory, but shouldn't be too much. My biggest concern is where the string gets split before being used, but I don't immediately recall any of them in Editor - there are a few in DataTables.
Allan
Hmm, that is not what I experience though, is it?
The editor language prompts gets overridden if and only if there is an "editor" section in DataTables defaults.
I.e. The editor defaults and overrides works fine, unless/until there is a DataTables default loaded containg values for editor that replaces the values.
So for me, it seems more like that there is an unintentional override applying DataTables defaults.
But I might overthink it and don't know the inner workings of course...
KR,
Bjørn H
Yes, I think I would expect that. Editor will look for DataTables'
i18n
event and then check for aneditor
property, and if found apply the strings there (the default DataTables language options don't have aneditor
property, but a lot of the translations do).The trouble is that it currently can't update the strings that have already been rendered.
If you don't want Editor to use the strings from the language file, and instead just use the Editor defaults you are setting, remove the
editor
property until I fix this.Allan