Skip to content
Permalink
Browse files

TranslationManager, Russian translation example

  • Loading branch information...
mbg033 committed Jul 19, 2016
1 parent de7bd2e commit a9339838ac295a4d045433c1b20fd5666fb35575
@@ -0,0 +1,63 @@
#include "TranslationManager.h"

#include <QApplication>
#include <QTranslator>
#include <QDir>
#include <QDebug>
#include <QFileInfo>


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 "";
}

@@ -0,0 +1,29 @@
#ifndef TRANSLATIONMANAGER_H
#define TRANSLATIONMANAGER_H

#include <QObject>

class QTranslator;
class TranslationManager : public QObject
{
Q_OBJECT
Q_PROPERTY(QString emptyString READ emptyString NOTIFY languageChanged)
public:
Q_INVOKABLE bool setLanguage(const QString &language);
static TranslationManager *instance();

QString emptyString();

signals:
void languageChanged();

private:
explicit TranslationManager(QObject *parent = 0);

private:
static TranslationManager * m_instance;
QTranslator * m_translator;

};

#endif // TRANSLATIONMANAGER_H
@@ -2,7 +2,7 @@


BITMONERO_URL=https://github.com/mbg033/bitmonero.git
BITMONERO_BRANCH=devel
BITMONERO_BRANCH=master
# thanks to SO: http://stackoverflow.com/a/20283965/4118915
CPU_CORE_COUNT=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
pushd $(pwd)
@@ -1,14 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<languages>
<language display_name="US English" locale="en_US" wallet_name="English" flag="/lang/flags/usa.png" qs="none"/>
<language display_name="UK English" locale="en_GB" wallet_name="English" flag="/lang/flags/uk.png" qs="none"/>
<language display_name="Russia" locale="ru_RU" wallet_name="English" flag="/lang/flags/russia.png" qs="none"/>
<language display_name="RPA" locale="TODO" wallet_name="English" flag="/lang/flags/rpa.png" qs="none"/>
<language display_name="Palestine" locale="TODO" wallet_name="English" flag="/lang/flags/palestine.png" qs="none"/>
<language display_name="India" locale="hi_IN" wallet_name="English" flag="/lang/flags/india.png" qs="none"/>
<language display_name="Italy" locale="it_IT" wallet_name="English" flag="/lang/flags/italy.png" qs="none"/>
<language display_name="German" locale="de_DE" wallet_name="English" flag="/lang/flags/german.png" qs="none"/>
<language display_name="China" locale="zh_CN" wallet_name="English" flag="/lang/flags/china.png" qs="none"/>
<language display_name="Brazil" locale="pt_BR" wallet_name="English" flag="/lang/flags/brazil.png" qs="none"/>
<language display_name="Bangladesh" locale="TODO" wallet_name="English" flag="/lang/flags/bangladesh.png" qs="none"/>

<!--
List of available languages for your wallet's seed:
0 : English
1 : Spanish
2 : German
3 : Italian
4 : Portuguese
5 : Russian
6 : Japanese
-->
<language display_name="US English" locale="en_US" wallet_language="English" flag="/lang/flags/usa.png" qs="none"/>
<language display_name="UK English" locale="en_GB" wallet_language="English" flag="/lang/flags/uk.png" qs="none"/>
<language display_name="Russia" locale="ru_RU" wallet_language="Russian" flag="/lang/flags/russia.png" qs="none"/>
<language display_name="RPA" locale="en_SA" wallet_language="English" flag="/lang/flags/rpa.png" qs="none"/>
<language display_name="Palestine" locale="ar_PS" wallet_language="English" flag="/lang/flags/palestine.png" qs="none"/>
<language display_name="India" locale="hi_IN" wallet_language="English" flag="/lang/flags/india.png" qs="none"/>
<language display_name="Italy" locale="it_IT" wallet_language="Italian" flag="/lang/flags/italy.png" qs="none"/>
<language display_name="German" locale="de_DE" wallet_language="German" flag="/lang/flags/german.png" qs="none"/>
<language display_name="China" locale="zh_CN" wallet_language="English" flag="/lang/flags/china.png" qs="none"/>
<language display_name="Brazil" locale="pt_BR" wallet_language="Portuguese" flag="/lang/flags/brazil.png" qs="none"/>
<language display_name="Bangladesh" locale="en_US" wallet_language="English" flag="/lang/flags/bangladesh.png" qs="none"/>
</languages>
@@ -37,6 +37,7 @@
#include "WalletManager.h"
#include "Wallet.h"
#include "PendingTransaction.h"
#include "TranslationManager.h"



@@ -53,10 +54,18 @@ int main(int argc, char *argv[])
app.installEventFilter(eventFilter);

qmlRegisterType<clipboardAdapter>("moneroComponents", 1, 0, "Clipboard");

qmlRegisterUncreatableType<Wallet>("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly");

qmlRegisterUncreatableType<PendingTransaction>("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction",
"PendingTransaction can't be instantiated directly");

qmlRegisterUncreatableType<WalletManager>("Bitmonero.WalletManager", 1, 0, "WalletManager",
"WalletManager can't be instantiated directly");

qmlRegisterUncreatableType<TranslationManager>("moneroComponents", 1, 0, "TranslationManager",
"TranslationManager can't be instantiated directly");

qRegisterMetaType<PendingTransaction::Priority>();


@@ -69,6 +78,8 @@ int main(int argc, char *argv[])

