i18n with nested editing
i18n with nested editing
Hey everyone!
I use https://editor.datatables.net/examples/simple/i18nFile.html in my DataTables.
However, i just couldn't get it to work together with https://editor.datatables.net/examples/datatables/nested.html. (The nested Editor is always in english, no matter where i add the i18n file url)
Where do the i18n settings have to be specified when using nested input?
Best,
Tim
Answers
The same place as usual I am tempted to say. I did not do anything about i18n for nested editing. It just worked from the start.
These are my Editor i18n settings for German which work fine:
The code above needs to be executed prior to Editor initialization.
I have German "language" settings for the data table as well which are also neatly applied to the nested data table inside the parent Editor form.
Interesting - i use "language: {url: '/i18n/de-DE.json'}," everywhere.
I even added this in every config available - the DataTable initialization as well as both Editor Initializations. Doesn't change anything
Works on the "Big" Table and Editor, doesn't change anything in the "Nested" Editor ...
Any ideas?
Hi,
Have you tried using the
config
option for thedatatable
field type to specify options for the inner table? e.g.:Allan
That is all pretty surprising! I also use "config.language" with field type datatable but only to hide a couple of controls that are not suitable for embedded datatables in my opinion. This does not hurt my overall language settings which are either German or English. The German language version as defined above.
This is what it looks like:
English:
I also use this independent of user language:
There could be a different cause for this. If you are using the same i18n file for both Editor and Data Tables it's not going to work.
In Data Tables this stuff is called "language" and in Editor it is called "i18n". God knows why?!
You've already seen my settings for Editor above. And how I override my Data Tables settings below (NOT my Editor settings!!) for field type "datatable" using "language". Please note: I hardly ever use "language" with other data tables because I changed the default for all data tables if user language is German.
So here are my default settings for Data Tables. Again this code must be executed before DT initialization.
Legacy! As with most quirks . I should really map
i18n
in DataTables to align with what Editor does...Allan
Initially I got very much confused by these things. And I also think both terms "language" and "i18n" are inappropriate in a way.
Why? You need to use those even though you aren't doing any kind of InternationalizatioN and are not using more than one language: Even if you just want to use deviating wording you need to use either "language" or "i18n"!
Why not just call it "wording" or whatever suitable comes to mind?
Hey everyone, thanks for your answers.
For testing, I purged my DataTable / Editor Objects of the JSON-URLs and added rf1234's code exactly as given - as soon as i added both of them (for DataTable as well as Editor's) it worked!
To avoid tons of duplicated "code" in every DataTables, I then put rf1234's translations into a json file (like the one provided by DataTables somewhere in the docs):
Works wonderful
Thanks everyone for helping!
Glad you got it working
Since you and me are using "Editor.defaults" and "datatable.defaults" there is no code dupliation regardless of whether or not you are using a json file. You need both statements just once and they work for all of your Editors and Data Tables. For that reason I don't use the json files.
The other advantage of not using language files is that you don't then incur extra Ajax calls to get them. There is no caching of the language files, so each table would trigger a new Ajax call (the browser will likely cache them though).
strings
is another option, butlanguage
andi18n
are fairly common from what I've seen in other libraries. The options can be used for i18n, so I generally prefer that option myself.Allan
Alright, i see. Did you put the defaults somewhere in the DataTables-Library source? If i put the defaults in the js code for my table, it obviously doesn't carry over to other .html pages with other tables.
Yes, the default language strings are in the core code. The method suggested by @rf1234 sets those default values so they are then used for any future initialisation on that page.
Allan
Just to share an approach to avoid code redundancy using Editor and Data Tables:
I run an "init" function prior to data table initialization on all of my pages. This function contains everything that applies to all of my data tables on all of my pages.
It has all of these default settings that I don't want to do redundantly:
* language and i18n - depending on the user language
* moment.js settings - depending on the user language
* most of my custom buttons (whenever such a button is used more than once)
* state saving and loading settings
* lots of other options: responsive, fixed header, scrollX - to mention a few - that I use throughout all of my data tables
Ah, that makes sense. Good idea, I will implement that for sure when I find the time! Thanks for the suggestions