Skip to content

Commit

Permalink
feat(build): Add Qt translations
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmozhijin committed Dec 14, 2024
1 parent c6bbea2 commit e62a524
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
echo "copyright=Copyright (C) $(python build_helper.py --task get_year) 沉默の金" >> $GITHUB_OUTPUT
echo "version=$(python build_helper.py --task get_version)" >> $GITHUB_OUTPUT
echo "num_version=$(python build_helper.py --task get_num_version)" >> $GITHUB_OUTPUT
echo "qt_translations_path=$(python build_helper.py --task get_qt_translations_path)" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Build Executable(Linux)
Expand All @@ -110,6 +111,12 @@ jobs:
macos-app-icon: "LDDC/res/img/icon/logo.icns"
macos-app-version: ${{ steps.info.outputs.num_version }}
macos-target-arch: ${{ steps.arch.outputs.nuitka_arch }}

include-data-files: |
"${{ steps.info.outputs.qt_translations_path }}/qtbase_en.qm=qtbase_en.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_zh_CN.qm=qtbase_zh_CN.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_zh_TW.qm=qtbase_zh_TW.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_ja.qm=qtbase_ja.qm"
env:
PYTHONPATH: ${{ github.workspace }}

Expand All @@ -132,6 +139,12 @@ jobs:
macos-app-icon: "LDDC/res/img/icon/logo.icns"
macos-app-version: ${{ steps.info.outputs.num_version }}
macos-target-arch: ${{ steps.arch.outputs.nuitka_arch }}

include-data-files: |
"${{ steps.info.outputs.qt_translations_path }}/qtbase_en.qm=PySide6/Qt/translations/qtbase_en.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_zh_CN.qm=PySide6/Qt/translations/qtbase_zh_CN.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_zh_TW.qm=PySide6/Qt/translations/qtbase_zh_TW.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_ja.qm=PySide6/Qt/translations/qtbase_ja.qm"
env:
PYTHONPATH: ${{ github.workspace }}

Expand All @@ -153,6 +166,13 @@ jobs:
windows-icon-from-ico: "LDDC/res/img/icon/logo.ico"
mingw64: true
windows-console-mode: 'attach'

include-data-files: |
"${{ steps.info.outputs.qt_translations_path }}/qtbase_en.qm=PySide6/translations/qtbase_en.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_zh_CN.qm=PySide6/translations/qtbase_zh_CN.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_zh_TW.qm=PySide6/translations/qtbase_zh_TW.qm"
"${{ steps.info.outputs.qt_translations_path }}/qtbase_ja.qm=PySide6/translations/qtbase_ja.qm"
env:
PYTHONPATH: ${{ github.workspace }}

Expand Down
8 changes: 4 additions & 4 deletions LDDC/utils/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ def load_translation(emit: bool = True) -> None:
match lang:
case "en":
translator.load(":/i18n/LDDC_en.qm")
if not qt_translator.load("qt_en.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
if not qt_translator.load("qtbase_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)):
if not qt_translator.load("qtbase_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)):
if not qt_translator.load("qtbase_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)):
if not qt_translator.load("qtbase_ja.qm", QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)):
logger.warning("Failed to load qt_ja.qm")
app.installTranslator(translator)
app.installTranslator(qt_translator)
Expand Down

0 comments on commit e62a524

Please sign in to comment.