2014-12-04 18:28:47 +01:00
|
|
|
/***************************************************************************************************
|
|
|
|
**
|
2015-02-27 11:21:09 +01:00
|
|
|
** Copyright (C) 2014 Roman Telezhynskyi <dismine(at)gmail.com>
|
2014-12-04 18:28:47 +01:00
|
|
|
**
|
|
|
|
** Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
** software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
** without restriction, including without limitation the rights to use, copy, modify,
|
|
|
|
** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
** permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
**
|
|
|
|
** The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
** substantial portions of the Software.
|
|
|
|
**
|
|
|
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
|
|
** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
**
|
|
|
|
******************************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QMUTRANSLATION_H
|
|
|
|
#define QMUTRANSLATION_H
|
|
|
|
|
2016-03-02 01:23:07 +01:00
|
|
|
#include "../qmuparser/qmuparser_global.h"
|
2014-12-04 18:28:47 +01:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
namespace qmu
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief The VTranslation class help store string for translation.
|
|
|
|
*
|
|
|
|
* I took idea from this article http://ololoepepe.blogspot.com/2013/08/qt.html.
|
|
|
|
* As you know, if wrap string to a function translate, it will be marked for translation. No matter what namespace
|
|
|
|
* contains this function. In class Translation used this circumstance.
|
|
|
|
* This mean never change name of method translate!!!!!.
|
|
|
|
* Instead of using QT_TRANSLATE_NOOP3 macros we can store strings in QMap.
|
|
|
|
* Example:
|
|
|
|
* create map and fill up its
|
|
|
|
* QMap<QString, VTranslation> map;
|
|
|
|
* map.insert("head_girth", VTranslation::translate("Measurements", "head_girth", "Around fullest part of Head."));
|
|
|
|
* get translated string
|
|
|
|
* map.value(measurement).translate();
|
2015-10-08 07:24:15 +02:00
|
|
|
*
|
2015-10-15 11:32:50 +02:00
|
|
|
* Hint. Define macros translate() for reducing code complexity.
|
2015-10-16 22:00:05 +02:00
|
|
|
* #define translate(context, source, disambiguation) QmuTranslation::translate((context), (source), (disambiguation))
|
2015-10-08 07:24:15 +02:00
|
|
|
*
|
|
|
|
* Don't forget to undef macros later!
|
2014-12-04 18:28:47 +01:00
|
|
|
*/
|
|
|
|
class QMUPARSERSHARED_EXPORT QmuTranslation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QmuTranslation();
|
|
|
|
~QmuTranslation(){}
|
2018-03-15 07:51:47 +01:00
|
|
|
QmuTranslation(const QString &context, const QString &sourceText, const QString &disambiguation = QString(),
|
2017-07-05 18:35:34 +02:00
|
|
|
int n = -1);
|
2014-12-04 18:28:47 +01:00
|
|
|
QmuTranslation &operator=(const QmuTranslation &tr);
|
|
|
|
QmuTranslation(const QmuTranslation &tr);
|
2018-01-21 15:00:53 +01:00
|
|
|
QString translate(const QString &locale) const;
|
2018-03-15 07:51:47 +01:00
|
|
|
static QmuTranslation translate(const char * context, const char * sourceText,
|
|
|
|
const char * disambiguation = nullptr, int n = -1);
|
2014-12-04 18:28:47 +01:00
|
|
|
QString getMcontext() const;
|
|
|
|
QString getMsourceText() const;
|
|
|
|
QString getMdisambiguation() const;
|
|
|
|
int getN() const;
|
|
|
|
private:
|
|
|
|
QString mcontext;
|
|
|
|
QString msourceText;
|
|
|
|
QString mdisambiguation;
|
|
|
|
int mn;
|
2018-01-21 15:00:53 +01:00
|
|
|
mutable QString localeName;
|
|
|
|
mutable QString cachedTranslation;
|
2014-12-04 18:28:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline QString QmuTranslation::getMcontext() const
|
|
|
|
{
|
|
|
|
return mcontext;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline QString QmuTranslation::getMsourceText() const
|
|
|
|
{
|
|
|
|
return msourceText;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline QString QmuTranslation::getMdisambiguation() const
|
|
|
|
{
|
|
|
|
return mdisambiguation;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline int QmuTranslation::getN() const
|
|
|
|
{
|
|
|
|
return mn;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace qmu
|
|
|
|
|
|
|
|
#endif // QMUTRANSLATION_H
|