Browse Source

[COR] New traduction system

master
Ulrich Van Den Hekke 11 years ago
parent
commit
8084b9d6d5
  1. 4
      cmake_modules/UseXinx.cmake
  2. 118
      framework/translations/translationmanager.cpp
  3. 51
      framework/translations/translationmanager.h
  4. 41
      framework/translations/translationmanager_p.h
  5. 1
      plugins/core/coreplugin.qrc
  6. 5
      plugins/core/plugindefinition/coreplugin.cpp
  7. 5
      plugins/cvsplugin/cvsplugin.cpp
  8. 1
      plugins/cvsplugin/cvsplugin.qrc
  9. 5
      plugins/empty/empty.cpp
  10. 1
      plugins/empty/empty.qrc
  11. 1
      plugins/generix/generix.qrc
  12. 5
      plugins/generix/plugindefinition/generix.cpp
  13. 5
      plugins/services/servicesplugin.cpp
  14. 1
      plugins/services/servicesplugin.qrc
  15. 5
      plugins/svnplugin/svnplugin.cpp
  16. 1
      plugins/svnplugin/svnplugin.qrc
  17. 5
      plugins/svnpluginwrapper/svnpluginwrapper.cpp
  18. 3
      plugins/svnpluginwrapper/svnpluginwrapper.qrc
  19. 5
      plugins/xsd/xsdedit.cpp
  20. 5
      plugins/xslgui/xslgui.cpp
  21. 4
      xinx/application.qrc
  22. 25
      xinx/main.cpp

4
cmake_modules/UseXinx.cmake

