Skip to content

Commit

Permalink
fix: Qt built-in buttons not translated in standalone mode
Browse files Browse the repository at this point in the history
  • Loading branch information
knipknap committed Aug 26, 2023
1 parent 69ec9f0 commit b47b186
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 13 additions & 6 deletions btl/i18n.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from PySide.QtCore import QTranslator, QLocale
from PySide.QtCore import QTranslator, QLocale, QLibraryInfo
from btl.const import translations_dir

# Unfortunately FreeCAD does not follow the standard "pt_BR" format,
Expand All @@ -8,18 +8,25 @@
# This makes it incompatible with the format expected by
# pyside.load(), so we need to assemble our own filename and
# reimplement the search.
locale = QLocale().name()
bcp47 = QLocale().bcp47Name()
locale = QLocale()
locale_name = locale.name()
bcp47 = locale.bcp47Name()
search_filenames = (
f"btl_{locale}.qm",
f"btl_{locale.replace('_', '-')}.qm",
f"btl_{locale_name}.qm",
f"btl_{locale_name.replace('_', '-')}.qm",
f"btl_{bcp47}.qm",
)

def install_translator(app):
# First the translator for Qt built-in strings.
path = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
translator = QTranslator(app)
if translator.load(locale, 'qtbase', '_', path):
app.installTranslator(translator)

# Now a translator for BTL strings.
translator = QTranslator(app)
for filename in search_filenames:
print(filename)
if translator.load(filename, translations_dir):
app.installTranslator(translator)
return
Expand Down
1 change: 0 additions & 1 deletion btl/qbtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
import argparse
from PySide import QtGui
from PySide.QtCore import QTranslator, QLocale
from btl import ToolDB, serializers
from btl.const import resource_dir
from btl.i18n import install_translator
Expand Down

0 comments on commit b47b186

Please sign in to comment.