Seamly2D
Code documentation
qmutranslation.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  **
3  ** Copyright (C) 2014 Roman Telezhynskyi <dismine(at)gmail.com>
4  **
5  ** Permission is hereby granted, free of charge, to any person obtaining a copy of this
6  ** software and associated documentation files (the "Software"), to deal in the Software
7  ** without restriction, including without limitation the rights to use, copy, modify,
8  ** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9  ** permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  **
11  ** The above copyright notice and this permission notice shall be included in all copies or
12  ** substantial portions of the Software.
13  **
14  ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15  ** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16  ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17  ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  **
20  ******************************************************************************************************/
21 
22 #ifndef QMUTRANSLATION_H
23 #define QMUTRANSLATION_H
24 
25 #include <QString>
26 
27 namespace qmu
28 {
29 
30 /**
31  * @file
32  * @brief The VTranslation class help store string for translation.
33  *
34  * I took idea from this article http://ololoepepe.blogspot.com/2013/08/qt.html.
35  * As you know, if wrap string to a function translate, it will be marked for translation. No matter what namespace
36  * contains this function. In class Translation used this circumstance.
37  * This mean never change name of method translate!!!!!.
38  * Instead of using QT_TRANSLATE_NOOP3 macros we can store strings in QMap.
39  * Example:
40  * create map and fill up its
41  * QMap<QString, VTranslation> map;
42  * map.insert("head_girth", VTranslation::translate("Measurements", "head_girth", "Around fullest part of Head."));
43  * get translated string
44  * map.value(measurement).translate();
45  *
46  * Hint. Define macros translate() for reducing code complexity.
47  * #define translate(context, source, disambiguation) QmuTranslation::translate((context), (source), (disambiguation))
48  *
49  * Don't forget to undef macros later!
50  */
52 {
53 public:
56  QmuTranslation(const QString &context, const QString &sourceText, const QString &disambiguation = nullptr,
57  int n = -1);
59  QmuTranslation(const QmuTranslation &tr);
60  QString translate() const;
61  static QmuTranslation translate(const QString &context, const QString &sourceText,
62  const QString &disambiguation = nullptr, int n = -1);
63  QString getMcontext() const;
64  QString getMsourceText() const;
65  QString getMdisambiguation() const;
66  int getN() const;
67 private:
68  QString mcontext;
69  QString msourceText;
70  QString mdisambiguation;
71  int mn;
72 };
73 
74 //---------------------------------------------------------------------------------------------------------------------
75 inline QString QmuTranslation::getMcontext() const
76 {
77  return mcontext;
78 }
79 
80 //---------------------------------------------------------------------------------------------------------------------
81 inline QString QmuTranslation::getMsourceText() const
82 {
83  return msourceText;
84 }
85 
86 //---------------------------------------------------------------------------------------------------------------------
87 inline QString QmuTranslation::getMdisambiguation() const
88 {
89  return mdisambiguation;
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
93 inline int QmuTranslation::getN() const
94 {
95  return mn;
96 }
97 
98 } // namespace qmu
99 
100 #endif // QMUTRANSLATION_H
QString getMsourceText() const
QString getMdisambiguation() const
QmuTranslation & operator=(const QmuTranslation &tr)
QString translate() const
QString getMcontext() const
Namespace for mathematical applications.