Hello all,
I am currently working on creating dynamic pages for my site, and I have two questions:
When accessing a database through a different language on Wix Multilingual, how would one go about either translating database entries to show up differently in different languages, or changing the website to use a different database (made in the target language) when showing a different language?
Apologies if a bit simplistic, I am not very experienced in coding.
Thank you for any help.
OK Guys, lets have a look at this problem. Before we go any further, I did not actually code anything myself, I have only had a more than longer look at the problems invoilved. So below I will give you 2 ways of approaching the solution to this problem. The actual coding is up to you.
1) I guess, but this might not be true, that you want to display multi-lingual db-output on a display page, not on an iinput page (a form).
2) let´s suppose we use 2 languages, English and Spanish and we want to display a field label called "Description(Descripción" and next to it a English or Spanidh description we pull from our collection, which would hold the content "Standard brick/Ladrillo común", like so:
English : Description : Standard brick
Spanish: Descripcion : Ladrillo común
So in out collection, we probably have 2 fields called Description_en and Description_es
3)The LABEL Desription/Decripción can be translated by using Wix MultiLingual. But to display the corresponding CONTENT of the description (Standard Brick/Ladrillo común) is up to us.
4) Now, we do not want BOTH descriptions shown together at the same time, it should be one of the other (either English or SPanish)
5) We basically have 2 ways of doing this:
A) we connect every field of our collection (dataset) to a field on our page to display, EXCEPT the "Description" field. This one, we retrieve in code with getItem and, in code, we lookup wich language has been selected and than decide which Description content we display. Again, for displaying info this is doable, for input forms this is more difficult
B) we connect BOTH fields to the dataset and display them (e.g. in a text box), but we HIDE either the English or the Spanish text. This would mean that in the editor, you would put 2 textfields for both description OVER eachother (make one a bit longer than the second, you a year later, when you look at i again, you would SEE that there are 2 text fields on top of each other.
Now, we set both text fields to hiddenOnload ion the props panel and, depending on the chosen language, we show the correct one (and, although it is hidden, double hide the other. This you will need if a user switches language more than once).
And that is probably all that there is to it. We just need to take into account that:
1)the Wix Language Dropdown boz does not have an onClick/onChange event, so if English is displayed and user clicks Spanish, the LABELS will be translated but not the content of our description for there is no way we can possibly know the user has changed language
2)therefore, do not use the Wix Language dropdown. use a standard dropdown which does have the events needed, so you can hide/show the desciption content when needed
3) I would go about it like this:
a)on my page, I would put a standatrd dropdown in theheader
b)I would retrieve with the API all languages supported and find the main languange (lsearch on "multi" in the API doc)
c) with these languages I would populate the dropdown like this:
English (value en)
Español (value es)
d) I would display the text in the default language (e.g. en) either by hiding/showing the text boxes or, possibility 1, by retrieving the desired ldescriptionby handing the description text box the value of the collection field Description_ concatenated with the language (Description + languagecode)
e)the above, I would do inside a Function, where I would hide/show or concatenate field names for all language dependent database fields. I would call it directly from the page_onready and dataset_onready (with the default lang code) AND I would call it again with the new language code when the user has clicked another language from the dropdown.
e)do not forget to SET the multilanguage code also: since we do not use Wix´s dropdown, we have to somehow let Wix know that the other lables, translated with Wix Multilingual inside the editor, also have to swith to a different language (and not only out multilang db-content)
f)I would contemplate storing the user language inside a session cookie (look up Storage in the API), SET that language and, on a next page (on upon a returning visitor), show the correct langauge immediately by reading this session value, instead of showing English every time (like in D, above). Especially when you have several multillang pages, it would be silly to force the user every time to change the language on a per page basis: once should be enough, you just store and retrieve it.
Hope this helps a bit, good luck.
Supporting multi-lingual web sites is an artform poorly understood. I could write a paper about it, but the short (and not full) version is this: When working with databases underneath a web site, you have two moments of multi-lingualness. First, the user-interface, second the data displayed. Let me clarify with an example.
Suppose we support Spanish and English and we sell jeans. Now, on the English website we want to show:
Category : Jeans
And on the Spanish one this:
Categoría : Vaquieros
The labels "Category" and "Categoría" can be translated using Wix mult-language (but not in forms). The description however is pulled from a database, so here we have to do something extra. In our database collection we would do something like this:
descr_en : Jeans
descr_es : Vaquieros
Now, whem displaying a (dynamic) page, we would first query Wix for the language used (en or es). Now, in our db-query we would add either "en" or "es" to the field "descr_" to retrieve the correct language dependant description.
Hope this helps.
i tried doing it but it din't work I opened in the dataset in both languages and all it did wat change it generally. So i think for the moment it is not possible, sorry if you probably thought i had the solution, but hope to find one soon.