thonny / thonny

Python IDE for beginners
https://thonny.org
MIT License
3.13k stars 1.03k forks source link

Translation: PR welcome? #668

Closed cspaier closed 4 years ago

cspaier commented 5 years ago

Hi,

A group of teachers (me included) are using Thonny in a highschool in south France. We distribute a portable version of Thonny here with small customization and homemade libraries for students and teachers.

I noticed your faq related to translating thonny. I was contemplating marking the strings with gettext so we could render a po file and host translation on externate tools such as poeditor.

Before starting working on that, I wanted to check with you if you would welcome such a PR.

Also maybe there are some specific technical details I missed on this matter?

Anyway thanks for good job! Thonny is a great tool for teaching and learning python.

aivarannamaa commented 5 years ago

Hi!

Thank you for the kind words!

Internationalization still isn't a priority for me, but it looks like there are enough people who consider it important. Therefore I'll welcome your PR (although this means I'll need to be more careful in changing strings in the future).

Translating short and simple UI texts (eg. menu items) should go smoothly. Longer texts (eg. Assistant's error explanations) need more care so that a small change in the original text wouldn't change all translations unusable. I hope there are features for this in gettext (eg. by giving codenames for some strings).

cspaier commented 5 years ago

Thank you for your answer.

Hum, I think gettext will handle that smoothly. If you change a string, we will have to render new po file and update translations. In the meantime, the untranslated strings will be shown in English so nothing will be break.

I fear I don't really understand the "codenames" idea you are referring too.

Anyway the more important might be the easy "menu strings" since that's what the students will be using mostly.

Maybe I start working on a PR and we could discuss specifics there if needed?

aivarannamaa commented 5 years ago

I fear I don't really understand the "codenames" idea you are referring too.

I thought of something like _("Blah, blah, ...", id="blah_msg") so that the translations would be bound to blah_msg and this allows changing "Blah, blah, ..." without breaking the translations. But nevermind, looks like (Python's) gettext doesn't support this.

Maybe I start working on a PR and we could discuss specifics there if needed?

Sure. I wish you luck!

cspaier commented 5 years ago

I think gettext handle that. It will bind the strings with it's origins (file.py line 13).

Anyway, I will do some tests and let you know.

badukaire commented 5 years ago

do you have any news regarding this? do you have some draft code around to see?

cspaier commented 5 years ago

I started marking strings with gettext but sadly didn't pushed nor tested compiling the po file. I now lost access to the machine where the (small) work is.

I will try to reproduce it in the following days and push it to my fork.

cspaier commented 5 years ago

Alright, in this commit I did a basic babel setup.

I marked one string here and extracted it successfully in /locale/messages.po with the command python setup.py extract_messages --output-file locale/messages.po.

Next steps are:

aivarannamaa commented 5 years ago

Do I understand correctly that Babel is required only at build time? In this case it's probably better to remove it from requirements.txt, as it is quite heavy dependency (8MB wheel would be quite noticable compared to 12 MB Thonny for Windows installer).

cspaier commented 5 years ago

Done.

Also, I realize my editor (atom) removed all trailing white space automatically. It might make the commits hard to follow but I think it's good practice to do so. Do you want me to look for an option to prevent that? Or another editor...

cspaier commented 5 years ago

I translated "File" into the french "Fichier" and it's working! I also removed shortcuts from setup.py as it's not needed and it clearly remove babel dependency for everyone but people working on translation.

image

I started documenting the process here (excuse my poor english).

cspaier commented 5 years ago

Allow me to explain what I have done:

I created this file containing a dict of language we use. It will allow us to map a language name to it's code. Babel have such functionality but for this simple mapping I thought a 8M dependency would be an overkill.

LANGUAGES_DICT = {
    "English": "en_US",
    "Français": "fr_FR"
}

In workbench, I created two methods:

https://github.com/cspaier/thonny/blob/d18183d65ddc0360604d7f43e3323f20efe40415/thonny/workbench.py#L216-L229

_init_language() is called on workbench._init_ here.

Finally we have the language plugin that allow user to set his language setting.

For now one have to restart thonny for language change to take effect. I thought calling workbench._set_language() would refresh everything but apparently it doesn't.

One can test setting language to French or English, restarting thonny and see the "File" string translated.

Now is time for me to wait for @aivarannamaa feedback on all this.

If it's ok we can start marking strings everywhere and setting up a poeditor or something else account to start translating.

raylu commented 5 years ago

hello and sorry for the drive-by

it's probably too late now, but ideally you'd make a separate commit that just removes the trailing whitespace

but you can also just view diffs without whitespace! https://github.com/thonny/thonny/compare/master...cspaier:localisation?w=1

badukaire commented 5 years ago

yes, this can be a good idea. it's easy to do that in the point where you started working. Then after the blank-removal PR is accepted just merge back into you i18n work

aivarannamaa commented 5 years ago

@cspaier, sorry for my late reply and thank you for the work!

The general approach looks fine to me.

Do I understand correctly, that currently the locale directory is expected to be next to thonny package directory? I think it would be cleaner if it was under thonny directory so that pip-installing thonny puts everything under one directory.

For now one have to restart thonny for language change to take effect.

I think this is OK. You could come up with a system which traverses all widgets (which are organized into a tree) and changes the labels dynamically, but I'm not sure it is worthwhile.

separate commit that just removes the trailing whitespace

For now I don't mind them being there as I can check the diff without WS changes. But I created an issue for further discussion: #735

cspaier commented 5 years ago

Cool!

I will move the locale folder inside thonny and update everything accordingly.

Yes restarting thonny to update language sounds quite fair.

I will mark some more strings, update the .po and .mo files and submit a PR.

Do you want me to set up a poeditor account for online translation?

aivarannamaa commented 5 years ago

Sounds good!

Do you want me to set up a poeditor account for online translation?

I haven't used it myself, but if it looks good to you then yes, please do!

cspaier commented 5 years ago

Here we go!

I made a request for open source project so we will have unlimited strings hosting.

For now everyone can participate there (same as the wiki) If needed be I can limit that. If you make an account on poeditor, I can make you an administrator of this project there (probably a good idea).

If someone wants to add a language best is they reach me for now they can do it in poeditor.

I will very soon just document the process from github to poeditor and vice versa here.

Edit: Anyone can add a new language directly in poeditor.

cspaier commented 5 years ago

Thonny has been approved for a free localization project. Enjoy localizing and don't be shy to spread the word that POEditor supports the open source movement!

Cheers, The POEditor Team

aivarannamaa commented 5 years ago

Cool! Thank you!

I hope I can experiment with Estonian translation and merge the PR by the end of week.

cspaier commented 5 years ago

Sure. Feel no rush. And remember you don't need to translate all strings to try things out: Untranslated one will be shown in English.

I will be afk this week end but should have time next week if any questions or issue would arise.

I added you as an administrator on POeditor so you should have all control there by now.

Also, if it helps you, I don't mind helping with translations PR in the future: Whenever someone add a new language, or translation of a language have move on, I could update everything and submit a PR. I documented this process so anyone should be able to do it, but if it remove you some work and you are ok with it, I am fine managing that for a bit.

Ilis commented 5 years ago

I've done Russian translation.

Some of terms are erroneous, I kept their formatting.

Please, note, some translations much wider then original terms.

And I can't see project as well, only my work,

aivarannamaa commented 5 years ago

Please, note, some translations much wider then original terms.

@Ilis, did you mean that same source string should be given different translations in different contexts? Can you give some examples?

Ilis commented 5 years ago

Can you give some examples?

E. g.

Tools
Инструменты
Run
Выполнить

I did translation for project where button

|Find Next|

became

|Найти Да|
|лее     |

and after some fix became

|Найти |
|далее |

and then project author gave some more room for sentence fit one line.

Some of terms are erroneous

Here I mean (Increase font size with bracket, _and running it with_, _(probably needs admin privileges). with spaces on edges, number of terms with 2, 3 or even 4 newlines.

aivarannamaa commented 5 years ago

I'll go through the strings some time later and then I'll fix these issues.

number of terms with 2, 3 or even 4 newlines

At least in some cases this is on purpose, because Tkinter Labels don't have good wrapping options. I updated couple of your translations to avoid About dialog going too wide.

mukimei commented 5 years ago

Japanese has been completed.... how do I add it to thonny so I can use it? I'm confused....

aivarannamaa commented 5 years ago

@mukimei , the usual process is:

  1. Fork this project
  2. Download po and mo files for your language to right subfolder under thonny/locale
  3. Add your language to thonny/languages.py
  4. Create a pull request

I don't mind doing it myself, if it is difficult for you.

mukimei commented 5 years ago

I added it via the GitHub Desktop... I don't know what to do now... or if I did it right...

Also I'm using a MacBook Pro

aivarannamaa commented 5 years ago

Don't worry, I'll include the translation myself.

aivarannamaa commented 5 years ago

@mukimei -- how do you write "Japanese" (or "Japanese language") in Japanese? This goes to the selection box for selecting Japanese language.

mukimei commented 5 years ago

Japanese (language) = 日本語

aivarannamaa commented 5 years ago

Lot of new terms have been marked and uploaded to Poeditor

aivarannamaa commented 4 years ago

Thonny has been approved for a free localization project. Enjoy localizing and don't be shy to spread the word that POEditor supports the open source movement! Cheers, The POEditor Team

@cspaier, it looks like something has happened to this POEditor project -- when I log into https://poeditor.com/join/project/Gh188fdYH6 it says "There are no languages available to translate in this project". Can you please investigate?

cspaier commented 4 years ago

For some reasons (inactivity?) the project was archived at poeditor. I clicked restore and we are back on track.

aivarannamaa commented 4 years ago

Thank you!

cspaier commented 1 year ago

This happened again, so I restored and investigated. As documented here, this happened because I didn't logged in at POeditor for 6 month.

I think it would be cleaner if I transfer the project to you @aivarannamaa at poeditor. If you are ok with that, I can ask POeditor team to do so. This way you won't have to rely on me for Thonny POeditor project not being archived.

Let me know what you think. Best

aivarannamaa commented 1 year ago

I think it would be cleaner if I transfer the project to you @aivarannamaa at poeditor. If you are ok with that, I can ask POeditor team to do so. This way you won't have to rely on me for Thonny POeditor project not being archived.

@cspaier, this sounds good! And thanks for creating this project in the first place!

cspaier commented 1 year ago

Much welcome. My work is small here.

Finally, I asked for transfer:

 The project will be moved once the target account and someone at POEditor confirm the transfer. 

You should have received an email I think.

aivarannamaa commented 1 year ago

Yes, I completed the transfer. Thanks!