qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
25.98k stars 3.82k forks source link

[qBittorrent webui] custom theme is broken by default #18109

Open MahdiMirzade opened 1 year ago

MahdiMirzade commented 1 year ago

qBittorrent & operating system versions

qBittorrent: v4.5.0 (64-bit) Operating system: Fedora Linux 37 (Workstation Edition) (64-bit) Qt: 5.15.7 libtorrent-rasterbar: 1.2.18.0

What is the problem?

I've followed the Developing alternate WebUIs (WIP) document, my commands are as followed:

git clone https://github.com/qbittorrent/qBittorrent.git
cp -rf qBittorrent/src/webui/www/ webui
cp -rf qBittorrent/src/icons/ webui/public/
cp -rf qBittorrent/src/icons/ webui/private/

And then changed my webui settings to match this path. Result is as show in the screenshot.

I thought maybe the git version was the problem, so I downloaded the latest tag (v4.5.0) and:

tar xzvf qBittorrent-release-4.5.0.tar.gz
cp -rf ~/Downloads/qBittorrent-release-4.5.0/src/webui/www/ webui
cp -rf ~/Downloads/qBittorrent-release-4.5.0/src/icons/ webui/private/
cp -rf ~/Downloads/qBittorrent-release-4.5.0/src/icons/ webui/public/

But the result didn't change. This seems to be an issue with translation, so I changed my client's language to "فارسی" to see if that would fix it, but it was the same.

Steps to reproduce

No response

Additional context

image

This issue was first witnessed by my theme's issues page.

Log(s) & preferences file(s)

No response

hugalafutro commented 1 year ago

For what it's worth I can also replicate this with themes from https://github.com/GilbN/theme.park, they have a issue open too: https://github.com/GilbN/theme.park/issues/458

sledgehammer999 commented 1 year ago

With PR #17616 only the builtin WebUI gets translated. The builtin WebUI uses this construct QBT_TR(string)QBT_TR[CONTEXT=context] to denote translatable strings to the server (qbt). With 4.5.0 the server does the translation only for the buildin webui.

As a fix you should apply a search+replace regex on all copied files. These two regexes match the expression

QBT_TR\((.*)\)QBT_TR\[CONTEXT=.*\]
QBT_TR\((.*)\)QBT_TR

and capture the translatable string in the 1st capturing group. Then use \1 or $1 to replace/substitute it.

ATTENTION: Apply the first regex before the second one, otherwise it won't work.

MahdiMirzade commented 1 year ago

Thank you @sledgehammer999 for your solution, But I think this regex does the trick better:

QBT_TR\((([^\)]|\)(?!QBT_TR))+)\)QBT_TR\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\]

In pycharm I did it like this: Ctrl-Shift-R -> Enable regex search by pressing Alt-x -> Paste expression in find input -> Type $1 in replace input.

But this solution won't fix everything, since when strings which translate combined by a number or another string (shown in the sidebar) are still broken as shown in this picture: image

Better solution: Changing the tstool.py in order to translate each context with its own original source, but I don't know if this can truly work or how much dependency qBittorrent webui has on this file so I didn't look into it.

Best solution: Wait for it to be fixed from upstream, because these hacks will break translations.

sledgehammer999 commented 1 year ago

Better solution: Changing the tstool.py in order to translate each context with its own original source, but I don't know if this can truly work or how much dependency qBittorrent webui has on this file so I didn't look into it.

tstool.py job is to extract the translatable strings into Qt's .ts file. Those .ts files are used to provide translations per locale.

Best solution: Wait for it to be fixed from upstream, because these hacks will break translations.

qBittorrent will no longer offer translated string to 3rd party webuis. The 3rd party webuis are supposed to handle the translation themselves (usually client-side).

Hint: The builtin webui files when copied and loaded as an alternative webui == 3rd party webui.

But this solution won't fix everything, since when strings which translate combined by a number or another string (shown in the sidebar) are still broken as shown in this picture:

The copied webui is offered as a base/example to start off coding. It sucks that the contained strings aren't immediately usable as a 3rd party webui.

MahdiMirzade commented 1 year ago

@sledgehammer999

tstool.py job is to extract the translatable strings into Qt's .ts file. Those .ts files are used to provide translations per locale.

Thank you for clarifying that.

qBittorrent will no longer offer translated string to 3rd party webuis. The 3rd party webuis are supposed to handle the translation themselves (usually client-side). The copied webui is offered as a base/example to start off coding. It sucks that the contained strings aren't immediately usable as a 3rd party webui.

That's unfortunate, this requires extra code and effort when you simple want to change a background color (I know this is possible through extensions like dark reader) or an icon you don't like, It would be better if handling i18n translations from webui was at least it an option from settings. Removing it killed a lot of themes out there.

However... thank you for guiding me.

luzpaz commented 3 months ago

Is this issue still valid ?

HSHallucinations commented 2 months ago

yes, i just found this thread while searching info on how to fix this :/