Rework translation

master
Unknown 2017-03-03 07:02:15 +01:00
parent 37f5715e87
commit d328314a74
9 changed files with 96 additions and 31 deletions

View File

@ -47,8 +47,8 @@ FORMS += mainwindow.ui \
RESOURCES += \
minetestmappergui.qrc
TRANSLATIONS = languages/gui_de.ts\
languages/gui_en.ts
TRANSLATIONS = translations/gui_de.ts\
translations/gui_en.ts
GIT_VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags)

View File

@ -3,6 +3,7 @@
#include <QApplication>
#include <QDebug>
#include <QCommandLineParser>
#include <QLibraryInfo>
int main(int argc, char *argv[])
{
@ -12,6 +13,28 @@ int main(int argc, char *argv[])
a.setApplicationVersion(GIT_VERSION);
a.setOrganizationName("MinetestMapperGui");
// Setup the translators
const QString translationsPath = "./translations/";
QTranslator qtTranslator;
if(qtTranslator.load("qt_" + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
a.installTranslator(&qtTranslator);
qDebug()<< QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
else{
qtTranslator.load("qt_" + QLocale::system().name(),
translationsPath);
a.installTranslator(&qtTranslator);
}
QTranslator translator;
if (translator.load("gui_" + QLocale::system().name(), translationsPath))
a.installTranslator(&translator);
// Init commandline parser
QCommandLineParser parser;
parser.setApplicationDescription("This program provides a graphical user interface for minetestmapper. \n"
"If you are looking for the command line interface of minetesmapper please execute minetestmapper directly.");
@ -25,7 +48,7 @@ int main(int argc, char *argv[])
bool portable = parser.isSet(startPortableOption);
MainWindow w(portable);
MainWindow w(portable, translationsPath, &translator, &qtTranslator);
w.show();
return a.exec();

View File

@ -35,9 +35,12 @@ InitStatics::InitStatics(void)
geometrySizeModeNumeric[geometrySizeModeSymbolic[i]] = i;
}
MainWindow::MainWindow(bool portable, QWidget *parent) :
MainWindow::MainWindow(bool portable, const QString &translationsPath, QTranslator *translator, QTranslator *qtTranslator, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui(new Ui::MainWindow),
translator(translator),
qtTranslator(qtTranslator),
translationsPath(translationsPath)
{
#ifndef Q_OS_WIN
if (!migrateSettingsProfiles())
@ -186,23 +189,22 @@ void MainWindow::createLanguageMenu(void)
// format systems language
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
qDebug()<<"Default locale:"<<defaultLocale;
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
m_langPath = QApplication::applicationDirPath();
m_langPath.append("/languages");
qDebug()<<"Lang path "<< m_langPath;
QDir dir(m_langPath);
QStringList fileNames = dir.entryList(QStringList("gui_*.qm"));
qDebug()<<"Lang path "<< translationsPath;
QDir dir(translationsPath);
QStringList fileNames = dir.entryList(QStringList("qt_*.qm"));
for (int i = 0; i < fileNames.size(); ++i) {
// get locale extracted by filename
QString locale;
locale = fileNames[i]; // "gui_de.qm"
locale.truncate(locale.lastIndexOf('.')); // "gui_de"
locale = fileNames[i]; // "qt_de.qm"
locale.truncate(locale.lastIndexOf('.')); // "qt_de"
locale.remove(0, locale.indexOf('_') + 1); // "de"
QString lang = QLocale::languageToString(QLocale(locale).language());
QIcon ico(QString("%1/%2.png").arg(m_langPath).arg(locale));
QIcon ico(QString("%1/%2.png").arg(translationsPath).arg(locale));
QAction *action = new QAction(ico, lang, this);
action->setCheckable(true);
@ -215,7 +217,7 @@ void MainWindow::createLanguageMenu(void)
if (defaultLocale == locale)
{
action->setChecked(true);
loadLanguage(locale);
//loadLanguage(locale);
}
}
}
@ -226,21 +228,20 @@ void MainWindow::slotLanguageChanged(QAction* action)
if(0 != action) {
// load the language dependant on the action content
loadLanguage(action->data().toString());
ui->menuLanguage->setIcon(action->icon());
}
}
void switchTranslator(QTranslator& translator, const QString& filename)
void MainWindow::switchTranslator(QTranslator *translator, const QString &prefix, const QLocale &locale)
{
// remove the old translator
qApp->removeTranslator(&translator);
QString m_langPath = QApplication::applicationDirPath();
m_langPath.append("/languages/");
qDebug()<<"Trying to load language "<< m_langPath+filename;
qDebug()<<translator.load(m_langPath+filename);
qApp->removeTranslator(translator);
qDebug() << "Trying to load language "<< translationsPath << prefix<<locale;
// load the new translator
if(translator.load(m_langPath+filename))
qApp->installTranslator(&translator);
if(translator->load(locale , "", prefix, translationsPath)){
qDebug() << "Loaded translator" << locale;
qApp->installTranslator(translator);
}
}
void MainWindow::loadLanguage(const QString& rLanguage)
@ -250,8 +251,8 @@ void MainWindow::loadLanguage(const QString& rLanguage)
QLocale locale = QLocale(m_currLang);
QLocale::setDefault(locale);
QString languageName = QLocale::languageToString(locale.language());
switchTranslator(m_translator, QString("gui_%1.qm").arg(rLanguage));
switchTranslator(m_translatorQt, QString("qtbase_%1.qm").arg(rLanguage));
switchTranslator(translator, "gui_", locale);
switchTranslator(qtTranslator, "qt_", locale);
ui->statusBar->showMessage(tr("Current Language changed to %1").arg(languageName),3000);
}
}

View File

@ -38,7 +38,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
explicit MainWindow(bool portable, QWidget *parent = 0);
explicit MainWindow(bool portable, const QString &translationsPath, QTranslator *translator, QTranslator *qtTranslator, QWidget *parent = 0);
~MainWindow();
public slots:
@ -116,6 +116,8 @@ private slots:
void on_figureSelect_currentIndexChanged(int index);
void switchTranslator(QTranslator *translator, const QString &prefix, const QLocale &locale);
private:
bool portable;
Ui::MainWindow *ui;
@ -136,10 +138,10 @@ private:
// creates the language menu dynamically from the content of m_langPath
void createLanguageMenu(void);
QTranslator m_translator; // contains the translations for this application
QTranslator m_translatorQt; // contains the translations for qt
QTranslator *translator; // contains the translations for this application
QTranslator *qtTranslator; // contains the translations for qt
QString m_currLang; // contains the currently loaded language
QString m_langPath; // Path of language files. This is always fixed to /languages.
QString translationsPath; // Path of language files. This is always fixed to /languages.
QString currentProfile; //contains the name of current loaded profile
QString pathAppData; // Path where the settings should be stored.
QString pathProfiles; // path where the profiles should be stored.
@ -152,6 +154,7 @@ private:
QDataWidgetMapper *drawMapFigureTableMapper;
MinetestMapperExe *minetestMapper;
QStringListModel *backends = new QStringListModel();
};
#endif // MAINWINDOW_H

View File

@ -204,8 +204,8 @@ void MakeColors::run(void)
parseNodesTxt(fileNodesTxt);
emit maxProgressChanged(requiredColors.size());
emit progressChanged(0);
output(QString("Found %1 nodes").arg(nodeList.size()), INFO);
output(QString("Searching and parsing %1 texture files").arg(requiredColors.size()), INFO);
output(tr("Found %Ln node(s)","",nodeList.size()), INFO);
output(tr("Searching and parsing %Ln texture file(s)","",requiredColors.size()), INFO);
for(int i = 0; i < textureSearchDirectorys.size(); i++)
{
//emit stateChanged("search and process textures "+ i +" of "+textureSearchDirectorys.size());

View File

Before

Width:  |  Height:  |  Size: 891 B

After

Width:  |  Height:  |  Size: 891 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1570,6 +1570,25 @@ Möchten Sie die Einstellungen jetzt öffnen? </translation>
<translation>Name des Neuen Profils:</translation>
</message>
</context>
<context>
<name>MakeColors</name>
<message numerus="yes">
<location filename="../makecolors.cpp" line="207"/>
<source>Found %Ln node(s)</source>
<translation>
<numerusform>%Ln Node gefunden</numerusform>
<numerusform>%Ln Nodes gefunden</numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="../makecolors.cpp" line="208"/>
<source>Searching and parsing %Ln texture file(s)</source>
<translation>
<numerusform>Suche und verarbeite %n Textur</numerusform>
<numerusform>Suche und verarbeite %n Texturen</numerusform>
</translation>
</message>
</context>
<context>
<name>MinetestMapperExe</name>
<message>

View File

@ -1492,6 +1492,25 @@ Do you want to cancel or proceed with default colors.txt file?</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MakeColors</name>
<message numerus="yes">
<location filename="../makecolors.cpp" line="207"/>
<source>Found %Ln node(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="../makecolors.cpp" line="208"/>
<source>Searching and parsing %Ln texture file(s)</source>
<translation type="unfinished">
<numerusform></numerusform>
<numerusform></numerusform>
</translation>
</message>
</context>
<context>
<name>MinetestMapperExe</name>
<message>