Added support for grid columns translations. Translated columns in
addressbook plugin.
This commit is contained in:
@@ -24,5 +24,19 @@
|
|||||||
\"addressZipCode\" TEXT NULL);"
|
\"addressZipCode\" TEXT NULL);"
|
||||||
|
|
||||||
],
|
],
|
||||||
"dependencies" : []
|
"dependencies" : [],
|
||||||
|
"translations" : {
|
||||||
|
"CZ" : {
|
||||||
|
"title" : "Titul",
|
||||||
|
"firstName" : "Jméno",
|
||||||
|
"lastName" : "Příjmení",
|
||||||
|
"birthDate" : "Datum narození",
|
||||||
|
"idCardNumber" : "Číslo dokladu",
|
||||||
|
"ztp" : "ZTP",
|
||||||
|
"addressCity" : "Město",
|
||||||
|
"addressStreet" : "Ulice",
|
||||||
|
"addressHouseNumber" : "Číslo popisné",
|
||||||
|
"addressZipCode" : "PSČ"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-1
@@ -109,7 +109,12 @@ public:
|
|||||||
if (i == section) {
|
if (i == section) {
|
||||||
QString colName(entity->metaObject()->property(i + 1).name());
|
QString colName(entity->metaObject()->property(i + 1).name());
|
||||||
delete entity;
|
delete entity;
|
||||||
return tr(colName.toStdString().c_str());
|
|
||||||
|
if (m_translations.contains(colName))
|
||||||
|
{
|
||||||
|
return m_translations[colName];
|
||||||
|
}
|
||||||
|
return colName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +184,11 @@ public:
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTranslations(const QMap<QString, QString> &translations)
|
||||||
|
{
|
||||||
|
m_translations = translations;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void handleFilter(const QString &filter) override
|
void handleFilter(const QString &filter) override
|
||||||
{
|
{
|
||||||
@@ -210,6 +220,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QList<QSharedPointer<T> > m_list;
|
QList<QSharedPointer<T> > m_list;
|
||||||
QList<QSharedPointer<T> > m_fullList;
|
QList<QSharedPointer<T> > m_fullList;
|
||||||
|
QMap<QString, QString> m_translations;
|
||||||
bool filtered;
|
bool filtered;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ public:
|
|||||||
m_formHandler = handler;
|
m_formHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void setTranslations(const QMap<QString, QString> &translations) {
|
||||||
|
m_tableModel->setTranslations(translations);
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool fillData() {
|
bool fillData() {
|
||||||
if (m_tableModel == NULL) {
|
if (m_tableModel == NULL) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public:
|
|||||||
void setPluginId(const QString &pluginId);
|
void setPluginId(const QString &pluginId);
|
||||||
QString pluginId();
|
QString pluginId();
|
||||||
QTableView *tableView();
|
QTableView *tableView();
|
||||||
|
virtual void setTranslations(const QMap<QString, QString> &translations) = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataChanged();
|
void dataChanged();
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ void IMetaDataPlugin::init(const QJsonObject &metaData)
|
|||||||
if (IGridForm *pluginUi = dynamic_cast<IGridForm*>(m_ui))
|
if (IGridForm *pluginUi = dynamic_cast<IGridForm*>(m_ui))
|
||||||
{
|
{
|
||||||
pluginUi->setPluginId(pluginId());
|
pluginUi->setPluginId(pluginId());
|
||||||
|
pluginUi->setTranslations(m_translations);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_service != NULL)
|
if (m_service != NULL)
|
||||||
@@ -87,6 +88,23 @@ void IMetaDataPlugin::parseMetaData(const QJsonObject &metaData)
|
|||||||
foreach (QJsonValue depVal, data.toObject()["dependecies"].toArray()) {
|
foreach (QJsonValue depVal, data.toObject()["dependecies"].toArray()) {
|
||||||
m_dependsOn.append(depVal.toString());
|
m_dependsOn.append(depVal.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonValue trVal = data.toObject()["translations"];
|
||||||
|
QString locale = QLocale::system().name();
|
||||||
|
QJsonValue trLocalized;
|
||||||
|
foreach (QString key, trVal.toObject().keys()) {
|
||||||
|
if (locale.contains(key, Qt::CaseInsensitive)) {
|
||||||
|
trLocalized = trVal.toObject()[key];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!trLocalized.isNull())
|
||||||
|
{
|
||||||
|
foreach (QString key, trLocalized.toObject().keys()) {
|
||||||
|
m_translations[key] = trLocalized.toObject()[key].toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString IMetaDataPlugin::parseLocaleText(const QJsonObject &object)
|
QString IMetaDataPlugin::parseLocaleText(const QJsonObject &object)
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public:
|
|||||||
|
|
||||||
virtual QTranslator* translator() { return NULL; }
|
virtual QTranslator* translator() { return NULL; }
|
||||||
virtual QIcon pluginIcon() { return QIcon(); }
|
virtual QIcon pluginIcon() { return QIcon(); }
|
||||||
|
QMap<QString, QString> translations() { return m_translations; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTranslator* translatorFrom(QString fileName) {
|
QTranslator* translatorFrom(QString fileName) {
|
||||||
@@ -87,6 +88,7 @@ protected:
|
|||||||
QWidget *m_ui;
|
QWidget *m_ui;
|
||||||
QWidget *m_settingsUi;
|
QWidget *m_settingsUi;
|
||||||
IService *m_service;
|
IService *m_service;
|
||||||
|
QMap<QString, QString> m_translations;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PluginInterface_iid "cz.itsolved.prodejna.IPlugin"
|
#define PluginInterface_iid "cz.itsolved.prodejna.IPlugin"
|
||||||
|
|||||||
Reference in New Issue
Block a user