From a9339838ac295a4d045433c1b20fd5666fb35575 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 19 Jul 2016 23:31:09 +0300 Subject: TranslationManager, Russian translation example --- TranslationManager.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 TranslationManager.cpp (limited to 'TranslationManager.cpp') diff --git a/TranslationManager.cpp b/TranslationManager.cpp new file mode 100644 index 00000000..69448ce2 --- /dev/null +++ b/TranslationManager.cpp @@ -0,0 +1,63 @@ +#include "TranslationManager.h" + +#include +#include +#include +#include +#include + + +TranslationManager * TranslationManager::m_instance = nullptr; + + +TranslationManager::TranslationManager(QObject *parent) : QObject(parent) +{ + m_translator = new QTranslator(this); +} + +bool TranslationManager::setLanguage(const QString &language) +{ + qDebug() << __FUNCTION__ << " " << language; + // if language is "en", remove translator + if (language.toLower() == "en") { + qApp->removeTranslator(m_translator); + emit languageChanged(); + return true; + } + + // we expecting to have translation files in "i18n" directory + QString dir = qApp->applicationDirPath() + QDir::separator() + "i18n"; + + QString filename = "monero-core_" + language; + + 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)); + // TODO: apply locale? + qApp->installTranslator(m_translator); + emit languageChanged(); + return true; + } else { + qCritical("%s: error loading translation for language '%s'", + __FUNCTION__, qPrintable(language)); + return false; + } +} + +TranslationManager *TranslationManager::instance() +{ + if (!m_instance) { + m_instance = new TranslationManager(); + } + return m_instance; +} + +QString TranslationManager::emptyString() +{ + return ""; +} + -- cgit v1.2.3 From aa0ea18356ca2435aac7fd0d2ae8f9e638bdaa46 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Thu, 21 Jul 2016 16:29:37 +0300 Subject: translation files moved to resources --- TranslationManager.cpp | 4 ++-- monero-core.pro | 7 ++++--- qml.qrc | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'TranslationManager.cpp') diff --git a/TranslationManager.cpp b/TranslationManager.cpp index 69448ce2..afd04ef6 100644 --- a/TranslationManager.cpp +++ b/TranslationManager.cpp @@ -25,8 +25,8 @@ bool TranslationManager::setLanguage(const QString &language) return true; } - // we expecting to have translation files in "i18n" directory - QString dir = qApp->applicationDirPath() + QDir::separator() + "i18n"; + // translations are compiled into app binary + QString dir = ":/translations"; QString filename = "monero-core_" + language; diff --git a/monero-core.pro b/monero-core.pro index 877019d0..0c24ea0d 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -90,8 +90,9 @@ linux { macx { LIBS+= \ - -lboost_serialization \ - -lboost_thread \ + -L/usr/local/lib \ + -lboost_serialization \ + -lboost_thread-mt \ -lboost_system \ -lboost_date_time \ -lboost_filesystem \ @@ -123,7 +124,7 @@ trans_update.depends = $$_PRO_FILE_ trans_release.commands = lrelease $$_PRO_FILE_ trans_release.depends = trans_update $$TRANSLATIONS -translate.commands = $(MKDIR) ${DESTDIR}/i18n && $(COPY) $$PWD/translations/*.qm ${DESTDIR}/i18n +#translate.commands = $(MKDIR) ${DESTDIR}/i18n && $(COPY) $$PWD/translations/*.qm ${DESTDIR}/i18n translate.depends = trans_release QMAKE_EXTRA_TARGETS += trans_update trans_release translate diff --git a/qml.qrc b/qml.qrc index eca9f561..152ea8f2 100644 --- a/qml.qrc +++ b/qml.qrc @@ -114,5 +114,11 @@ pages/Receive.qml components/IconButton.qml lang/flags/italy.png + translations/monero-core_de.qm + translations/monero-core_en.qm + translations/monero-core_it.qm + translations/monero-core_pl.qm + translations/monero-core_ru.qm + translations/monero-core_zh.qm -- cgit v1.2.3 From 9cd73dfbbed6e200852ca9e1c1494ea3e5eae6c3 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Wed, 27 Jul 2016 22:32:33 +0300 Subject: Translations are separate qm files --- .gitignore | 1 + TranslationManager.cpp | 6 +++- build.sh | 9 ++++-- main.cpp | 3 ++ monero-core.pro | 86 +++++++++++++++++++++++++++++--------------------- qml.qrc | 6 ---- 6 files changed, 65 insertions(+), 46 deletions(-) (limited to 'TranslationManager.cpp') diff --git a/.gitignore b/.gitignore index a2ce1444..f2bec9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.user *.user.* +translations/*.qm diff --git a/TranslationManager.cpp b/TranslationManager.cpp index afd04ef6..fa39d35a 100644 --- a/TranslationManager.cpp +++ b/TranslationManager.cpp @@ -26,7 +26,11 @@ bool TranslationManager::setLanguage(const QString &language) } // translations are compiled into app binary - QString dir = ":/translations"; +#ifdef Q_OS_MACX + QString dir = qApp->applicationDirPath() + "/../Resources/translations"; +#else + QString dir = qApp->applicationDirPath() + "/translations"; +#endif QString filename = "monero-core_" + language; diff --git a/build.sh b/build.sh index 5cfea74d..3c3260f5 100755 --- a/build.sh +++ b/build.sh @@ -2,14 +2,17 @@ pushd $(pwd) ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BITMOMERO_DIR=bitmonero -#$SHELL get_libwallet_api.sh +if [ ! -d $BITMOMERO_DIR ]; then + $SHELL get_libwallet_api.sh +fi if [ ! -d build ]; then mkdir build; fi cd build echo $(pwd) -qmake ../monero-core.pro "CONFIG += release" -make release +qmake ../monero-core.pro "CONFIG+=release" +make make deploy popd diff --git a/main.cpp b/main.cpp index 030a21c3..9f109e01 100644 --- a/main.cpp +++ b/main.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "clipboardAdapter.h" #include "filter.h" #include "oscursor.h" @@ -46,6 +47,8 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + qDebug() << "app startd"; + app.setApplicationName("monero-core"); app.setOrganizationDomain("getmonero.org"); app.setOrganizationName("The Monero Project"); diff --git a/monero-core.pro b/monero-core.pro index 0997d2bd..668cecdb 100644 --- a/monero-core.pro +++ b/monero-core.pro @@ -5,7 +5,6 @@ QT += qml quick widgets WALLET_ROOT=$$PWD/bitmonero CONFIG += c++11 -CONFIG += debug_and_release # cleaning "auto-generated" bitmonero directory on "make distclean" QMAKE_DISTCLEAN += -r $$WALLET_ROOT @@ -13,8 +12,6 @@ QMAKE_DISTCLEAN += -r $$WALLET_ROOT INCLUDEPATH += $$WALLET_ROOT/include \ $$PWD/src/libwalletqt - - HEADERS += \ filter.h \ clipboardAdapter.h \ @@ -104,51 +101,59 @@ macx { -lcrypto \ -ldl - deploy.commands += macdeployqt $$sprintf("%1/release/%2.app", $$OUT_PWD,$$TARGET) } -deploy.commands += - -# translations files; -TRANSLATIONS = $$PWD/translations/monero-core_en.ts \ # English (could be untranslated) - $$PWD/translations/monero-core_de.ts \ # Deutsch - $$PWD/translations/monero-core_zh.ts \ # Chineese - $$PWD/translations/monero-core_ru.ts \ # Russian - $$PWD/translations/monero-core_it.ts \ # Italian - $$PWD/translations/monero-core_pl.ts \ # Polish - - - -# extra make targets for lupdate and lrelease invocation -# use "make lupdate" to update *.ts files and "make lrelease" to generate *.qm files -trans_update.commands = lupdate $$_PRO_FILE_ -trans_update.depends = $$_PRO_FILE_ - -trans_release.commands = lrelease $$_PRO_FILE_ -trans_release.depends = trans_update $$TRANSLATIONS - -#translate.commands = $(MKDIR) ${DESTDIR}/i18n && $(COPY) $$PWD/translations/*.qm ${DESTDIR}/i18n -translate.depends = trans_release - +# translation stuff +TRANSLATIONS = \ # English is default language, no explicit translation file + $$PWD/translations/monero-core_de.ts \ # Deutsch + $$PWD/translations/monero-core_zh.ts \ # Chineese + $$PWD/translations/monero-core_ru.ts \ # Russian + $$PWD/translations/monero-core_it.ts \ # Italian + $$PWD/translations/monero-core_pl.ts \ # Polish +CONFIG(release, debug|release) { + DESTDIR = release + LANGUPD_OPTIONS = -locations relative -no-ui-lines + LANGREL_OPTIONS = -compress -nounfinished -removeidentical + +} else { + DESTDIR = debug + LANGUPD_OPTIONS = + LANGREL_OPTIONS = -markuntranslated "MISS_TR " +} -QMAKE_EXTRA_TARGETS += trans_update trans_release translate deploy +TARGET_FULL_PATH = $$OUT_PWD/$$DESTDIR -# updating transations only in release mode as this is requires to re-link project -# even if no changes were made. +macx { + TARGET_FULL_PATH = $$sprintf("%1/%2/%3.app", $$OUT_PWD, $$DESTDIR, $$TARGET) +} -#PRE_TARGETDEPS += translate +TRANSLATION_TARGET_DIR = $$TARGET_FULL_PATH/Contents/Resources/translations -CONFIG(release, debug|release) { - DESTDIR=release - PRE_TARGETDEPS += translate +isEmpty(QMAKE_LUPDATE) { + win32:LANGUPD = $$[QT_INSTALL_BINS]\lupdate.exe + else:LANGUPD = $$[QT_INSTALL_BINS]/lupdate } -CONFIG(debug, debug|release) { - DESTDIR=debug +isEmpty(QMAKE_LRELEASE) { + win32:LANGREL = $$[QT_INSTALL_BINS]\lrelease.exe + else:LANGREL = $$[QT_INSTALL_BINS]/lrelease } +langupd.command = \ + $$LANGUPD $$LANGUPD_OPTIONS $$shell_path($$_PRO_FILE) -ts $$_PRO_FILE_PWD/$$TRANSLATIONS + +langrel.depends = langupd +langrel.input = TRANSLATIONS +langrel.output = $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm +langrel.commands = \ + $$LANGREL $$LANGREL_OPTIONS ${QMAKE_FILE_IN} -qm $$TRANSLATION_TARGET_DIR/${QMAKE_FILE_BASE}.qm +langrel.CONFIG += no_link + +QMAKE_EXTRA_TARGETS += langupd deploy +QMAKE_EXTRA_COMPILERS += langrel +PRE_TARGETDEPS += langupd compiler_langrel_make_all RESOURCES += qml.qrc @@ -157,6 +162,14 @@ QML_IMPORT_PATH = # Default rules for deployment. include(deployment.pri) +macx { + deploy.commands += macdeployqt $$sprintf("%1/%2/%3.app", $$OUT_PWD, $$DESTDIR, $$TARGET) +} + +win32 { + deploy.commands += windeployqt $$sprintf("%1/%2/%3", $$OUT_PWD, $$DESTDIR, $$TARGET) +} + @@ -167,3 +180,4 @@ OTHER_FILES += \ DISTFILES += \ notes.txt + diff --git a/qml.qrc b/qml.qrc index 152ea8f2..eca9f561 100644 --- a/qml.qrc +++ b/qml.qrc @@ -114,11 +114,5 @@ pages/Receive.qml components/IconButton.qml lang/flags/italy.png - translations/monero-core_de.qm - translations/monero-core_en.qm - translations/monero-core_it.qm - translations/monero-core_pl.qm - translations/monero-core_ru.qm - translations/monero-core_zh.qm -- cgit v1.2.3