libyui  3.4.2
YTransText.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YTransText.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YTransText_h
26 #define YTransText_h
27 
28 #include <libintl.h>
29 #include <string>
30 
31 
32 /**
33  * Helper class for translated strings: Stores a message in the original
34  * (untranslated) version along with the translation into the current locale.
35  **/
37 {
38 public:
39 
40  /**
41  * Constructor with both original and translated message.
42  **/
43  YTransText( const std::string & orig,
44  const std::string & translation )
45  : _orig( orig ), _translation( translation ) {}
46 
47  /**
48  * Constructor that automatically translates the original message.
49  **/
50  YTransText( const std::string & orig ) : _orig( orig )
51  {
52  _translation = gettext( _orig.c_str() );
53  }
54 
55  /**
56  * Copy constructor.
57  **/
58  YTransText( const YTransText & src )
59  {
60  _orig = src.orig();
61  _translation = src.translation();
62  }
63 
64  /**
65  * Assignment operator.
66  **/
67  YTransText & operator= ( const YTransText & src )
68  {
69  _orig = src.orig();
70  _translation = src.translation();
71 
72  return *this;
73  }
74 
75  /**
76  * Return the original message.
77  **/
78  const std::string & orig() const { return _orig; }
79 
80  /**
81  * Return the translation.
82  **/
83  const std::string & translation() const { return _translation; }
84 
85  /**
86  * Return the translation.
87  * ( alias, just as a shortcut )
88  **/
89  const std::string & trans() const { return _translation; }
90 
91  /**
92  * Set the original message. Does not touch the translation, so make sure
93  * you change both if you want to keep them synchronized!
94  **/
95  void setOrig( const std::string & newOrig ) { _orig = newOrig; }
96 
97  /**
98  * Set the translation.
99  **/
100  void setTranslation( const std::string & newTrans ) { _translation = newTrans; }
101 
102  /**
103  * operator< : Compares translations.
104  **/
105  bool operator< ( const YTransText & other ) const
106  { return _translation < other.translation(); }
107 
108  /**
109  * operator> : Compares translations.
110  **/
111  bool operator> ( const YTransText & other ) const
112  { return _translation > other.translation(); }
113 
114  /**
115  * operator== : Compares translations.
116  **/
117  bool operator== ( const YTransText & other ) const
118  { return _translation == other.translation(); }
119 
120 
121 private:
122 
123  std::string _orig;
124  std::string _translation;
125 
126 };
127 
128 
129 
130 #endif // YTransText_h
YTransText(const std::string &orig, const std::string &translation)
Constructor with both original and translated message.
Definition: YTransText.h:43
const std::string & trans() const
Return the translation.
Definition: YTransText.h:89
bool operator>(const YTransText &other) const
operator> : Compares translations.
Definition: YTransText.h:111
bool operator<(const YTransText &other) const
operator< : Compares translations.
Definition: YTransText.h:105
const std::string & translation() const
Return the translation.
Definition: YTransText.h:83
YTransText(const std::string &orig)
Constructor that automatically translates the original message.
Definition: YTransText.h:50
YTransText(const YTransText &src)
Copy constructor.
Definition: YTransText.h:58
void setTranslation(const std::string &newTrans)
Set the translation.
Definition: YTransText.h:100
void setOrig(const std::string &newOrig)
Set the original message.
Definition: YTransText.h:95
const std::string & orig() const
Return the original message.
Definition: YTransText.h:78
YTransText & operator=(const YTransText &src)
Assignment operator.
Definition: YTransText.h:67
Helper class for translated strings: Stores a message in the original (untranslated) version along wi...
Definition: YTransText.h:36
bool operator==(const YTransText &other) const
operator== : Compares translations.
Definition: YTransText.h:117