Skip to content

Commit

Permalink
feat: Updated translations & added Traditional Chinese and Japanese
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmozhijin committed Nov 28, 2024
1 parent f10b067 commit 014e6ea
Show file tree
Hide file tree
Showing 16 changed files with 9,097 additions and 1,162 deletions.
Binary file modified LDDC/res/i18n/LDDC_en.qm
Binary file not shown.
1,070 changes: 622 additions & 448 deletions LDDC/res/i18n/LDDC_en.ts

Large diffs are not rendered by default.

Binary file added LDDC/res/i18n/LDDC_ja.qm
Binary file not shown.
1,970 changes: 1,970 additions & 0 deletions LDDC/res/i18n/LDDC_ja.ts

Large diffs are not rendered by default.

Binary file added LDDC/res/i18n/LDDC_zh-Hant.qm
Binary file not shown.
1,979 changes: 1,979 additions & 0 deletions LDDC/res/i18n/LDDC_zh-Hant.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions LDDC/res/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
</qresource>
<qresource prefix="/">
<file>i18n/LDDC_en.qm</file>
<file>i18n/LDDC_ja.qm</file>
<file>i18n/LDDC_zh-Hant.qm</file>
</qresource>
</RCC>
5,148 changes: 4,458 additions & 690 deletions LDDC/res/resource_rc.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LDDC/ui/local_match.ui
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
<bool>false</bool>
</property>
<property name="format">
<string>%v/%m %p%</string>
<string notr="true">%v/%m %p%</string>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion LDDC/ui/local_match_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def setupUi(self, local_match):
self.progressBar.setObjectName("progressBar")
self.progressBar.setOrientation(Qt.Orientation.Horizontal)
self.progressBar.setInvertedAppearance(False)
self.progressBar.setFormat("%v/%m %p%")

self.verticalLayout.addWidget(self.progressBar)

Expand Down Expand Up @@ -326,6 +327,5 @@ def retranslateUi(self, local_match):
___qtablewidgetitem5.setText(QCoreApplication.translate("local_match", "\u4fdd\u5b58\u8def\u5f84", None))
___qtablewidgetitem6 = self.songs_table.horizontalHeaderItem(6)
___qtablewidgetitem6.setText(QCoreApplication.translate("local_match", "\u72b6\u6001", None))
self.progressBar.setFormat(QCoreApplication.translate("local_match", "%v/%m %p%", None))

# retranslateUi
11 changes: 11 additions & 0 deletions LDDC/ui/search_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
<ui version="4.0">
<class>search_base</class>
<widget class="QWidget" name="search_base">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>672</width>
<height>415</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="source_comboBox">
<property name="sizeAdjustPolicy">
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
</property>
<item>
<property name="text">
<string>聚合</string>
Expand Down
2 changes: 2 additions & 0 deletions LDDC/ui/search_base_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Ui_search_base:
def setupUi(self, search_base):
if not search_base.objectName():
search_base.setObjectName("search_base")
search_base.resize(672, 415)
self.verticalLayout = QVBoxLayout(search_base)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QHBoxLayout()
Expand All @@ -44,6 +45,7 @@ def setupUi(self, search_base):
self.source_comboBox.addItem("")
self.source_comboBox.addItem("")
self.source_comboBox.setObjectName("source_comboBox")
self.source_comboBox.setSizeAdjustPolicy(QComboBox.SizeAdjustPolicy.AdjustToContents)

self.horizontalLayout.addWidget(self.source_comboBox)

Expand Down
14 changes: 12 additions & 2 deletions LDDC/ui/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,22 @@ li.checked::marker { content: &quot;\2612&quot;; }
</item>
<item>
<property name="text">
<string>英文</string>
<string notr="true">简体中文</string>
</property>
</item>
<item>
<property name="text">
<string>中文</string>
<string>繁體中文</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">English</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">日本語</string>
</property>
</item>
</widget>
Expand Down
7 changes: 4 additions & 3 deletions LDDC/ui/settings_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ def setupUi(self, settings):

self.language_comboBox = QComboBox(self.groupBox_6)
self.language_comboBox.addItem("")
self.language_comboBox.addItem("\u7b80\u4f53\u4e2d\u6587")
self.language_comboBox.addItem("")
self.language_comboBox.addItem("")
self.language_comboBox.addItem("English")
self.language_comboBox.addItem("\u65e5\u672c\u8a9e")
self.language_comboBox.setObjectName("language_comboBox")

self.gridLayout_2.addWidget(self.language_comboBox, 0, 2, 1, 1)
Expand Down Expand Up @@ -555,8 +557,7 @@ def retranslateUi(self, settings):

