Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Interfaces/AAA/Accounting_Interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Interfaces/AAA/Authorization.h"
#include "Interfaces/Common/QtTypes.hpp"
#include "Interfaces/Helpers/TokenHelper.h"
#include "Interfaces/Helpers/LanguageHelper.h"

using namespace Targoman::API;
using namespace Targoman::API::AAA;
Expand Down Expand Up @@ -186,11 +187,10 @@ ORMSelectQuery intfAccountUnits::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICALLBO
})
.leftJoin(tblAccountUnitsI18NBase::Name)
.addCol(DBExpression::VALUE(QString("COALESCE("
"JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.untName.\"%2\"')),"
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountUnitsI18NBase::Name, "untName") + ","
"JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.untName.default')),"
"%3.untName)")
"%2.untName)")
.arg(tblAccountUnitsI18NBase::Name)
.arg(APICALLBOOM_PARAM.language())
.arg(_alias.isEmpty() ? tblAccountUnitsBase::Name : _alias)
),
tblAccountUnitsBase::Fields::untName
Expand Down Expand Up @@ -296,16 +296,16 @@ ORMSelectQuery intfAccountProducts::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICAL
tblAccountProductsBase::Fields::prdDesc,
})
.leftJoin(tblAccountProductsI18NBase::Name)
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.prdName.\"%2\"')), %3.prdName)")
.arg(tblAccountProductsI18NBase::Name)
.arg(APICALLBOOM_PARAM.language())
.addCol(DBExpression::VALUE(QString("COALESCE("
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountProductsI18NBase::Name, "prdName") + ","
"%1.prdName)")
.arg(_alias.isEmpty() ? tblAccountProductsBase::Name : _alias)
),
tblAccountProductsBase::Fields::prdName
)
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.prdDesc.\"%2\"')), %3.prdDesc)")
.arg(tblAccountProductsI18NBase::Name)
.arg(APICALLBOOM_PARAM.language())
.addCol(DBExpression::VALUE(QString("COALESCE("
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountProductsI18NBase::Name, "prdDesc") + ","
"%1.prdDesc)")
.arg(_alias.isEmpty() ? tblAccountProductsBase::Name : _alias)
),
tblAccountProductsBase::Fields::prdDesc
Expand Down Expand Up @@ -405,16 +405,16 @@ ORMSelectQuery intfAccountSaleables::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICA
tblAccountSaleablesBase::Fields::slbDesc,
})
.leftJoin(tblAccountSaleablesI18NBase::Name)
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.slbName.\"%2\"')), %3.slbName)")
.arg(tblAccountSaleablesI18NBase::Name)
.arg(APICALLBOOM_PARAM.language())
.addCol(DBExpression::VALUE(QString("COALESCE("
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountSaleablesI18NBase::Name, "slbName") + ","
"%1.slbName)")
.arg(_alias.isEmpty() ? tblAccountSaleablesBase::Name : _alias)
),
tblAccountSaleablesBase::Fields::slbName
)
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.slbDesc.\"%2\"')), %3.slbDesc)")
.arg(tblAccountSaleablesI18NBase::Name)
.arg(APICALLBOOM_PARAM.language())
.addCol(DBExpression::VALUE(QString("COALESCE("
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblAccountSaleablesI18NBase::Name, "slbDesc") + ","
"%1.slbDesc)")
.arg(_alias.isEmpty() ? tblAccountSaleablesBase::Name : _alias)
),
tblAccountSaleablesBase::Fields::slbDesc
Expand Down
56 changes: 56 additions & 0 deletions Interfaces/Helpers/LanguageHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI 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 AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#include "LanguageHelper.h"

namespace Targoman::API::Helpers {

QString LanguageHelper::getI18NClauseForCoalesce(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const QString &_i18nTableName,
const QString &_fieldName,
const QString &_i18nDataFieldName
) {
QString FieldPath = "$";
if (_fieldName.isEmpty() == false)
FieldPath += "." + _fieldName;

QString Result = QString("JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '%3.\"%4\"'))")
.arg(_i18nTableName)
.arg(_i18nDataFieldName)
.arg(FieldPath)
.arg(APICALLBOOM_PARAM.language())
;

if (APICALLBOOM_PARAM.language().contains("-"))
Result += ","
+ QString("JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '%3.%4'))")
.arg(_i18nTableName)
.arg(_i18nDataFieldName)
.arg(FieldPath)
.arg(APICALLBOOM_PARAM.language().split("-").first());

return Result;
}

} //namespace Targoman::API::Helpers
46 changes: 46 additions & 0 deletions Interfaces/Helpers/LanguageHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI 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 AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#ifndef TARGOMAN_API_LANGUAGEHELPER_H
#define TARGOMAN_API_LANGUAGEHELPER_H

#include <QString>
#include "../Server/APICallBoom.h"

