Skip to content

Commit c2ee635

Browse files
fanquakeFuzzbawls
authored andcommitted
build: automatically determine macOS translations
Rather than using OSX_QT_TRANSLATIONS which must be manually updated, and we forget to update anyway, automatically find and copy available translations from the translations directory.
1 parent 1c44ecf commit c2ee635

File tree

2 files changed

+23
-45
lines changed

2 files changed

+23
-45
lines changed

Makefile.am

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ OSX_DEPLOY_SCRIPT=$(top_srcdir)/contrib/macdeploy/macdeployqtplus
4040
OSX_FANCY_PLIST=$(top_srcdir)/contrib/macdeploy/fancy.plist
4141
OSX_INSTALLER_ICONS=$(top_srcdir)/src/qt/res/icons/bitcoin.icns
4242
OSX_PLIST=$(top_builddir)/share/qt/Info.plist #not installed
43-
OSX_QT_TRANSLATIONS = da,de,es,hu,ru,uk,zh_CN,zh_TW
4443

4544
DIST_DOCS = $(wildcard doc/*.md) $(wildcard doc/release-notes/*.md)
4645
DIST_CONTRIB = $(top_srcdir)/contrib/pivx-cli.bash-completion \
@@ -140,7 +139,7 @@ osx_volname:
140139

141140
if BUILD_DARWIN
142141
$(OSX_DMG): $(OSX_APP_BUILT) $(OSX_PACKAGING) $(OSX_BACKGROUND_IMAGE)
143-
$(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)
142+
$(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -dmg -fancy $(OSX_FANCY_PLIST) -verbose 2 -volname $(OSX_VOLNAME)
144143

145144
$(OSX_BACKGROUND_IMAGE).png: contrib/macdeploy/$(OSX_BACKGROUND_SVG)
146145
sed 's/PACKAGE_NAME/$(PACKAGE_NAME)/' < "$<" | $(RSVG_CONVERT) -f png -d 36 -p 36 -o $@
@@ -174,7 +173,7 @@ $(APP_DIST_DIR)/.DS_Store: $(OSX_DSSTORE_GEN)
174173
$(PYTHON) $< "$@" "$(OSX_VOLNAME)"
175174

176175
$(APP_DIST_DIR)/$(OSX_APP)/Contents/MacOS/PIVX-Qt: $(OSX_APP_BUILT) $(OSX_PACKAGING)
177-
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
176+
INSTALLNAMETOOL=$(INSTALLNAMETOOL) OTOOL=$(OTOOL) STRIP=$(STRIP) $(PYTHON) $(OSX_DEPLOY_SCRIPT) $(OSX_APP) -translations-dir=$(QT_TRANSLATION_DIR) -verbose 2
178177

179178
deploydir: $(APP_DIST_EXTRAS)
180179
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
@@ -527,8 +528,7 @@ ap.add_argument("-no-strip", dest="strip", action="store_false", default=True, h
527528
ap.add_argument("-sign", dest="sign", action="store_true", default=False, help="sign .app bundle with codesign tool")
528529
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")
529530
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")
530-
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")
531-
ap.add_argument("-translations-dir", nargs=1, metavar="path", default=None, help="Path to Qt's translation files")
531+
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.")
532532
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")
533533
ap.add_argument("-volname", nargs=1, metavar="volname", default=[], help="custom volume name for dmg")
534534

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

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

561552
for p in config.add_resources:
562553
if verbose >= 3:
@@ -685,26 +676,24 @@ if config.plugins:
685676

686677
# ------------------------------------------------
687678

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

709698
# ------------------------------------------------
710699

@@ -716,16 +705,6 @@ with open(os.path.join(applicationBundle.resourcesPath, "qt.conf"), "wb") as f:
716705

717706
# ------------------------------------------------
718707

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

0 commit comments

Comments
 (0)