Commit 4cb45b2b authored by Victor Yacovlev's avatar Victor Yacovlev

Out-of-project fix for error messages loading

parent 77652f25
#include "errormessages.h" #include "errormessages.h"
#include <kumir2-libs/extensionsystem/pluginmanager.h> #include <kumir2-libs/extensionsystem/pluginmanager.h>
#include <kumir2-libs/extensionsystem/kplugin.h>
#include <QtCore> #include <QtCore>
...@@ -44,10 +45,12 @@ QStringList ErrorMessages::readCSVRow(const QString &line) ...@@ -44,10 +45,12 @@ QStringList ErrorMessages::readCSVRow(const QString &line)
return result; return result;
} }
bool ErrorMessages::loadMessages(const QString &plugin) bool ErrorMessages::loadMessages(const QByteArray &pluginName)
{ {
const QString fileName = ExtensionSystem::PluginManager::instance()->sharePath() + ExtensionSystem::KPlugin* kPlugin = ExtensionSystem::PluginManager::instance()->loadedPlugin(pluginName);
+ "/" + plugin.toLower() + "/messages.csv"; const QString fileName = kPlugin->myResourcesDir().absoluteFilePath("messages.csv");
// const QString fileName = ExtensionSystem::PluginManager::instance()->sharePath() +
// + "/" + pluginName.toLower() + "/messages.csv";
QFile f(fileName); QFile f(fileName);
if (f.open(QIODevice::ReadOnly|QIODevice::Text)) { if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
...@@ -58,7 +61,7 @@ bool ErrorMessages::loadMessages(const QString &plugin) ...@@ -58,7 +61,7 @@ bool ErrorMessages::loadMessages(const QString &plugin)
QList<Context> contexts; QList<Context> contexts;
for (int i=0; i<languages.size(); i++) { for (int i=0; i<languages.size(); i++) {
QLocale loc(languages[i]); QLocale loc(languages[i]);
contexts << Context(plugin,loc.language()); contexts << Context(pluginName,loc.language());
} }
if (contexts.isEmpty()) { if (contexts.isEmpty()) {
qWarning() << fileName+": file data is empty or not valid CSV-file"; qWarning() << fileName+": file data is empty or not valid CSV-file";
...@@ -88,11 +91,11 @@ bool ErrorMessages::loadMessages(const QString &plugin) ...@@ -88,11 +91,11 @@ bool ErrorMessages::loadMessages(const QString &plugin)
return true; return true;
} }
QString ErrorMessages::message(const QString &plugin QString ErrorMessages::message(const QByteArray &pluginName
, const QLocale::Language &language , const QLocale::Language &language
, const QString &key) , const QString &key)
{ {
Context context(plugin, language); Context context(pluginName, language);
static QRegExp arg1("\\\\1=\\{(\\S*)\\}"); static QRegExp arg1("\\\\1=\\{(\\S*)\\}");
arg1.setMinimal(true); arg1.setMinimal(true);
static QRegExp arg2("\\\\2=\\{(\\S*)\\}"); static QRegExp arg2("\\\\2=\\{(\\S*)\\}");
......
...@@ -42,14 +42,14 @@ inline QString _(const char * x, const QString &a, const QString &b, const QStri ...@@ -42,14 +42,14 @@ inline QString _(const char * x, const QString &a, const QString &b, const QStri
class EM_EXPORT ErrorMessages { class EM_EXPORT ErrorMessages {
public: public:
static bool loadMessages(const QString &plugin); static bool loadMessages(const QByteArray &pluginName);
static QString message(const QString &plugin static QString message(const QByteArray &pluginName
, const QLocale::Language &language , const QLocale::Language &language
, const QString &key); , const QString &key);
private: private:
static QStringList readCSVRow(const QString &line); static QStringList readCSVRow(const QString &line);
typedef QPair<QString,QLocale::Language> Context; typedef QPair<QByteArray,QLocale::Language> Context;
typedef QHash<QString,QString> Database; typedef QHash<QString,QString> Database;
static QMap<Context, Database> database; static QMap<Context, Database> database;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment