StudentiUniMi / website

Fully responsive, SEO-friendly website with the aim of providing services and access to all groups of didactic courses and general purposes to students of the University of Milan.
https://studentiunimi.it/
MIT License
54 stars 12 forks source link

Localization #14

Closed Giuseppetm closed 3 years ago

Giuseppetm commented 3 years ago

The user must be able to change the language of the website: the available ones should be english and italian.

Giuseppetm commented 3 years ago

@UmbertoPirovano provided us a first version of translation from Italian to English.

Traduzione network.docx

We may already proceed with the development of the code to support this feature.

Giuseppetm commented 3 years ago

Issue \\ See how html code can be shown starting from string field

Option 2 here (html-react-parser): link

Giuseppetm commented 3 years ago

Issue \ Define how to manage extra groups description translate and any other field value defined by json data

@manuelelucchi can you help with this one?

image

This is an example, how to handle the localization in json files? I was thinking on defining new field values like "it" and "en" in the json (description will be an array) so we can map the available languages we have and relate them to the json field values.

MarcoBuster commented 3 years ago

We should move away from JSON files imo

Giuseppetm commented 3 years ago

We should move away from JSON files imo

The server will always return a json, and the db must handle the translated fields, so.. 🙉🙉🙉

MarcoBuster commented 3 years ago

We should move away from JSON files imo

The server will always return a json, and the db must handle the translated fields, so.. 🙉🙉🙉

Then we need to adapt the JSON format for this use case.

MarcoBuster commented 3 years ago

I was thinking on defining new field values like "it" and "en" in the json (description will be an array) so we can map the available languages we have and relate them to the json field values.

Can we duplicate the JSON file for each language? By doing so we save bandwith

Giuseppetm commented 3 years ago

I was thinking on defining new field values like "it" and "en" in the json (description will be an array) so we can map the available languages we have and relate them to the json field values.

Can we duplicate the JSON file for each language? By doing so we save bandwith

The JSONs we need to translate are services and maybe extra groups. If we use multiple jsons we introduce redundancy and possibly inconsistency. The bandwith for the actual 2 jsons that we need to translate is minimal.

Giuseppetm commented 3 years ago

For the last bug reported: maybe it's because of the initial declaration of the state for the cookies. I should use something like: let [cookies, ] = useCookies();

Edit: this has been done in color palette switcher.

Giuseppetm commented 3 years ago

Note: html react parser doesn't work with custom react components, but only with pure html. This is not what I need, so I must find another package to parse from strings to components.

Maybe this one? : https://stackoverflow.com/questions/63256579/convert-string-to-html-on-react-rich-text-editor

Edit: we need to fix cookies behaviour on the branch master.

Giuseppetm commented 3 years ago

React-jsx-parser did the trick for parsing react components from string. https://github.com/TroyAlford/react-jsx-parser

Giuseppetm commented 3 years ago

Note for @manuelelucchi:

image

Sometimes the localization object is initialized as undefined. We must fix this error.

Edit: I probably fixed it.

Giuseppetm commented 3 years ago

The change not being globally has been fixed by using withCookies.