@ -108,12 +108,14 @@ macro(initialisation_xinx)
file(GLOB_RECURSE winresources *.rc)
endif(WIN32)
set_source_files_properties(${translations} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/translations")
#set_source_files_properties(${translations} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/translations")
set_source_files_properties(${translations} PROPERTIES OUTPUT_LOCATION "${CMAKE_BINARY_DIR}/i18n")
qt4_wrap_ui(generated_forms ${forms})
xinx_automoc(moc_headers ${headers} OPTIONS ${MOC_FRAMEWORK})
qt4_add_resources(generated_resources ${resources})
#qt4_create_translation(translations_qm ${forms} ${headers} ${sources} ${translations})
qt4_add_translation(translations_qm ${translations})
endmacro(initialisation_xinx)

118
framework/translations/translationmanager.cpp

@ -0,0 +1,118 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "translationmanager_p.h"
#include <QDir>
#include <QApplication>
/* TranslationManagerPrivate */
QStringList TranslationManagerPrivate::findQmFiles()
{
QStringList result, filenames;
foreach(const QString & path, QDir::searchPaths(":translations"))
{
QDir dir(path);
QStringList localFileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
foreach(const QString fileName, localFileNames)
{
if (! filenames.contains(fileName))
{
filenames << fileName;
result << dir.filePath(fileName);
}
}
}
return result;
}
TranslationManager::Language TranslationManagerPrivate::languageName(const QString & qmFile)
{
QTranslator translator;
translator.load(qmFile);
TranslationManager::Language lang;
lang.code = qmFile.section("_", -1);
lang.name = translator.translate("TranslationManager", "C", "Translate this word in the name of your lang (ie: English, Français, ...)");
lang.image = translator.translate("TranslationManager", ":/images/unknown.png", "Give the image that contains the flag of your lang");
if (lang.name == "C")
{
lang.code = lang.name = lang.image = QString();
}
return lang;
}
/* TranslationManager */
TranslationManager::TranslationManager() : d(new TranslationManagerPrivate)
{
d->_lang = QLocale::system().name();
QStringList qmFiles = d->findQmFiles();
foreach(const QString & qmFile, qmFiles)
{
Language l = d->languageName(qmFile);
if (! l.code.isEmpty())
{
d->_languages.insert(l.code, l);
}
}
}
TranslationManager::~TranslationManager()
{
}
void TranslationManager::setLanguage(const QString& lang)
{
d->_lang = lang;
}
const QString& TranslationManager::language() const
{
return d->_lang;
}
void TranslationManager::apply()
{
foreach(QTranslator * translator, d->_translators)
{
qApp->removeTranslator(translator);
delete translator;
}
d->_translators.clear();
foreach(const QString & file, d->_files)
{
if (file.endsWith("_" + d->_lang + ".qm"))
{
QTranslator * translator = new QTranslator(qApp);
translator->load(file);
qApp->installTranslator(translator);
}
}
}

51
framework/translations/translationmanager.h

@ -0,0 +1,51 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSLATIONMANAGER_H
#define TRANSLATIONMANAGER_H
#include <core/xinxsingleton.h>
#include <QScopedPointer>
class TranslationManagerPrivate;
class TranslationManager : public XinxLibSingleton<TranslationManager>
{
Q_OBJECT
public:
struct Language
{
QString name;
QString code;
QString image;
};
virtual ~TranslationManager();
void setLanguage(const QString & lang);
const QString & language() const;
void apply();
private:
TranslationManager();
friend class XinxLibSingleton<TranslationManager>;
QScopedPointer<TranslationManagerPrivate> d;
};
#endif // TRANSLATIONMANAGER_H

41
framework/translations/translationmanager_p.h

@ -0,0 +1,41 @@
/*
XINX
Copyright (C) 2007-2011 by Ulrich Van Den Hekke
xinx@shadoware.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSLATIONMANAGER_P_H
#define TRANSLATIONMANAGER_P_H
#include "translationmanager.h"
#include <QStringList>
#include <QTranslator>
class TranslationManagerPrivate
{
public:
QHash<QString, TranslationManager::Language> _languages;
QString _lang;
QStringList _files;
QList<QTranslator*> _translators;
QStringList findQmFiles();
TranslationManager::Language languageName(const QString & qmFile);
};
#endif // TRANSLATIONMANAGER_P_H

1
plugins/core/coreplugin.qrc

@ -13,7 +13,6 @@
<file>images/typexsl.png</file>
<file>images/typexq.png</file>
<file>images/complete_fn.png</file>
<file>translations/coreplugin_fr.qm</file>
<file>images/run.png</file>
<file>images/xmlpres.png</file>
</qresource>

5
plugins/core/plugindefinition/coreplugin.cpp

@ -59,7 +59,6 @@
#include <QDir>
#include <QApplication>
#include <QTextEdit>
#include <QTranslator>
#include <QApplication>
#include <QAction>
@ -86,10 +85,6 @@ CorePlugin::~CorePlugin()
bool CorePlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/translations/coreplugin_%1").arg(lang));
qApp->installTranslator(tranlator);
m_resolver = new ManualFileResolver();
return true;

5
plugins/cvsplugin/cvsplugin.cpp

@ -26,7 +26,6 @@
#include <QString>
#include <QVariant>
#include <QSettings>
#include <QTranslator>
/* CVSPlugin */
@ -43,10 +42,6 @@ CVSPlugin::~CVSPlugin()
bool CVSPlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/translations/cvsplugin_%1").arg(lang));
qApp->installTranslator(tranlator);
Q_ASSERT(m_settings);
m_settings->load();

1
plugins/cvsplugin/cvsplugin.qrc

@ -2,6 +2,5 @@
<qresource prefix="/" >
<file>images/hi32-app-cervisia.png</file>
<file>images/hi64-app-cervisia.png</file>
<file>translations/cvsplugin_fr.qm</file>
</qresource>
</RCC>

5
plugins/empty/empty.cpp

@ -23,7 +23,6 @@
// Qt header
#include <QString>
#include <QVariant>
#include <QTranslator>
#include <QApplication>
#include <QPixmap>
@ -40,10 +39,6 @@ EmptyPlugin::~EmptyPlugin()
bool EmptyPlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/empty/translations/empty_%1").arg(lang));
qApp->installTranslator(tranlator);
return true;
}

1
plugins/empty/empty.qrc

@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/empty/" >
<file>images/empty.png</file>
<file>translations/empty_fr.qm</file>
</qresource>
</RCC>

1
plugins/generix/generix.qrc

@ -5,7 +5,6 @@
<file>images/logo_gce32.png</file>
<file>images/logo_gce64.png</file>
<file>images/dictionary.png</file>
<file>translations/dictionary_fr.qm</file>
<file>images/dictionary16.png</file>
<file>images/label.png</file>
<file>images/spain.png</file>

5
plugins/generix/plugindefinition/generix.cpp

@ -46,7 +46,6 @@
// Qt header
#include <QString>
#include <QVariant>
#include <QTranslator>
#include <QApplication>
#include <QDockWidget>
#include <QDir>
@ -98,10 +97,6 @@ GenerixPlugin::~GenerixPlugin()
bool GenerixPlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/generix/translations/dictionary_%1").arg(lang));
qApp->installTranslator(tranlator);
m_resolver = new Gce150FileResolver();
return true;

5
plugins/services/servicesplugin.cpp

@ -30,7 +30,6 @@
// Qt header
#include <QString>
#include <QVariant>
#include <QTranslator>
#include <QApplication>
class OpenWebServicesObjectStep : public IProjectInitialisationStep
@ -75,10 +74,6 @@ ServicesPlugin::~ServicesPlugin()
bool ServicesPlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/services/translations/servicesplugin_%1").arg(lang));
qApp->installTranslator(tranlator);
return true;
}

1
plugins/services/servicesplugin.qrc

@ -5,6 +5,5 @@
<file>images/action.png</file>
<file>images/services.png</file>
<file>images/serviceparam.png</file>
<file>translations/servicesplugin_fr.qm</file>
</qresource>
</RCC>

5
plugins/svnplugin/svnplugin.cpp

@ -24,7 +24,6 @@
// Qt header
#include <QString>
#include <QVariant>
#include <QTranslator>
#include <QApplication>
#include <QPixmap>
@ -37,10 +36,6 @@ SVNPlugin::SVNPlugin()
bool SVNPlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/translations/svnplugin_%1").arg(lang));
qApp->installTranslator(tranlator);
return true;
}

1
plugins/svnplugin/svnplugin.qrc

@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/" >
<file>images/repos_svn.png</file>
<file>translations/svnplugin_fr.qm</file>
</qresource>
</RCC>

5
plugins/svnpluginwrapper/svnpluginwrapper.cpp

@ -25,7 +25,6 @@
// Qt header
#include <QString>
#include <QVariant>
#include <QTranslator>
#include <QApplication>
#include <QPixmap>
@ -38,10 +37,6 @@ SVNPluginWrapper::SVNPluginWrapper()
bool SVNPluginWrapper::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/translations/svnpluginwrapper_%1").arg(lang));
qApp->installTranslator(tranlator);
return true;
}

3
plugins/svnpluginwrapper/svnpluginwrapper.qrc

@ -1,6 +1,5 @@
<RCC>
<RCC>
<qresource prefix="/" >
<file>images/svnwrapper.png</file>
<file>translations/svnpluginwrapper_fr.qm</file>
</qresource>
</RCC>

5
plugins/xsd/xsdedit.cpp

@ -24,7 +24,6 @@
// Qt header
#include <QString>
#include <QVariant>
#include <QTranslator>
#include <QApplication>
/* XSLStyleSheetFileType */
@ -88,10 +87,6 @@ XsdEditPlugin::~XsdEditPlugin()
bool XsdEditPlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/xsd/translations/xsdedit_%1").arg(lang));
qApp->installTranslator(tranlator);
return true;
}

5
plugins/xslgui/xslgui.cpp

@ -24,7 +24,6 @@
// Qt header
#include <QString>
#include <QVariant>
#include <QTranslator>
#include <QApplication>
/* XSLStyleSheetFileType */
@ -89,10 +88,6 @@ XslGuiPlugin::~XslGuiPlugin()
bool XslGuiPlugin::initializePlugin(const QString & lang)
{
QTranslator * tranlator = new QTranslator(this);
tranlator->load(QString(":/xslgui/translations/xslgui_%1").arg(lang));
qApp->installTranslator(tranlator);
return true;
}

