Rework translation
This commit is contained in:
parent
37f5715e87
commit
d328314a74
@ -47,8 +47,8 @@ FORMS += mainwindow.ui \
|
|||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
minetestmappergui.qrc
|
minetestmappergui.qrc
|
||||||
|
|
||||||
TRANSLATIONS = languages/gui_de.ts\
|
TRANSLATIONS = translations/gui_de.ts\
|
||||||
languages/gui_en.ts
|
translations/gui_en.ts
|
||||||
|
|
||||||
|
|
||||||
GIT_VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags)
|
GIT_VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags)
|
||||||
|
25
main.cpp
25
main.cpp
@ -3,6 +3,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
#include <QLibraryInfo>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -12,6 +13,28 @@ int main(int argc, char *argv[])
|
|||||||
a.setApplicationVersion(GIT_VERSION);
|
a.setApplicationVersion(GIT_VERSION);
|
||||||
a.setOrganizationName("MinetestMapperGui");
|
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;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("This program provides a graphical user interface for minetestmapper. \n"
|
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.");
|
"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);
|
bool portable = parser.isSet(startPortableOption);
|
||||||
|
|
||||||
MainWindow w(portable);
|
MainWindow w(portable, translationsPath, &translator, &qtTranslator);
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
@ -35,9 +35,12 @@ InitStatics::InitStatics(void)
|
|||||||
geometrySizeModeNumeric[geometrySizeModeSymbolic[i]] = i;
|
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),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow),
|
||||||
|
translator(translator),
|
||||||
|
qtTranslator(qtTranslator),
|
||||||
|
translationsPath(translationsPath)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
if (!migrateSettingsProfiles())
|
if (!migrateSettingsProfiles())
|
||||||
@ -186,23 +189,22 @@ void MainWindow::createLanguageMenu(void)
|
|||||||
|
|
||||||
// format systems language
|
// format systems language
|
||||||
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
|
QString defaultLocale = QLocale::system().name(); // e.g. "de_DE"
|
||||||
|
qDebug()<<"Default locale:"<<defaultLocale;
|
||||||
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
|
defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de"
|
||||||
|
|
||||||
m_langPath = QApplication::applicationDirPath();
|
qDebug()<<"Lang path "<< translationsPath;
|
||||||
m_langPath.append("/languages");
|
QDir dir(translationsPath);
|
||||||
qDebug()<<"Lang path "<< m_langPath;
|
QStringList fileNames = dir.entryList(QStringList("qt_*.qm"));
|
||||||
QDir dir(m_langPath);
|
|
||||||
QStringList fileNames = dir.entryList(QStringList("gui_*.qm"));
|
|
||||||
|
|
||||||
for (int i = 0; i < fileNames.size(); ++i) {
|
for (int i = 0; i < fileNames.size(); ++i) {
|
||||||
// get locale extracted by filename
|
// get locale extracted by filename
|
||||||
QString locale;
|
QString locale;
|
||||||
locale = fileNames[i]; // "gui_de.qm"
|
locale = fileNames[i]; // "qt_de.qm"
|
||||||
locale.truncate(locale.lastIndexOf('.')); // "gui_de"
|
locale.truncate(locale.lastIndexOf('.')); // "qt_de"
|
||||||
locale.remove(0, locale.indexOf('_') + 1); // "de"
|
locale.remove(0, locale.indexOf('_') + 1); // "de"
|
||||||
|
|
||||||
QString lang = QLocale::languageToString(QLocale(locale).language());
|
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);
|
QAction *action = new QAction(ico, lang, this);
|
||||||
action->setCheckable(true);
|
action->setCheckable(true);
|
||||||
@ -215,7 +217,7 @@ void MainWindow::createLanguageMenu(void)
|
|||||||
if (defaultLocale == locale)
|
if (defaultLocale == locale)
|
||||||
{
|
{
|
||||||
action->setChecked(true);
|
action->setChecked(true);
|
||||||
loadLanguage(locale);
|
//loadLanguage(locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,21 +228,20 @@ void MainWindow::slotLanguageChanged(QAction* action)
|
|||||||
if(0 != action) {
|
if(0 != action) {
|
||||||
// load the language dependant on the action content
|
// load the language dependant on the action content
|
||||||
loadLanguage(action->data().toString());
|
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
|
// remove the old translator
|
||||||
qApp->removeTranslator(&translator);
|
qApp->removeTranslator(translator);
|
||||||
QString m_langPath = QApplication::applicationDirPath();
|
qDebug() << "Trying to load language "<< translationsPath << prefix<<locale;
|
||||||
m_langPath.append("/languages/");
|
|
||||||
qDebug()<<"Trying to load language "<< m_langPath+filename;
|
|
||||||
qDebug()<<translator.load(m_langPath+filename);
|
|
||||||
// load the new translator
|
// load the new translator
|
||||||
if(translator.load(m_langPath+filename))
|
if(translator->load(locale , "", prefix, translationsPath)){
|
||||||
qApp->installTranslator(&translator);
|
qDebug() << "Loaded translator" << locale;
|
||||||
|
qApp->installTranslator(translator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadLanguage(const QString& rLanguage)
|
void MainWindow::loadLanguage(const QString& rLanguage)
|
||||||
@ -250,8 +251,8 @@ void MainWindow::loadLanguage(const QString& rLanguage)
|
|||||||
QLocale locale = QLocale(m_currLang);
|
QLocale locale = QLocale(m_currLang);
|
||||||
QLocale::setDefault(locale);
|
QLocale::setDefault(locale);
|
||||||
QString languageName = QLocale::languageToString(locale.language());
|
QString languageName = QLocale::languageToString(locale.language());
|
||||||
switchTranslator(m_translator, QString("gui_%1.qm").arg(rLanguage));
|
switchTranslator(translator, "gui_", locale);
|
||||||
switchTranslator(m_translatorQt, QString("qtbase_%1.qm").arg(rLanguage));
|
switchTranslator(qtTranslator, "qt_", locale);
|
||||||
ui->statusBar->showMessage(tr("Current Language changed to %1").arg(languageName),3000);
|
ui->statusBar->showMessage(tr("Current Language changed to %1").arg(languageName),3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
mainwindow.h
11
mainwindow.h
@ -38,7 +38,7 @@ class MainWindow : public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(bool portable, QWidget *parent = 0);
|
explicit MainWindow(bool portable, const QString &translationsPath, QTranslator *translator, QTranslator *qtTranslator, QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -116,6 +116,8 @@ private slots:
|
|||||||
|
|
||||||
void on_figureSelect_currentIndexChanged(int index);
|
void on_figureSelect_currentIndexChanged(int index);
|
||||||
|
|
||||||
|
void switchTranslator(QTranslator *translator, const QString &prefix, const QLocale &locale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool portable;
|
bool portable;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
@ -136,10 +138,10 @@ private:
|
|||||||
// creates the language menu dynamically from the content of m_langPath
|
// creates the language menu dynamically from the content of m_langPath
|
||||||
void createLanguageMenu(void);
|
void createLanguageMenu(void);
|
||||||
|
|
||||||
QTranslator m_translator; // contains the translations for this application
|
QTranslator *translator; // contains the translations for this application
|
||||||
QTranslator m_translatorQt; // contains the translations for qt
|
QTranslator *qtTranslator; // contains the translations for qt
|
||||||
QString m_currLang; // contains the currently loaded language
|
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 currentProfile; //contains the name of current loaded profile
|
||||||
QString pathAppData; // Path where the settings should be stored.
|
QString pathAppData; // Path where the settings should be stored.
|
||||||
QString pathProfiles; // path where the profiles should be stored.
|
QString pathProfiles; // path where the profiles should be stored.
|
||||||
@ -152,6 +154,7 @@ private:
|
|||||||
QDataWidgetMapper *drawMapFigureTableMapper;
|
QDataWidgetMapper *drawMapFigureTableMapper;
|
||||||
MinetestMapperExe *minetestMapper;
|
MinetestMapperExe *minetestMapper;
|
||||||
QStringListModel *backends = new QStringListModel();
|
QStringListModel *backends = new QStringListModel();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -204,8 +204,8 @@ void MakeColors::run(void)
|
|||||||
parseNodesTxt(fileNodesTxt);
|
parseNodesTxt(fileNodesTxt);
|
||||||
emit maxProgressChanged(requiredColors.size());
|
emit maxProgressChanged(requiredColors.size());
|
||||||
emit progressChanged(0);
|
emit progressChanged(0);
|
||||||
output(QString("Found %1 nodes").arg(nodeList.size()), INFO);
|
output(tr("Found %Ln node(s)","",nodeList.size()), INFO);
|
||||||
output(QString("Searching and parsing %1 texture files").arg(requiredColors.size()), INFO);
|
output(tr("Searching and parsing %Ln texture file(s)","",requiredColors.size()), INFO);
|
||||||
for(int i = 0; i < textureSearchDirectorys.size(); i++)
|
for(int i = 0; i < textureSearchDirectorys.size(); i++)
|
||||||
{
|
{
|
||||||
//emit stateChanged("search and process textures "+ i +" of "+textureSearchDirectorys.size());
|
//emit stateChanged("search and process textures "+ i +" of "+textureSearchDirectorys.size());
|
||||||
|
Before Width: | Height: | Size: 891 B After Width: | Height: | Size: 891 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@ -1570,6 +1570,25 @@ Möchten Sie die Einstellungen jetzt öffnen? </translation>
|
|||||||
<translation>Name des Neuen Profils:</translation>
|
<translation>Name des Neuen Profils:</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</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>
|
<context>
|
||||||
<name>MinetestMapperExe</name>
|
<name>MinetestMapperExe</name>
|
||||||
<message>
|
<message>
|
@ -1492,6 +1492,25 @@ Do you want to cancel or proceed with default colors.txt file?</source>
|
|||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</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>
|
<context>
|
||||||
<name>MinetestMapperExe</name>
|
<name>MinetestMapperExe</name>
|
||||||
<message>
|
<message>
|
Loading…
x
Reference in New Issue
Block a user