diff --git a/addressbook/addressbook.json b/addressbook/addressbook.json index 6c6a779..ce7ac2f 100644 --- a/addressbook/addressbook.json +++ b/addressbook/addressbook.json @@ -24,5 +24,19 @@ \"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Č" + } + } } diff --git a/core/autotablemodel.h b/core/autotablemodel.h index 4858ce0..6f45b0f 100644 --- a/core/autotablemodel.h +++ b/core/autotablemodel.h @@ -109,7 +109,12 @@ public: if (i == section) { QString colName(entity->metaObject()->property(i + 1).name()); 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(); } + void setTranslations(const QMap &translations) + { + m_translations = translations; + } + protected: void handleFilter(const QString &filter) override { @@ -210,6 +220,7 @@ protected: private: QList > m_list; QList > m_fullList; + QMap m_translations; bool filtered; diff --git a/core/gridform.h b/core/gridform.h index c057c95..54642b8 100644 --- a/core/gridform.h +++ b/core/gridform.h @@ -80,6 +80,10 @@ public: m_formHandler = handler; } + virtual void setTranslations(const QMap &translations) { + m_tableModel->setTranslations(translations); + } + public slots: bool fillData() { if (m_tableModel == NULL) { diff --git a/core/igridform.h b/core/igridform.h index 01a556d..f5a1aec 100644 --- a/core/igridform.h +++ b/core/igridform.h @@ -27,6 +27,7 @@ public: void setPluginId(const QString &pluginId); QString pluginId(); QTableView *tableView(); + virtual void setTranslations(const QMap &translations) = 0; signals: void dataChanged(); diff --git a/core/imetadataplugin.cpp b/core/imetadataplugin.cpp index 44b72a8..cc1e709 100644 --- a/core/imetadataplugin.cpp +++ b/core/imetadataplugin.cpp @@ -59,6 +59,7 @@ void IMetaDataPlugin::init(const QJsonObject &metaData) if (IGridForm *pluginUi = dynamic_cast(m_ui)) { pluginUi->setPluginId(pluginId()); + pluginUi->setTranslations(m_translations); } if (m_service != NULL) @@ -87,6 +88,23 @@ void IMetaDataPlugin::parseMetaData(const QJsonObject &metaData) foreach (QJsonValue depVal, data.toObject()["dependecies"].toArray()) { 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) diff --git a/core/iplugin.h b/core/iplugin.h index 1ae33bc..018b2dc 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -75,6 +75,7 @@ public: virtual QTranslator* translator() { return NULL; } virtual QIcon pluginIcon() { return QIcon(); } + QMap translations() { return m_translations; } protected: QTranslator* translatorFrom(QString fileName) { @@ -87,6 +88,7 @@ protected: QWidget *m_ui; QWidget *m_settingsUi; IService *m_service; + QMap m_translations; }; #define PluginInterface_iid "cz.itsolved.prodejna.IPlugin"