diff options
| author | Guillaume LE VAILLANT <glv@posteo.net> | 2018-04-23 13:51:11 +0200 |
|---|---|---|
| committer | Guillaume LE VAILLANT <glv@posteo.net> | 2018-04-23 13:56:12 +0200 |
| commit | cfc6abcfdc72ade22d3068e2dee4be04d624f1a6 (patch) | |
| tree | 90d7962651a9364dd9f2369cc2cf22451d97850e | |
| parent | 5a5d92e6f64a85b251c89bf95e1ffc5dc438f089 (diff) | |
| download | monzero-gui-cfc6abcfdc72ade22d3068e2dee4be04d624f1a6.tar.gz monzero-gui-cfc6abcfdc72ade22d3068e2dee4be04d624f1a6.tar.xz monzero-gui-cfc6abcfdc72ade22d3068e2dee4be04d624f1a6.zip | |
Embed the translation files in the monero-wallet-gui binary
If a translation file exists in a "translations" directory located in the same
directory as the binary, it is used in priority (this can be useful when working
on translations as you don't have to recompile the whole program all the time),
and if no such file is found the embedded translation file is used.
| -rw-r--r-- | TranslationManager.cpp | 30 | ||||
| -rw-r--r-- | monero-wallet-gui.pro | 68 |
2 files changed, 41 insertions, 57 deletions
diff --git a/TranslationManager.cpp b/TranslationManager.cpp index fa39d35a..e7fc52aa 100644 --- a/TranslationManager.cpp +++ b/TranslationManager.cpp @@ -25,19 +25,12 @@ bool TranslationManager::setLanguage(const QString &language) return true; } - // translations are compiled into app binary -#ifdef Q_OS_MACX - QString dir = qApp->applicationDirPath() + "/../Resources/translations"; -#else QString dir = qApp->applicationDirPath() + "/translations"; -#endif - QString filename = "monero-core_" + language; - qDebug("%s: loading translation file '%s' from '%s", + qDebug("%s: loading translation file '%s' from '%s'", __FUNCTION__, qPrintable(filename), qPrintable(dir)); - if (m_translator->load(filename, dir)) { qDebug("%s: translation for language '%s' loaded successfully", __FUNCTION__, qPrintable(language)); @@ -45,11 +38,24 @@ bool TranslationManager::setLanguage(const QString &language) qApp->installTranslator(m_translator); emit languageChanged(); return true; - } else { - qCritical("%s: error loading translation for language '%s'", - __FUNCTION__, qPrintable(language)); - return false; } + + qDebug("%s: couldn't load translation file '%s' from '%s'", + __FUNCTION__, qPrintable(filename), qPrintable(dir)); + qDebug("%s: loading embedded translation file '%s'", + __FUNCTION__, qPrintable(filename)); + + if (m_translator->load(filename, ":")) { + qDebug("%s: embedded translation for language '%s' loaded successfully", + __FUNCTION__, qPrintable(language)); + qApp->installTranslator(m_translator); + emit languageChanged(); + return true; + } + + qCritical("%s: error loading translation for language '%s'", + __FUNCTION__, qPrintable(language)); + return false; } TranslationManager *TranslationManager::instance() diff --git a/monero-wallet-gui.pro b/monero-wallet-gui.pro index 45561ba8..fff30254 100644 --- a/monero-wallet-gui.pro +++ b/monero-wallet-gui.pro @@ -327,38 +327,7 @@ macx { # translation stuff -TRANSLATIONS = \ # English is default language, no explicit translation file - $$PWD/translations/monero-core.ts \ # translation source (copy this file when creating a new translation) - $$PWD/translations/monero-core_ar.ts \ # Arabic - $$PWD/translations/monero-core_pt-br.ts \ # Portuguese (Brazil) - $$PWD/translations/monero-core_de.ts \ # German - $$PWD/translations/monero-core_eo.ts \ # Esperanto - $$PWD/translations/monero-core_es.ts \ # Spanish - $$PWD/translations/monero-core_fi.ts \ # Finnish - $$PWD/translations/monero-core_fr.ts \ # French - $$PWD/translations/monero-core_hr.ts \ # Croatian - $$PWD/translations/monero-core_id.ts \ # Indonesian - $$PWD/translations/monero-core_hi.ts \ # Hindi - $$PWD/translations/monero-core_it.ts \ # Italian - $$PWD/translations/monero-core_ja.ts \ # Japanese - $$PWD/translations/monero-core_nl.ts \ # Dutch - $$PWD/translations/monero-core_pl.ts \ # Polish - $$PWD/translations/monero-core_ru.ts \ # Russian - $$PWD/translations/monero-core_sv.ts \ # Swedish - $$PWD/translations/monero-core_zh-cn.ts \ # Chinese (Simplified-China) - $$PWD/translations/monero-core_zh-tw.ts \ # Chinese (Traditional-Taiwan) - $$PWD/translations/monero-core_he.ts \ # Hebrew - $$PWD/translations/monero-core_ko.ts \ # Korean - $$PWD/translations/monero-core_ro.ts \ # Romanian - $$PWD/translations/monero-core_da.ts \ # Danish - $$PWD/translations/monero-core_cs.ts \ # Czech - $$PWD/translations/monero-core_sk.ts \ # Slovak - $$PWD/translations/monero-core_sl.ts \ # Slovenian - $$PWD/translations/monero-core_rs.ts \ # Serbian - $$PWD/translations/monero-core_cat.ts \ # Catalan - $$PWD/translations/monero-core_tr.ts \ # Turkish - $$PWD/translations/monero-core_ua.ts \ # Ukrainian - $$PWD/translations/monero-core_pt-pt.ts \ # Portuguese (Portugal) +TRANSLATIONS = $$files($$PWD/translations/monero-core_*.ts) CONFIG(release, debug|release) { DESTDIR = release/bin @@ -371,14 +340,7 @@ CONFIG(release, debug|release) { # LANGREL_OPTIONS = -markuntranslated "MISS_TR " } -TARGET_FULL_PATH = $$OUT_PWD/$$DESTDIR -TRANSLATION_TARGET_DIR = $$TARGET_FULL_PATH/translations - -macx { - TARGET_FULL_PATH = $$sprintf("%1/%2/%3.app", $$OUT_PWD, $$DESTDIR, $$TARGET) - TRANSLATION_TARGET_DIR = $$TARGET_FULL_PATH/Contents/Resources/translations -} - +TRANSLATION_TARGET_DIR = $$OUT_PWD/translations !ios { isEmpty(QMAKE_LUPDATE) { @@ -405,11 +367,27 @@ macx { QMAKE_EXTRA_TARGETS += langupd deploy deploy_win QMAKE_EXTRA_COMPILERS += langrel -} - - - + # Compile an initial version of translation files when running qmake + # the first time and generate the resource file for translations. + !exists($$TRANSLATION_TARGET_DIR) { + mkpath($$TRANSLATION_TARGET_DIR) + } + qrc_entry = "<RCC>" + qrc_entry += ' <qresource prefix="/">' + write_file($$TRANSLATION_TARGET_DIR/translations.qrc, qrc_entry) + for(tsfile, TRANSLATIONS) { + qmfile = $$TRANSLATION_TARGET_DIR/$$basename(tsfile) + qmfile ~= s/.ts$/.qm/ + system($$LANGREL $$LANGREL_OPTIONS $$tsfile -qm $$qmfile) + qrc_entry = " <file>$$basename(qmfile)</file>" + write_file($$TRANSLATION_TARGET_DIR/translations.qrc, qrc_entry, append) + } + qrc_entry = " </qresource>" + qrc_entry += "</RCC>" + write_file($$TRANSLATION_TARGET_DIR/translations.qrc, qrc_entry, append) + RESOURCES += $$TRANSLATION_TARGET_DIR/translations.qrc +} # Update: no issues with the "slow link process" anymore, @@ -432,7 +410,7 @@ macx { } win32 { - deploy.commands += windeployqt $$sprintf("%1/%2/%3.exe", $$OUT_PWD, $$DESTDIR, $$TARGET) -release -qmldir=$$PWD + deploy.commands += windeployqt $$sprintf("%1/%2/%3.exe", $$OUT_PWD, $$DESTDIR, $$TARGET) -release -no-translations -qmldir=$$PWD # Win64 msys2 deploy settings contains(QMAKE_HOST.arch, x86_64) { deploy.commands += $$escape_expand(\n\t) $$PWD/windeploy_helper.sh $$DESTDIR |
