Skip to content

Commit 4d70d3d

Browse files
committed
build: automatically determine macOS translations
Rather than using OSX_QT_TRANSLATIONS which must be manually updated, and we forget to update anyway, i.e: #19059, automatically find and copy available translations from the translations directory.
1 parent 2e1336d commit 4d70d3d

File tree

3 files changed

+23
-46
lines changed

3 files changed

+23
-46
lines changed

Makefile.am

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ OSX_DEPLOY_SCRIPT=$(top_srcdir)/contrib/macdeploy/macdeployqtplus
4141
OSX_FANCY_PLIST=$(top_srcdir)/contrib/macdeploy/fancy.plist
4242
OSX_INSTALLER_ICONS=$(top_srcdir)/src/qt/res/icons/bitcoin.icns
4343
OSX_PLIST=$(top_builddir)/share/qt/Info.plist #not installed
44-
OSX_QT_TRANSLATIONS = ar,bg,ca,cs,da,de,es,fa,fi,fr,gd,gl,he,hu,it,ja,ko,lt,lv,pl,pt,ru,sk,sl,sv,uk,zh_CN,zh_TW
4544

4645
DIST_CONTRIB = \
4746
$(top_srcdir)/contrib/linearize/linearize-data.py \
@@ -117,7 +116,7 @@ osx_volname:
117116