namespace Targoman::API::Helpers {

using namespace Server;

class LanguageHelper
{
public:
static QString getI18NClauseForCoalesce(
INTFAPICALLBOOM_IMPL &APICALLBOOM_PARAM,
const QString &_i18nTableName,
const QString &_fieldName,
const QString &_i18nDataFieldName = "i18nData");
};

} //namespace Targoman::API::Helpers

#endif // TARGOMAN_API_LANGUAGEHELPER_H
2 changes: 2 additions & 0 deletions Interfaces/Interfaces.pro
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ HEADERS += \
API/intfModuleHelper.h \
Helpers/IteratorHelper.hpp \
Helpers/JSonHelper.h \
Helpers/LanguageHelper.h \
Helpers/TokenHelper.h \
ORM/intfFAQ.h \
ORM/intfMigrations.h \
Expand Down Expand Up @@ -86,6 +87,7 @@ HEADERS += \
SOURCES += \
API/intfModuleHelper.cpp \
Helpers/JSonHelper.cpp \
Helpers/LanguageHelper.cpp \
Helpers/TokenHelper.cpp \
ORM/intfFAQ.cpp \
ORM/intfMigrations.cpp \
Expand Down
8 changes: 5 additions & 3 deletions Interfaces/ORM/intfI18N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
#include "Interfaces/AAA/Authorization.h"
#include "Interfaces/AAA/AAADefs.hpp"
#include "Interfaces/AAA/clsJWT.hpp"
#include "Interfaces/Helpers/LanguageHelper.h"

using namespace Targoman::API::AAA;

namespace Targoman::API::ORM {

using namespace Helpers;

intfI18N::intfI18N(
const QString &_module,
const QString &_schema
Expand All @@ -50,12 +53,11 @@ QString intfI18N::translated(
auto Data = this->makeSelectQuery(APICALLBOOM_PARAM)
.addCol(tblI18N::Fields::i18nKey)
.addCol(DBExpression::VALUE(QString("COALESCE("
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.\"%3\"')),"
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblI18N::Name, "", tblI18N::Fields::i18nValue) + ","
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.default')),"
"'%4')")
"'%3')")
.arg(tblI18N::Name)
.arg(tblI18N::Fields::i18nValue)
.arg(APICALLBOOM_PARAM.language())
.arg(_key)
),
"Translated")
Expand Down
4 changes: 2 additions & 2 deletions ModuleHelpers/MT/Interfaces/intfMTCharts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Interfaces/Helpers/TokenHelper.h"
#include "intfMTAccounting.h"
#include "intfMTModule.h"
#include "Interfaces/Helpers/LanguageHelper.h"

using namespace Targoman::API;
using namespace Targoman::API::AAA;
Expand Down Expand Up @@ -765,12 +766,11 @@ std::tuple<CreditUsageRemained_t, QMap<QString, QString>> baseintfMTCharts::getU
auto I18NSelectQuery = I18N->makeSelectQuery(APICALLBOOM_PARAM)
.addCol(tblI18N::Fields::i18nKey)
.addCol(DBExpression::VALUE(QString("COALESCE("
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.\"%3\"')),"
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblI18N::Name, "", tblI18N::Fields::i18nValue) + ","
"JSON_UNQUOTE(JSON_EXTRACT(%1.%2, '$.default'))"
")")
.arg(tblI18N::Name)
.arg(tblI18N::Fields::i18nValue)
.arg(APICALLBOOM_PARAM.language())
),
"Translated")

Expand Down
7 changes: 4 additions & 3 deletions Modules/Account/moduleSrc/ORM/PaymentGateways.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../Account.h"
#include "Payment/PaymentLogic.h"
#include "Interfaces/Helpers/URLHelper.h"
#include "Interfaces/Helpers/LanguageHelper.h"

using namespace Targoman::API::AccountModule::Payment;
using namespace Targoman::API::Helpers;
Expand Down Expand Up @@ -79,9 +80,9 @@ ORMSelectQuery PaymentGatewayTypes::makeSelectQuery(INTFAPICALLBOOM_IMPL &APICAL
Query
.removeCol(tblPaymentGatewayTypes::Fields::pgtName)
.leftJoin(tblPaymentGatewayTypesI18N::Name)
.addCol(DBExpression::VALUE(QString("COALESCE(JSON_UNQUOTE(JSON_EXTRACT(%1.i18nData, '$.pgtName.\"%2\"')), %3.pgtName)")
.arg(tblPaymentGatewayTypesI18N::Name)
.arg(APICALLBOOM_PARAM.language())
.addCol(DBExpression::VALUE(QString("COALESCE("
+ LanguageHelper::getI18NClauseForCoalesce(APICALLBOOM_PARAM, tblPaymentGatewayTypesI18N::Name, "pgtName") + ","
"%1.pgtName)")
.arg(_alias.isEmpty() ? tblPaymentGatewayTypes::Name : _alias)
),
tblPaymentGatewayTypes::Fields::pgtName
Expand Down