engine.rootContext()->setContextProperty("walletManager", WalletManager::instance());

engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance());

// export to QML monero accounts root directory
// wizard is talking about where
// to save the wallet file (.keys, .bin), they have to be user-accessible for
@@ -19,7 +19,8 @@ HEADERS += \
src/libwalletqt/PendingTransaction.h \
src/libwalletqt/TransactionHistory.h \
src/libwalletqt/TransactionInfo.h \
oshelper.h
oshelper.h \
TranslationManager.h


SOURCES += main.cpp \
@@ -31,7 +32,8 @@ SOURCES += main.cpp \
src/libwalletqt/PendingTransaction.cpp \
src/libwalletqt/TransactionHistory.cpp \
src/libwalletqt/TransactionInfo.cpp \
oshelper.cpp
oshelper.cpp \
TranslationManager.cpp

lupdate_only {
SOURCES = *.qml \
@@ -101,11 +103,11 @@ macx {

# 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
$$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



@@ -117,7 +119,7 @@ trans_update.depends = $$_PRO_FILE_
trans_release.commands = lrelease $$_PRO_FILE_
trans_release.depends = trans_update $$TRANSLATIONS

translate.commands = $(COPY) $$PWD/*.qm ${DESTDIR}
translate.commands = $(MKDIR) ${DESTDIR}/i18n && $(COPY) $$PWD/translations/*.qm ${DESTDIR}/i18n
translate.depends = trans_release

QMAKE_EXTRA_TARGETS += trans_update trans_release translate
@@ -666,12 +666,13 @@
<context>
<name>WizardWelcome</name>
<message>
<location filename="../wizard/WizardWelcome.qml" line="65"/>
<location filename="../wizard/WizardWelcome.qml" line="49"/>
<location filename="../wizard/WizardWelcome.qml" line="73"/>
<source>Welcome</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wizard/WizardWelcome.qml" line="76"/>
<location filename="../wizard/WizardWelcome.qml" line="86"/>
<source>Please choose a language and regional format.</source>
<translation type="unfinished"></translation>
</message>
@@ -666,12 +666,13 @@
<context>
<name>WizardWelcome</name>
<message>
<location filename="../wizard/WizardWelcome.qml" line="65"/>
<location filename="../wizard/WizardWelcome.qml" line="49"/>
<location filename="../wizard/WizardWelcome.qml" line="73"/>
<source>Welcome</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wizard/WizardWelcome.qml" line="76"/>
<location filename="../wizard/WizardWelcome.qml" line="86"/>
<source>Please choose a language and regional format.</source>
<translation type="unfinished"></translation>
</message>
@@ -666,12 +666,13 @@
<context>
<name>WizardWelcome</name>
<message>
<location filename="../wizard/WizardWelcome.qml" line="65"/>
<location filename="../wizard/WizardWelcome.qml" line="49"/>
<location filename="../wizard/WizardWelcome.qml" line="73"/>
<source>Welcome</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wizard/WizardWelcome.qml" line="76"/>
<location filename="../wizard/WizardWelcome.qml" line="86"/>
<source>Please choose a language and regional format.</source>
<translation type="unfinished"></translation>
</message>
@@ -666,12 +666,13 @@
<context>
<name>WizardWelcome</name>
<message>
<location filename="../wizard/WizardWelcome.qml" line="65"/>
<location filename="../wizard/WizardWelcome.qml" line="49"/>
<location filename="../wizard/WizardWelcome.qml" line="73"/>
<source>Welcome</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wizard/WizardWelcome.qml" line="76"/>
<location filename="../wizard/WizardWelcome.qml" line="86"/>
<source>Please choose a language and regional format.</source>
<translation type="unfinished"></translation>
</message>
@@ -6,7 +6,7 @@
<message>
<location filename="../pages/AddressBook.qml" line="47"/>
<source>Add new entry</source>
<translation type="unfinished"></translation>
<translation>Новая запись</translation>
</message>
<message>
<location filename="../pages/AddressBook.qml" line="56"/>
@@ -666,14 +666,15 @@
<context>
<name>WizardWelcome</name>
<message>
<location filename="../wizard/WizardWelcome.qml" line="65"/>
<location filename="../wizard/WizardWelcome.qml" line="49"/>
<location filename="../wizard/WizardWelcome.qml" line="73"/>
<source>Welcome</source>
<translation type="unfinished"></translation>
<translation>Добро пожаловать</translation>
</message>
<message>
<location filename="../wizard/WizardWelcome.qml" line="76"/>
<location filename="../wizard/WizardWelcome.qml" line="86"/>
<source>Please choose a language and regional format.</source>
<translation type="unfinished"></translation>
<translation>Пожалуйста выберите язык и региональный формат.</translation>
</message>
</context>
<context>
@@ -666,12 +666,13 @@
<context>
<name>WizardWelcome</name>
<message>
<location filename="../wizard/WizardWelcome.qml" line="65"/>
<location filename="../wizard/WizardWelcome.qml" line="49"/>
<location filename="../wizard/WizardWelcome.qml" line="73"/>
<source>Welcome</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../wizard/WizardWelcome.qml" line="76"/>
<location filename="../wizard/WizardWelcome.qml" line="86"/>
<source>Please choose a language and regional format.</source>
<translation type="unfinished"></translation>
</message>
Oops, something went wrong.

0 comments on commit a933983

Please sign in to comment.
You can’t perform that action at this time.