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

feat: translations #662

Merged
merged 27 commits into from
Dec 31, 2024
Merged

Conversation

Computerdores
Copy link
Collaborator

@Computerdores Computerdores commented Dec 23, 2024

Implements Translation using the translation files from weblate. Also modifies en.json when necessary.

For testing go to src/qt/translations.py and either:

  1. add Translations.change_language("<language of choice>") at the end of the file,
  2. or uncomment return "???" in __getitem__.

The first option should leave untranslated strings in Englisch while the second should replace every string that is effected by translations to ???.

Notes:

  • preview_panel.py isn't translated completely, mostly due to ongoing refactoring of that file in other places
    • reverting the changes to this file might be a good idea

Close #598.
Close #447.
Close #524.

@CyanVoxel CyanVoxel added Type: Enhancement New feature or request Type: Translation Translates or improves translation capabilities Priority: High An important issue requiring attention labels Dec 23, 2024
@CyanVoxel CyanVoxel added this to the Alpha v9.5 (Post-SQL) milestone Dec 23, 2024
@CyanVoxel
Copy link
Member

Just a note, I would avoid renaming the keys if possible or else I don't think Weblate will know how to propagate those changes automatically. In f4b30c1 I had to update the keys across all translation files simultaneously before updating on the Weblate side.

@Computerdores Computerdores marked this pull request as ready for review December 23, 2024 20:50
@Computerdores Computerdores added the Status: Review Needed A review of this is needed label Dec 23, 2024
@Computerdores
Copy link
Collaborator Author

This PR is now ready for review

@Computerdores
Copy link
Collaborator Author

@CyanVoxel could you have a look a my responses to the review comments once you have time?

@CyanVoxel CyanVoxel removed the Status: Review Needed A review of this is needed label Dec 29, 2024
@CyanVoxel
Copy link
Member

Everything else is looking great, there's just one last issues I've run into - when my program was translated to German it wouldn't function properly, specifically with the item thumbnails. No files could render thumbnails or be selected and when closing the library I'd get a very long succession of tracebacks:
(Truncated):

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "F:\GitHub\TagStudio/tagstudio\src\qt\widgets\item_thumb.py", line 210, in <lambda>
    self.update_thumb(ts, image=i),
    ^^^^^^^^^^^^^^^^^
SystemError: <class 'method'> returned a result with an exception set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "F:\GitHub\TagStudio/tagstudio\src\qt\widgets\item_thumb.py", line 210, in <lambda>
    self.update_thumb(ts, image=i),
    ^^^^^^^^^^^^^^^^^
SystemError: <class 'method'> returned a result with an exception set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "F:\GitHub\TagStudio/tagstudio\src\qt\widgets\item_thumb.py", line 210, in <lambda>
    self.update_thumb(ts, image=i),
    ^^^^^^^^^^^^^^^^^
SystemError: <class 'method'> returned a result with an exception set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "F:\GitHub\TagStudio/tagstudio/tag_studio.py", line 65, in main
    driver.start()
  File "F:\GitHub\TagStudio/tagstudio\src\qt\ts_qt.py", line 511, in start
    app.exec()
  File "F:\GitHub\TagStudio/tagstudio\src\qt\widgets\item_thumb.py", line 210, in <lambda>
    self.update_thumb(ts, image=i),
    ^^^^^^^^^^^^^^^^^
SystemError: <class 'method'> returned a result with an exception set

TagStudio Frontend (Qt) Crashed! Press Enter to Continue...

@Computerdores
Copy link
Collaborator Author

Everything else is looking great, there's just one last issues I've run into - when my program was translated to German it wouldn't function properly, specifically with the item thumbnails. No files could render thumbnails or be selected and when closing the library I'd get a very long succession of tracebacks: (Truncated):

Do you know what you were doing when that happened? Because this doesn't happen for me and the traceback is basically useless (the file in which the error occurs wasn't even modified by this PR)

@CyanVoxel
Copy link
Member

Everything else is looking great, there's just one last issues I've run into - when my program was translated to German it wouldn't function properly, specifically with the item thumbnails. No files could render thumbnails or be selected and when closing the library I'd get a very long succession of tracebacks: (Truncated):

Do you know what you were doing when that happened? Because this doesn't happen for me and the traceback is basically useless (the file in which the error occurs wasn't even modified by this PR)

The item thumbnails break when opening the library, and the crash + traceback occurs when closing the library. Happens to me on Windows and macOS
image

Happens to me under multiple languages, and opening other test libraries either gives me the same error or a new set of errors (looks like from trying to add new files):

QPainter::begin: Paint device returned engine == 0, type: 0
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::fillRect: Painter not active
QPainter::begin: Paint device returned engine == 0, type: 0
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::fillRect: Painter not active
QPainter::begin: Paint device returned engine == 0, type: 0
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::fillRect: Painter not active
Traceback (most recent call last):
  File "/Users/cyanvoxel/Files/GitHub/TagStudio/tagstudio/tag_studio.py", line 65, in main
    driver.start()
  File "/Users/cyanvoxel/Files/GitHub/TagStudio/tagstudio/src/qt/ts_qt.py", line 511, in start
    app.exec()
  File "/Users/cyanvoxel/Files/GitHub/TagStudio/tagstudio/src/qt/ts_qt.py", line 757, in <lambda>
    self.add_new_files_runnable(tracker),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyanvoxel/Files/GitHub/TagStudio/tagstudio/src/qt/ts_qt.py", line 776, in add_new_files_runnable
    Translations.translate_with_setter(
  File "/Users/cyanvoxel/Files/GitHub/TagStudio/tagstudio/src/qt/translations.py", line 74, in translate_with_setter
    set_text(self.translate_formatted(key, **kwargs))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyanvoxel/Files/GitHub/TagStudio/tagstudio/src/qt/translations.py", line 77, in translate_formatted
    return self[key].format(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'x + 1'

TagStudio Frontend (Qt) Crashed! Press Enter to Continue...

@CyanVoxel
Copy link
Member

Adding a "Blocked" label to remind myself to temporarily close the Weblate translations before pulling this to avoid merge conflicts

@CyanVoxel CyanVoxel added the Status: Blocked This issue or pull request is awaiting the outcome of another issue or pull request label Dec 29, 2024
@Computerdores
Copy link
Collaborator Author

The KeyError is definitely not the cause of the crashes - it comes from the other translations having broken formatting (e.g. "Test {x + 1} asd" is an example that would cause the error from above). Should be fixed now nonetheless

@Computerdores
Copy link
Collaborator Author

I still can't reproduce the crash though

@CyanVoxel
Copy link
Member

Everything seems to be fixed for me now as of cc4b6df, minus the uncommented Translations.change_language("de") regression. The KeyError crash occurred for me on a library with mostly unlinked entries and possibly some new files that weren't already in the library, while the SystemError crash was purely just from opening and closing any other library with the translations activated. In any case, they seem to be fixed!

@Computerdores
Copy link
Collaborator Author

The regression is fixed now - should be good to merge then, right?

@CyanVoxel CyanVoxel merged commit 69aed92 into TagStudioDev:main Dec 31, 2024
5 checks passed
@CyanVoxel CyanVoxel removed the Status: Blocked This issue or pull request is awaiting the outcome of another issue or pull request label Dec 31, 2024
@CyanVoxel
Copy link
Member

Fixed up a couple things with the en.json file, but other than that I think that's everything! Thank you so much for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High An important issue requiring attention Type: Enhancement New feature or request Type: Translation Translates or improves translation capabilities
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Feature Request]: [Translation] Always include variables in strings
2 participants