i18n
i18n
Andreas S.
Posts: 208Questions: 74Answers: 4
in Editor
How can the user switch between two languages? I have two languages, and one should the user selected. I my case it is German and English. Default should be English. How can I configure that the editor or the Datatable to load the correct language file?
And is it possible to add in the lang file my own var to show the editor label in the correct language?
for example the length of a pool, en: pool length, de: Beckenlänge.
Andreas
This discussion has been closed.
Answers
"How can the user switch between two languages?"
Well, that should be done outside Data Tables I guess. You could take the browser language as the default. If the browser language is German you take German, else you take English. And then you could have a button the user could click on to choose manually. You could save the language in a cookie.
This is what I do on the server side in PHP:
Javascript; I use a button called "languagepicker" ... and a javascript plugin called cookies to read and write cookies. The Ajax call only returns the result of this:
filter_var(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), FILTER_SANITIZE_STRING)
After implementing the language selection in any fashion you like you can set the language settings for Editor and Data Tables like this:
And this is to set the editor labels:
https://editor.datatables.net/reference/api/field().label()
Just to quickly add to @rf1234's excellent answer - there is no API in DataTables to dynamically change the language strings that it uses. They have to be set when the table is initialised (usually at page load time).
Allan
good to know, Allan. And also no problem because of the page refresh upon language change. I still have to translate all the Editor field labels myself too ...
I've just tested this and it worked. ("lang" is a global variable)
Viel Erfolg und schöne Grüße nach Deutschland / Österreich / Schweiz, Andreas!
Roland
I also tried to get the placeholder "Please select a Department" bilingual.
editor.field().opts({placeholder: ....}) didn't work.
So I tried this approach which will also work for everything else in Editor and Data Tables:
Thanks for your answers. I will try it soon.
Andreas