118117
if BUILD_DARWIN
119118
$(OSX_DMG): $(OSX_APP_BUILT) $(OSX_PACKAGING) $(OSX_BACKGROUND_IMAGE)
120-
$(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -add-qt-tr $(OSX_QT_TRANSLATIONS) -translations-dir=$(QT_TRANSLATION_DIR) -dmg -fancy $(OSX_FANCY_PLIST) -verbose 2 -volname $(OSX_VOLNAME)
119+
$(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -dmg -fancy $(OSX_FANCY_PLIST) -verbose 2 -volname $(OSX_VOLNAME)
121120

122121
$(OSX_BACKGROUND_IMAGE).png: contrib/macdeploy/$(OSX_BACKGROUND_SVG)
123122
sed 's/PACKAGE_NAME/$(PACKAGE_NAME)/' < "$<" | $(RSVG_CONVERT) -f png -d 36 -p 36 -o $@
@@ -151,7 +150,7 @@ $(APP_DIST_DIR)/.DS_Store: $(OSX_DSSTORE_GEN)
151150
$(PYTHON) $< "$@" "$(OSX_VOLNAME)"
152151

153152
$(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/Bitcoin-Qt: $(OSX_APP_BUILT) $(OSX_PACKAGING)
154-
INSTALLNAMETOOL=$(INSTALLNAMETOOL) OTOOL=$(OTOOL) STRIP=$(STRIP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -add-qt-tr $(OSX_QT_TRANSLATIONS) -verbose 2
153+
INSTALLNAMETOOL=$(INSTALLNAMETOOL) OTOOL=$(OTOOL) STRIP=$(STRIP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -verbose 2
155154

156155
deploydir: $(APP_DIST_EXTRAS)
157156
endif

contrib/macdeploy/macdeployqtplus

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#
1818

1919
import subprocess, sys, re, os, shutil, stat, os.path, time
20-
from string import Template
2120
from argparse import ArgumentParser
21+
from pathlib import Path
22+
from string import Template
2223
from typing import List, Optional
2324

2425
# This is ported from the original macdeployqt with modifications
@@ -526,8 +527,7 @@ ap.add_argument("-no-strip", dest="strip", action="store_false", default=True, h
526527
ap.add_argument("-sign", dest="sign", action="store_true", default=False, help="sign .app bundle with codesign tool")
527528
ap.add_argument("-dmg", nargs="?", const="", metavar="basename", help="create a .dmg disk image; if basename is not specified, a camel-cased version of the app name is used")
528529
ap.add_argument("-fancy", nargs=1, metavar="plist", default=[], help="make a fancy looking disk image using the given plist file with instructions; requires -dmg to work")
529-
ap.add_argument("-add-qt-tr", nargs=1, metavar="languages", default=[], help="add Qt translation files to the bundle's resources; the language list must be separated with commas, not with whitespace")
530-
ap.add_argument("-translations-dir", nargs=1, metavar="path", default=None, help="Path to Qt's translation files")
530+
ap.add_argument("-translations-dir", nargs=1, metavar="path", default=None, help="Path to Qt's translations. Base translations will automatically be added to the bundle's resources.")
531531
ap.add_argument("-add-resources", nargs="+", metavar="path", default=[], help="list of additional files or folders to be copied into the bundle's resources; must be the last argument")
532532
ap.add_argument("-volname", nargs=1, metavar="volname", default=[], help="custom volume name for dmg")
533533

@@ -547,15 +547,6 @@ if not os.path.exists(app_bundle):
547547
app_bundle_name = os.path.splitext(os.path.basename(app_bundle))[0]
548548

549549
# ------------------------------------------------
550-
translations_dir = None
551-
if config.translations_dir and config.translations_dir[0]:
552-
if os.path.exists(config.translations_dir[0]):
553-
translations_dir = config.translations_dir[0]
554-
else:
555-
if verbose >= 1:
556-
sys.stderr.write("Error: Could not find translation dir \"{}\"\n".format(translations_dir))
557-
sys.exit(1)
558-
# ------------------------------------------------
559550

560551
for p in config.add_resources:
561552
if verbose >= 3:
@@ -684,26 +675,24 @@ if config.plugins:
684675

685676
# ------------------------------------------------
686677

687-
if len(config.add_qt_tr) == 0:
688-
add_qt_tr = []
689-
else:
690-
if translations_dir is not None:
691-
qt_tr_dir = translations_dir
692-
else:
693-
if deploymentInfo.qtPath is not None:
694-
qt_tr_dir = os.path.join(deploymentInfo.qtPath, "translations")
695-
else:
696-
sys.stderr.write("Error: Could not find Qt translation path\n")
697-
sys.exit(1)
698-
add_qt_tr = ["qt_{}.qm".format(lng) for lng in config.add_qt_tr[0].split(",")]
699-
for lng_file in add_qt_tr:
700-
p = os.path.join(qt_tr_dir, lng_file)
701-
if verbose >= 3:
702-
print("Checking for \"{}\"...".format(p))
703-
if not os.path.exists(p):
704-
if verbose >= 1:
705-
sys.stderr.write("Error: Could not find Qt translation file \"{}\"\n".format(lng_file))
706-
sys.exit(1)
678+
if config.translations_dir:
679+
if not Path(config.translations_dir[0]).exists():
680+
sys.stderr.write("Error: Could not find translation dir \"{}\"\n".format(config.translations_dir[0]))
681+
sys.exit(1)
682+
683+
if verbose >= 2:
684+
print("+ Adding Qt translations +")
685+
686+
translations = Path(config.translations_dir[0])
687+
688+
regex = re.compile('qt_[a-z]*(.qm|_[A-Z]*.qm)')
689+
690+
lang_files = [x for x in translations.iterdir() if regex.match(x.name)]
691+
692+
for file in lang_files:
693+
if verbose >= 3:
694+
print(file.as_posix(), "->", os.path.join(applicationBundle.resourcesPath, file.name))
695+
shutil.copy2(file.as_posix(), os.path.join(applicationBundle.resourcesPath, file.name))
707696

708697
# ------------------------------------------------
709698

@@ -715,16 +704,6 @@ with open(os.path.join(applicationBundle.resourcesPath, "qt.conf"), "wb") as f:
715704

716705
# ------------------------------------------------
717706

718-
if len(add_qt_tr) > 0 and verbose >= 2:
719-
print("+ Adding Qt translations +")
720-
721-
for lng_file in add_qt_tr:
722-
if verbose >= 3:
723-
print(os.path.join(qt_tr_dir, lng_file), "->", os.path.join(applicationBundle.resourcesPath, lng_file))
724-
shutil.copy2(os.path.join(qt_tr_dir, lng_file), os.path.join(applicationBundle.resourcesPath, lng_file))
725-
726-
# ------------------------------------------------
727-
728707
if len(config.add_resources) > 0 and verbose >= 2:
729708
print("+ Adding additional resources +")
730709

depends/packages/qt.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ $(package)_patches+= fix_android_qmake_conf.patch fix_android_jni_static.patch d
1414
$(package)_patches+= freetype_back_compat.patch drop_lrelease_dependency.patch fix_powerpc_libpng.patch
1515
$(package)_patches+= fix_mingw_cross_compile.patch fix_qpainter_non_determinism.patch
1616

17-
# Update OSX_QT_TRANSLATIONS when this is updated
1817
$(package)_qttranslations_file_name=qttranslations-$($(package)_suffix)
1918
$(package)_qttranslations_sha256_hash=fb5a47799754af73d3bf501fe513342cfe2fc37f64e80df5533f6110e804220c
2019

0 commit comments

Comments
 (0)