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

Feature/i18n #5479

Merged
merged 1 commit into from
Jul 23, 2020
Merged

Feature/i18n #5479

merged 1 commit into from
Jul 23, 2020

Conversation

mrcruz
Copy link
Contributor

@mrcruz mrcruz commented Jul 16, 2020

This a a very simple implementation of the way Qt does its translations. It has a script to both extract tagged keys automatically and a script to create a binary file with the translations.

The main problem that I really would like to improve is in file src/run_tribler.py: I had to shuffle around the imports in the middle of the file because their order does change the semantics of the program. If I import TriblerWindow before installing a translator, the window in created with the default language. That happens because a lot of things are done in constructors. Is there a way to solve this that does not required a huge change?

@tribler-ci
Copy link
Contributor

Can one of the admins verify this patch?

@mrcruz mrcruz mentioned this pull request Jul 16, 2020
@ichorid
Copy link
Contributor

ichorid commented Jul 16, 2020

ok to test

@ichorid
Copy link
Contributor

ichorid commented Jul 16, 2020

@mrcruz , welcome and thanks for contributing! 👍

@qstokkink
Copy link
Contributor

qstokkink commented Jul 17, 2020

Cool!

If I import TriblerWindow before installing a translator, the window in created with the default language. That happens because a lot of things are done in constructors. Is there a way to solve this that does not required a huge change?

The easiest and cleanest way is probably to drop the installTranslator code into the GUI __init__.py file:

EDIT: Doesn't work.

@qstokkink
Copy link
Contributor

qstokkink commented Jul 17, 2020

This is the cleanest I could come up with (that actually works 😃):

diff --git a/src/run_tribler.py b/src/run_tribler.py
index e1ff95336..596ecab54 100644
--- a/src/run_tribler.py
+++ b/src/run_tribler.py
@@ -139,14 +139,12 @@ if __name__ == "__main__":
             check_free_space()
 
             from tribler_gui.tribler_app import TriblerApplication
+            from tribler_gui.tribler_window import TriblerWindow
 
             app_name = os.environ.get('TRIBLER_APP_NAME', 'triblerapp')
             app = TriblerApplication(app_name, sys.argv)
-        
-            from tribler_gui.i18n import get_default_system_translator
-            translator = get_default_system_translator()
-            app.installTranslator(translator)
-            
+            app.installTranslator(app.translator)
+
             if app.is_running():
                 for arg in sys.argv[1:]:
                     if os.path.exists(arg) and arg.endswith(".torrent"):
@@ -155,7 +153,6 @@ if __name__ == "__main__":
                         app.send_message(arg)
                 sys.exit(1)
 
-            from tribler_gui.tribler_window import TriblerWindow
             window = TriblerWindow()
             window.setWindowTitle("Tribler")
             app.set_activation_window(window)
diff --git a/src/tribler-gui/tribler_gui/tribler_app.py b/src/tribler-gui/tribler_gui/tribler_app.py
index 9cc12d201..b2d213b93 100644
--- a/src/tribler-gui/tribler_gui/tribler_app.py
+++ b/src/tribler-gui/tribler_gui/tribler_app.py
@@ -6,6 +6,7 @@ from PyQt5.QtCore import QCoreApplication, QEvent, Qt
 from tribler_core.utilities.unicode import ensure_unicode
 
 from tribler_gui.code_executor import CodeExecutor
+from tribler_gui.i18n import get_default_system_translator
 from tribler_gui.single_application import QtSingleApplication
 
 # Set the QT application parameters before creating any instances of the application.
@@ -23,6 +24,7 @@ class TriblerApplication(QtSingleApplication):
         QtSingleApplication.__init__(self, app_name, args)
         self.code_executor = None
         self.messageReceived.connect(self.on_app_message)
+        self.translator = get_default_system_translator()
 
     def on_app_message(self, msg):
         if msg.startswith('file') or msg.startswith('magnet'):

This was linked to issues Jul 17, 2020
@ichorid ichorid added this to In progress in Usability and performance via automation Jul 17, 2020
@mrcruz
Copy link
Contributor Author

mrcruz commented Jul 20, 2020

I followed the suggestion by @qstokkink and I would say the only thing missing now is some UI to select the language. I'm trusting the locale.getdefaultlocale() will be reliable even though I do not have any experience with it.

@mrcruz mrcruz marked this pull request as ready for review July 20, 2020 18:05
@mrcruz
Copy link
Contributor Author

mrcruz commented Jul 21, 2020

I feel the need to create a simple README to facilitate future translations. Where should I put this? I was thinking in a README file inside de i18n folder. Do we have a standard for documentations?

@qstokkink
Copy link
Contributor

@mrcruz if you're struggling with rounding off this PR and you have allow edits from maintainers enabled, I can help you out with rounding off this PR if you want.

@mrcruz
Copy link
Contributor Author

mrcruz commented Jul 23, 2020

@mrcruz if you're struggling with rounding off this PR and you have allow edits from maintainers enabled, I can help you out with rounding off this PR if you want.

It is enabled. Feel free to change in any way you want!

@qstokkink
Copy link
Contributor

@mrcruz alright 👍 let me polish this up for merge.

@qstokkink
Copy link
Contributor

Alright, cleaned up. All tests (should) pass now.

@mrcruz your e-mail and username were the wrong way around (your username was in the e-mail field and vise versa). I corrected it for this commit, but you'll probably want to fix that locally.

qstokkink
qstokkink previously approved these changes Jul 23, 2020
Using QT QTranslate pipeline. with auto extracting of keys and building of qm files. probably still missing many keys spread though the code.

Adds initial pt_BR translation

Adds README file to document how to work with translations
@qstokkink qstokkink requested a review from devos50 July 23, 2020 09:39
@devos50 devos50 merged commit 4b0eb29 into Tribler:devel Jul 23, 2020
Usability and performance automation moved this from In progress to Done Jul 23, 2020
@devos50
Copy link
Contributor

devos50 commented Jul 23, 2020

Thanks!

@mrcruz mrcruz deleted the feature/i18n branch July 23, 2020 09:45
@qstokkink
Copy link
Contributor

Agreed, very cool.

@@ -0,0 +1,19 @@
# Internationalization

This app uses QT multi language feature to provider internationalization.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provider: A typo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 indeed. This should also state "the QT multi language feature".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a quick PR for that, before we forget.

@ichorid
Copy link
Contributor

ichorid commented Apr 30, 2021

@mrcruz , I've recently cleaned up and wrapped all the remaining GUI strings in tr(). Would you care to update BR translation?

@mrcruz
Copy link
Contributor Author

mrcruz commented May 2, 2021

I guess you linked the wrong url in your comment. I will work on an update later on this week and create a PR. I'm glad we have more languages already!

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

Successfully merging this pull request may close these issues.

How to translate? multi-lingual interface
6 participants