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

Out-of-project fix for error messages loading

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