Skip to content

Commit

Permalink
Fix translator (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Sep 2, 2023
1 parent 0da553a commit 4587cd5
Show file tree
Hide file tree
Showing 9 changed files with 1,129 additions and 625 deletions.
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,9 @@ translation_po_all:
TMP_POT_FILE_PATH := $(shell mktemp)
PO_FILE_PATH := locale/${locale}/LC_MESSAGES/buzz.po
translation_po:
if [[ -f "${PO_FILE_PATH}" ]]; then \
xgettext --from-code=UTF-8 -o ${TMP_POT_FILE_PATH} -l python buzz/gui.py; \
sed -i.bak 's/CHARSET/UTF-8/' ${TMP_POT_FILE_PATH} && rm ${TMP_POT_FILE_PATH}.bak; \
msgmerge -U ${PO_FILE_PATH} ${TMP_POT_FILE_PATH}; \
else \
mkdir -p locale/${locale}/LC_MESSAGES; \
xgettext --from-code=UTF-8 -o ${PO_FILE_PATH} -l python buzz/gui.py; \
sed -i.bak 's/CHARSET/UTF-8/' ${PO_FILE_PATH} && rm ${PO_FILE_PATH}.bak; \
fi
xgettext --from-code=UTF-8 -o "${TMP_POT_FILE_PATH}" -l python $(shell find buzz/widgets -name '*.py')
sed -i.bak 's/CHARSET/UTF-8/' ${TMP_POT_FILE_PATH} && rm ${TMP_POT_FILE_PATH}.bak
msgmerge -U ${PO_FILE_PATH} ${TMP_POT_FILE_PATH}

translation_mo:
for dir in locale/*/ ; do \
Expand Down
1 change: 1 addition & 0 deletions buzz/buzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
from typing import TextIO

from PyQt6.QtCore import QLocale
from appdirs import user_log_dir

# Check for segfaults if not running in frozen mode
Expand Down
9 changes: 3 additions & 6 deletions buzz/locale.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import gettext
import os

from PyQt6.QtCore import QLocale

from buzz.assets import get_asset_path
from buzz.settings.settings import APP_NAME

if "LANG" not in os.environ:
language = str(QLocale().uiLanguages()[0]).replace("-", "_")
os.environ["LANG"] = language

locale_dir = get_asset_path("locale")
gettext.bindtextdomain("buzz", locale_dir)

translate = gettext.translation(APP_NAME, locale_dir, fallback=True)
translate = gettext.translation(
APP_NAME, locale_dir, languages=QLocale().uiLanguages(), fallback=True
)

_ = translate.gettext
Loading

0 comments on commit 4587cd5

Please sign in to comment.