self.open_log_dir_button.setText(QCoreApplication.translate("settings", "\u6253\u5f00\u65e5\u5fd7\u6587\u4ef6\u5939", None))
self.language_comboBox.setItemText(0, QCoreApplication.translate("settings", "\u81ea\u52a8", None))
self.language_comboBox.setItemText(1, QCoreApplication.translate("settings", "\u82f1\u6587", None))
self.language_comboBox.setItemText(2, QCoreApplication.translate("settings", "\u4e2d\u6587", None))
self.language_comboBox.setItemText(2, QCoreApplication.translate("settings", "\u7e41\u9ad4\u4e2d\u6587", None))

self.label_7.setText(QCoreApplication.translate("settings", "\u8bed\u8a00\uff1a", None))
self.label_2.setText(QCoreApplication.translate("settings", "\u4e3b\u9898\u989c\u8272:", None))
Expand Down
36 changes: 23 additions & 13 deletions LDDC/utils/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ class _SignalHelper(QObject):
language_changed = _signal_helper.language_changed


def get_system_language() -> QLocale.Language:
def get_system_language() -> tuple[QLocale.Language, QLocale.Script]:
if platform.system() == 'Darwin':
try:
from Foundation import NSUserDefaults # type: ignore[reportMissingImports]
if (languages := NSUserDefaults.standardUserDefaults().objectForKey_("AppleLanguages")):
language = languages[0]
if language.startswith("zh"):
return QLocale.Language.Chinese
if language.startswith("zh-Hant"):
return QLocale.Language.Chinese, QLocale.Script.TraditionalHanScript
return QLocale.Language.Chinese, QLocale.Script.SimplifiedHanScript
except ImportError:
logger.warning("Failed to get system language on macOS")
return QLocale.system().language()
return QLocale.system().language(), QLocale.system().script()


def load_translation(emit: bool = True) -> None:
Expand All @@ -44,24 +46,32 @@ def load_translation(emit: bool = True) -> None:
translator = QTranslator()
qt_translator = QTranslator()
lang = cfg.get("language")
match lang:
case "auto":
if lang == "auto":
language, script = get_system_language()
match language:
case QLocale.Language.Chinese:
lang = 'zh-Hant' if script == QLocale.Script.TraditionalHanScript else 'zh-Hans'
case QLocale.Language.Japanese:
lang = 'ja'
case _:
lang = 'en'

language = get_system_language()
logger.info("System language detected: %s", language)
if language != QLocale.Language.Chinese:
translator.load(":/i18n/LDDC_en.qm")
if not qt_translator.load("qt_en.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
logger.warning("Failed to load qt_en.qm")
elif not qt_translator.load("qt_zh_CN.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
logger.warning("Failed to load qt_zh_CN.qm")
match lang:
case "en":
translator.load(":/i18n/LDDC_en.qm")
if not qt_translator.load("qt_en.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
logger.warning("Failed to load qt_en.qm")
case "zh-Hans":
if not qt_translator.load("qt_zh_CN.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
logger.warning("Failed to load qt_zh_CN.qm")
case "zh-Hant":
translator.load(":/i18n/LDDC_zh-Hant.ts")
if not qt_translator.load("qt_zh_TW.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
logger.warning("Failed to load qt_zh_TW.qm")
case "ja":
translator.load(":/i18n/LDDC_ja.qm")
if not qt_translator.load("qt_ja.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
logger.warning("Failed to load qt_ja.qm")
app.installTranslator(translator)
app.installTranslator(qt_translator)

Expand Down
16 changes: 12 additions & 4 deletions LDDC/view/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ def init_ui(self) -> None:
match cfg["language"]:
case "auto":
self.language_comboBox.setCurrentIndex(0)
case "en":
self.language_comboBox.setCurrentIndex(1)
case "zh-Hans":
self.language_comboBox.setCurrentIndex(1)
case "zh-Hant":
self.language_comboBox.setCurrentIndex(2)
case "en":
self.language_comboBox.setCurrentIndex(3)
case "ja":
self.language_comboBox.setCurrentIndex(4)

self.color_scheme_mapping = {
0: "auto",
Expand Down Expand Up @@ -217,9 +221,13 @@ def language_comboBox_changed(self, index: int) -> None:
case 0:
cfg.setitem("language", "auto")
case 1:
cfg.setitem("language", "en")
case 2:
cfg.setitem("language", "zh-Hans")
case 2:
cfg.setitem("language", "zh-Hant")
case 3:
cfg.setitem("language", "en")
case 4:
cfg.setitem("language", "ja")
load_translation()
self.init_ui()

Expand Down

0 comments on commit 014e6ea

Please sign in to comment.