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.
This commit is contained in:
Guillaume LE VAILLANT 2018-04-23 13:51:11 +02:00
parent 5a5d92e6f6
commit cfc6abcfdc
2 changed files with 41 additions and 57 deletions

View file

@ -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 {
}
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()

View file

@ -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,13 +367,29 @@ 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,
# for development, just build debug version of libwallet_merged lib
# by invoking 'get_libwallet_api.sh Debug'
@ -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