Skip to content

Commit

Permalink
#2 增加编译po的工作流
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorReid committed Jun 16, 2024
1 parent 3a3dec4 commit b0dce4e
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 4 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/locale-po.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Compile po into mo

on:
push:
branches:
- dev_locale

jobs:
job1:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pip install polib==1.2.0

- name: Show dir
run: pwd

- name: Compile PO files
run: |
PYTHONPATH=$(pwd) python your_script.py python src/one_dragon/devtools/compile_po.py
- name: Commit changes
run: |
if ! git diff --quiet; then
git config user.name github-actions
git config user.email [email protected]
git add data/locales/**/*.mo
git commit -m "#2 自动编译mo文件提交 $(date +%Y-%m-%d)"
git push
else
echo "No file modifications"
fi
Binary file added assets/text/output/cn/LC_MESSAGES/ocr.mo
Binary file not shown.
Binary file added assets/text/output/cn/LC_MESSAGES/ui.mo
Binary file not shown.
Binary file added assets/text/output/en/LC_MESSAGES/ocr.mo
Binary file not shown.
Binary file added assets/text/output/en/LC_MESSAGES/ui.mo
Binary file not shown.
5 changes: 3 additions & 2 deletions requirements-dev-ext.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# extra requirements that development or deployment needs
pyinstaller==6.7.0
pip-tools==7.4.1
polib==1.2.0 # i18 compile .mo file into .po file
pyinstaller==6.7.0 # package into exe
pip-tools==7.4.1 # use pip-compile
Empty file.
36 changes: 36 additions & 0 deletions src/one_dragon/devtools/compile_po.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

import polib

from one_dragon.utils import os_utils


def compile_lang(model: str, lang: str):
"""
将特定语言的文件编译成mo文件
:param model: 模块 不同模块的多语言文本区分
:param lang: 语言 cn
:return: None
"""
base_dir = os_utils.get_path_under_work_dir('assets', 'text')
po_file_path = os.path.join(base_dir, model, '%s.po' % lang)

output_dir = os_utils.get_path_under_work_dir('assets', 'text', 'output', lang, 'LC_MESSAGES')
mo_file_path = os.path.join(output_dir, '%s.mo' % model)

po = polib.pofile(po_file_path)
po.save_as_mofile(mo_file_path)


def compile_po_files():
"""
将不同语言的po文件编译成mo
:return:
"""
for model in ['ocr', 'ui']:
for lang in ['cn', 'en']:
compile_lang(model, lang)


if __name__ == '__main__':
compile_po_files()
3 changes: 2 additions & 1 deletion src/one_dragon/gui/app/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def init_navigation(self):
def init_window(self):
title = f"{gt(self.project_config.project_name, 'ui')} {gt('安装器', 'ui')}"
self.setWindowTitle(title)
self.resize(960, 720)
self.resize(960, 820)
self.move(100, 100)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion src/one_dragon/utils/i18_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_translations(model: str, lang: str):
:param lang: 语言
:return:
"""
translate_path = os_utils.get_path_under_work_dir('assets', 'text')
translate_path = os_utils.get_path_under_work_dir('assets', 'text', 'output')
lang_dir = os.path.join(translate_path, lang, 'LC_MESSAGES', f'{model}.mo')
# 未有对应的文本mo文件
if not os.path.exists(lang_dir):
Expand Down

0 comments on commit b0dce4e

Please sign in to comment.