Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up localization using Weblate #46

Closed
probonopd opened this issue Feb 14, 2021 · 18 comments
Closed

Set up localization using Weblate #46

probonopd opened this issue Feb 14, 2021 · 18 comments

Comments

@probonopd
Copy link
Member

probonopd commented Feb 14, 2021

  • Do we need a separate ts file, and hence a separate Weblate subproject for each of the utilities?
  • How is Hosted Weblate supposed to get its permissions to push something into a GitHub Repository? Doesn't one need to enter a GitHub Token somewhere into the Weblate GUI? (Where is this documented?) --> Need to add the user weblate in https://github.com/helloSystem/Utilities/settings/access and give it Write rights
  • Alternatively, how exactly does one need to set up hosted Weblate so that it creates (and appends to existing) GitHub Pull Requests instead of trying to push?

Pending on

@probonopd
Copy link
Member Author

probonopd commented Feb 14, 2021

Running pylupdate5 . -ts i18n/en.ts creates a file that Weblate can use to translate strings.

Questions:

  • https://doc.bccnsoft.com/docs/PyQt5/i18n.html talks about pylupdate5 - do we need to use that one instead (from FreeBSD package py37-qt5-xml)? It doesn't seem to scan the whole directory tree at once but seems to require a .pro file which makes everything even more complex than needed?
  • How do we get the translations split up so that we can put only the corresponding translations into each .app bundle for each application? (If we go with one ts file and hence one Weblate subproject per application, then maybe we don't even need to do this work...)
  • Do we use raw .ts files in the .app bundles (which makes it easier to work on the translations while using the application) or do we need to compile them down to binary .qm files?
  • Can we set up an automated process (e.g., GitHub Action) that handles extracting the translations from the source code files, and putting the translated strings into the application bundles, automatically?

@rbircher
Copy link

* Do we need a separate ts file, and hence a separate Weblate subproject for each of the utilities?

* How is Hosted Weblate supposed to get its permissions to push something into a GitHub Repository? Doesn't one need to enter a GitHub Token somewhere into the Weblate GUI? (Where is this documented?)

* Alternatively, how exactly does one need to set up hosted Weblate so that it creates (and appends to existing) GitHub Pull Requests instead of trying to push?

Pending on

* Approval from Weblate as a free hosted open source project

* [WeblateOrg/weblate#3533 (comment)](https://github.com/WeblateOrg/weblate/issues/3533#issuecomment-778759649)

Have a look at https://docs.weblate.org/en/latest/vcs.html You have to add the weblate User to the Git repo. So you can grant weblate access. For Upload it looks like a SSH Key is required.

@probonopd
Copy link
Member Author

Addded the user weblate as a collaborator with read access on GitHub. In the hope that this will allow it to make pull requests.

@probonopd
Copy link
Member Author

It is still not making pull requests.
What exactly do I need to configure in https://hosted.weblate.org/settings/hellosystem/utilities/#vcs so that it makes pull requests?

@probonopd
Copy link
Member Author

probonopd commented Feb 14, 2021

Now setting git@github.com:helloSystem/Utilities.git as the Push URL in Weblate and giving the Weblate user Write rights in https://github.com/helloSystem/Utilities/settings/access...

This seems to have done the trick, no SSH keys neded.

But I would prefer the bot not to push but use Pull Requests...

@rbircher
Copy link

Yea absolutly. I don't know if it's even a good idea, to have this fully automated. Do we have controll who has access to the weblate instance?

@probonopd
Copy link
Member Author

I think that only the Weblate admin for the project (that would be me) can trigger a push. In any case, the good thing about GitHub pushes is that they can be reverted if something goes wrong.

@rbircher
Copy link

Ok, this sounds good. Normally this translation scripts really works well. they don't destroy code. Well, I don't have experiance with this particular one, but with the one i worked, it worked really well.

@probonopd
Copy link
Member Author

probonopd commented Feb 28, 2021

I am still looking for the leanest way to translate PyQt5 applications, ideally without the need to compile anything. After all, I chose PyQt5 specifically because it doesn’t need to be compiled…

Am I missing something?

https://forum.learnpyqt.com/t/impossible-translations/298/9

Not so easy:
https://simpleit.rocks/python/how-to-translate-a-python-project-with-gettext-the-easy-way/

Those extra steps for compiling are really bothering me.
After all, git is not great in storing compiled blobs, and we don't want to need a compile pipeline for PyQt stuff (or else we could have gone with a compiled language right from the start)

@probonopd probonopd reopened this Feb 28, 2021
@probonopd
Copy link
Member Author

probonopd commented Feb 28, 2021

Possibly we need to define a custom _ function that uses something like https://github.com/alexshpilkin/po/blob/master/po.py to extract the translation directly from a po file?

We can't be the first ones to run into this...?

@probonopd
Copy link
Member Author

probonopd commented Oct 4, 2021

I have a proof-of-concept working for a system that uses raw Qt .ts files to translate the UI without the need for compilation:

image

This requires the Python module translate-toolkit to be installed with sudo python3 -m pip install translate-toolkit as it apparently is not available in FreeBSD packages.

The proof-of-concept currently uses .ts files from outside of the appliction bundle because we have all translations for all applications in entire repository in the same set of .ts files.
We probably need to split this up and have one .ts file for each application.

Is this possible to set up easily in Hosted Weblate without having to create one Weblate project per application in this repository?

@probonopd
Copy link
Member Author

To generate/update the English .ts file, use something along those lines?

FreeBSD% mkdir -p Preferences/Users.app/Resources/i18n

FreeBSD% pylupdate5 -verbose -noobsolete Preferences/Users.app/Resources/*{py,ui} -ts Preferences/Users.app/Resources/i18n/en.ts
Updating 'Preferences/Users.app/Resources/i18n/en.ts'...
    Found 11 source texts (11 new and 0 already existing)

Unlike lupdate which seemingly cannot use .py files as the input, pylupdate5 one can, but it cannot work on a whole directory recursively. And unfortunately it produces bigger output files because it inserts lines like <location filename="../Preferences/Users.app/Resources/adduser.py" line="21"/>. I wonder whether we could change it to better suit our needs (it's Python, after all).

In the meantime we can use

sudo pkg install -y xmlstarlet
FreeBSD% xml ed -L -d '//location' Preferences/Users.app/Resources/i18n/en.ts

to remove the unwanted <location/> tags.

@probonopd
Copy link
Member Author

Is this possible to set up easily in Hosted Weblate without having to create one Weblate project per application in this repository?

This looks exactly like what we need:

https://docs.weblate.org/en/latest/admin/addons.html#component-discovery

Automatically adds or removes project components based on file changes in the version control system.

Triggered each time the VCS is updated, and otherwise similar to the import_project management command. This way you can track multiple translation components within one VCS.

@probonopd
Copy link
Member Author

Unfortunately Murphy's Law is hitting me:
Not having looked at Hosted Weblate for half a year, it is now down for 600 minutes exactly when I wanted to have a look at it again. Not complaining, just saying.

image

@probonopd
Copy link
Member Author

As we can see in

https://github.com/helloSystem/Utilities/tree/master/Developer%20Preview/Format%20Disk.app/Resources/i18n

we have

Utilities/Developer Preview/Format Disk.app/Resources/i18n/formatdisk_en.ts
Utilities/Developer Preview/Format Disk.app/Resources/i18n/formatdisk_de.ts

I would like to set up Weblate to find these but I can't get it to work:

image

Like this it works but then the component variable becomes Developer Preview/Format Disk.app/Resources/i18n/formatdisk rather than formatdisk or Format Disk.app:

image

How to solve this?

@probonopd
Copy link
Member Author

In the meantime, I can add the individual applications one-by-one by hand lke this:

https://hosted.weblate.org/projects/hellosystem/ -> Add new translation component -> From existing component -> Under "Component name" enter the name of the application (without ".app") (e.g., "Format Disk") -> Under "Component" select "helloSystem/Utilities" -> Continue -> Select the appropriate directory where the translations reside -> "Do NOT enter anything in "Monolingual base language file".

Works but is manual work for each application.

@probonopd
Copy link
Member Author

Basic setup is working now and documented at https://hellosystem.github.io/docs/developer/localization.

@probonopd
Copy link
Member Author

probonopd commented Oct 10, 2021

@louies0623 I see you contributed translations for many Asian languages. Thank you very much, highly appreciated. Do you actually speak all of those languages? Hats off. May I add you to https://hellosystem.github.io/docs/developer/acknowledgements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants