8values / 8values.github.io

The 8values political quiz
MIT License
989 stars 411 forks source link

Localization #14

Closed gervasiocaj closed 4 years ago

gervasiocaj commented 7 years ago

This feature allows localization to any language, with incomplete translation to pt. It uses the i18next framework, and modifies the questions.js and ideologies.js to extract the necessary strings and move them to the respective JSON files in the locales folder. The binding is still a bit ugly, for example:

<h2 id="results" class="translate"></h2>
<p id="results_desc" class="translate"></p>
for (i of document.getElementsByClassName("translate")) {
    document.getElementById(i.id).innerHTML=i18next.t(i.id)
}
{
    "results": "Résultats",
    "results_desc": "Lorem ipsum dolor sit amet."
}

Resolves #5

Jameskmonger commented 7 years ago

There seems to be a lot of code duplication between the different pages. Would it be possible to get this put into its own script?

gervasiocaj commented 7 years ago

According to 6200b85:

In order to load the namespaces and do the string binding, just load the i18n.js file on the HTML and call the i18n_load_ns() with the namespaces notation found here. To fill the string data (e.g. "12 apples"), the element must adhere to the following notation (see HTML data-* attributes):

<p data-i18n="apple_count" data-amount="18"></p>
{ "apple_count": "{{amount}} apples" }

To refresh the string, alter the data-* attribute accordingly and call i18n_ready().

TristanBomb commented 7 years ago

I'd like to thank you for all the work you've put into this! Unfortunately, I'm not really familiar with the framework you're using. Just a few things:

Thanks!

gervasiocaj commented 7 years ago

@TristanBomb how did you generate/drew the images?

elifoster commented 7 years ago

@TristanBomb The best way to handle internationalized images is to render the text using CSS instead of actually putting in the image. I took a look at some of the svg files that are in this project and it should be pretty simple.

gervasiocaj commented 7 years ago

Thanks to @Saphareas, this is now possible :smile:

Jameskmonger commented 7 years ago

Great work @gervasiocaj

dalssoft commented 7 years ago

any update? this seems to be a very important upgrade which would be make 8values available to a much broader audience. btw, congrats @TristanBomb, @gervasiocaj et al for the hard work!

gervasiocaj commented 7 years ago

IMHO it is pretty stable, but the Portuguese translation is not finished yet. Waiting for @TristanBomb word on It.

JoshuaKimsey commented 7 years ago

I don't know! I absolutely agree that translations would be of a huge help to make 8Values even more wide spread! However, I too have had a pull request waiting for a while now too with no word from @TristanBomb. Hopefully, both @gervasiocaj and I will here soon.

P.S: Congrats to @gervasiocaj for the outstanding work he did to get the translations working! 😄

dalssoft commented 7 years ago

@gervasiocaj do you have a URL running for this PR on pt-br? this would be useful as is and wouldn't be necessary to wait for @TristanBomb decision

gervasiocaj commented 7 years ago

Here you go: https://gervasiocaj.github.io/8values.github.io/

dalssoft commented 7 years ago

it's still in en-US :(

gervasiocaj commented 7 years ago

Try this https://gervasiocaj.github.io/8values.github.io/?lng=pt

dalssoft commented 7 years ago

@gervasiocaj what's the best way to translate the remaining text in en?

gervasiocaj commented 7 years ago

Submit a PR to my fork editing this file. These are the original strings.

laurenzfg commented 7 years ago

Hi @gervasiocaj how is the progress of your l18n efforts? If the technical stuff is done and you finalized the syntax of the .json files, I'd be more than happy to start working on a German translation.

gervasiocaj commented 7 years ago

You can revise this German translation: https://github.com/gervasiocaj/8values.github.io/tree/localization/locales/de

laurenzfg commented 7 years ago

I will certainly look into it! Thank you for providing me with the relevant directory.

sentfanwyaerda commented 7 years ago

Hi, personally I dislike the javascript approach of making it i18n. I made a simple PHP PATCH: https://github.com/sentfanwyaerda/8waarden.nl (including the dutch 'nl' translation)

JoshuaKimsey commented 7 years ago

@sentfanwyaerda While something like that might work better/ be more efficient than using just pure JavaScript, here's one issue I see. That would be the first introduction of PHP into this project, which would require making sure that PHP is setup properly on the hosting server. As it is right now, the user can run the html files locally on their computer and the program will function perfectly normal. Introducing PHP adds an extra amount of work needed to get an environment setup for users to use the code, either on a server or locally on their own computer.

Maybe @TristanBomb and the other contributors are ok with this, I honestly don't know! In all honesty, using PHP would probably be easier code wise. The issues arise from the users end with having to deal with PHP. Ultimately, I do believe that sticking with pure JS is a better solution for the user, even if it means more work on our end.

gervasiocaj commented 7 years ago

At the moment we have complete translations to pt, es and de. Thanks everyone!

JoshuaKimsey commented 7 years ago

Hey, that's great @gervasiocaj! What other languages are you aiming to have the test be in at this point?

renanpvaz commented 7 years ago

Shouldn't this PR be merged already so other languages can be added later?

gervasiocaj commented 7 years ago

I am about to merge the commit cd97fa1, which introduces some changes in the text. Looking for suggestions and solutions to track the progress of these translations, since they might be outdated for a while until the contributors have some free time.

snorepion commented 7 years ago

I've started working on an Esperanto translation. Are the only files that I need to change the JSON files in localization branch/locales/eo (copied from locales/en)? Once I finish Esperanto, I'll start working on Swedish too.

Genora51 commented 4 years ago

I'm closing this PR and moving the conversation over to #123 to include the newest updates to 8values; it would be great to revive the thread over on that PR and get it merged soon!