Skip to content

Commit

Permalink
Rare: Improve translation handling
Browse files Browse the repository at this point in the history
* Remove base Qt translations from repo, load translations from Qt itself
* Prefix translation `qm` files with `rare_`.
* Rename `translation_source.ts` to simply `source.ts`
* If the selected language matches the system local, remove the option from the configuration.
  • Loading branch information
loathingKernel committed Feb 12, 2024
1 parent f088fc9 commit 8a3bdbd
Show file tree
Hide file tree
Showing 26 changed files with 523 additions and 509 deletions.
6 changes: 3 additions & 3 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
host = https://www.transifex.com

[o:rare-1:p:rare:r:placeholder-ts]
file_filter = rare/resources/languages/<lang>.ts
source_file = rare/resources/languages/translation_source.ts
source_lang = en_US
file_filter = rare/resources/languages/rare_<lang>.ts
source_file = rare/resources/languages/source.ts
source_lang = en
type = QT
minimum_perc = 50

5 changes: 4 additions & 1 deletion misc/py2ts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
cwd="$(pwd)"
cd "$(dirname "$0")"/.. || exit

pylupdate5 -noobsolete $(find rare/ -iname "*.py") -ts rare/resources/languages/translation_source.ts
#py_files=$(find rare -iname "*.py" -not -path rare/ui)
#ui_files=$(find rare/ui -iname "*.ui")

pylupdate5 -noobsolete $(find rare/ -iname "*.py") -ts rare/resources/languages/source.ts

cd "$cwd" || exit
15 changes: 8 additions & 7 deletions rare/components/tabs/settings/rare.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import platform
import subprocess
import locale
import sys
from logging import getLogger

Expand Down Expand Up @@ -33,9 +34,9 @@ def __init__(self, parent=None):

# Select lang
language = self.settings.value(*options.language)
self.lang_select.addItem(self.tr("System default"), "")
for locale, title in get_translations():
self.lang_select.addItem(title, locale)
self.lang_select.addItem(self.tr("System default"), options.language.default)
for lang_code, title in get_translations():
self.lang_select.addItem(title, lang_code)
if (index := self.lang_select.findData(language, Qt.UserRole)) > 0:
self.lang_select.setCurrentIndex(index)
else:
Expand Down Expand Up @@ -212,8 +213,8 @@ def save_window_size(self):
self.settings.remove(options.window_size.key)

def on_lang_changed(self, index: int):
if not index:
lang_code = self.lang_select.itemData(index, Qt.UserRole)
if lang_code == locale.getlocale()[0]:
self.settings.remove(options.language.key)
return
language = self.lang_select.itemData(index, Qt.UserRole)
self.settings.setValue(options.language.key, language)
else:
self.settings.setValue(options.language.key, lang_code)
Binary file removed rare/resources/languages/qt_de.qm
Binary file not shown.
Binary file removed rare/resources/languages/qt_pt_BR.qm
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8a3bdbd

Please sign in to comment.