4
xinx/application.qrc

@ -3,12 +3,8 @@
<file alias="licence.html">../licence.html</file>
</qresource>
<qresource prefix="/">
<file alias="translations/xinxcomponents_fr.qm">../components/translations/xinxcomponents_fr.qm</file>
<file alias="translations/libxinx_fr.qm">../framework/translations/libxinx_fr.qm</file>
<file alias="qcodeedit/marks.qxm">../framework/editors/marks.qxm</file>
<file alias="qcodeedit/lan/none.qnfa">../framework/editors/none.qnfa</file>
<file>translations/qt_fr.qm</file>
<file>translations/xinx_fr.qm</file>
<file>images/error16.png</file>
<file>images/france.png</file>
<file>images/usa.png</file>

25
xinx/main.cpp

@ -30,6 +30,7 @@
#include <session/sessionmanager.h>
#include <project/xinxprojectmanager.h>
#include <core/version.h>
#include <translations/translationmanager.h>
// QCodeEdit header
#include <qlinemarksinfocenter.h>
@ -41,7 +42,6 @@
#include <QFile>
#include <QMessageBox>
#include <QLocale>
#include <QTranslator>
#include <QDir>
#include <QThread>
#include <QBitmap>
@ -62,6 +62,7 @@ static void initSearchPath(QApplication * app)
{
const QString configDirectory = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
const QString homeDirectory = QDir::home().absoluteFilePath(configDirectory);
const QString i18nDirectory = QDir(homeDirectory).absoluteFilePath("i18n");
const QString datasDirectory = QDir(homeDirectory).absoluteFilePath("datas");
const QString scriptDirectory = QDir(homeDirectory).absoluteFilePath("scripts");
const QString pluginsDirectory = QDir(homeDirectory).absoluteFilePath("plugins");
@ -72,6 +73,14 @@ static void initSearchPath(QApplication * app)
QDir::home().mkpath(pluginsDirectory);
QDir::home().mkpath(templatesDirectory);
// .. for i18n ...
QDir::addSearchPath("translations", i18nDirectory);
QDir::addSearchPath("translations", QDir(QApplication::applicationDirPath()).absoluteFilePath("../i18n"));
#ifndef Q_WS_WIN
QDir::addSearchPath("translations", QDir(QApplication::applicationDirPath()).absoluteFilePath("../share/xinx/i18n"));
QDir::addSearchPath("translations", QDir(QApplication::applicationDirPath()).absoluteFilePath("../lib/xinx/i18n"));
#endif // Q_WS_WIN
// .. for datas ...
QDir::addSearchPath("datas", datasDirectory);
QDir::addSearchPath("datas", QDir(QApplication::applicationDirPath()).absoluteFilePath("../datas"));
@ -226,18 +235,8 @@ int main(int argc, char *argv[])
app.processEvents();
// ... load qt translation ...
QTranslator translator_xinx, translator_qt, translator_libxinx, tranlator_components;
translator_qt.load(QString(":/translations/qt_%1").arg(XINXConfig::self()->config().language));
app.installTranslator(&translator_qt);
// ... load xinx translation ...
translator_xinx.load(QString(":/translations/xinx_%1").arg(XINXConfig::self()->config().language));
app.installTranslator(&translator_xinx);
// ... load xinx library translation ...
translator_libxinx.load(QString(":/translations/libxinx_%1").arg(XINXConfig::self()->config().language));
app.installTranslator(&translator_libxinx);
// ... load components translations
tranlator_components.load(QString(":/translations/xinxcomponents_%1").arg(XINXConfig::self()->config().language));
app.installTranslator(&tranlator_components);
TranslationManager::self()->setLanguage(XINXConfig::self()->config().language);
TranslationManager::self()->apply();
bool recovering = false;
if (XinxSession::Session::sessionsNames().contains(RECOVER_SESSION))

Loading…
Cancel
Save