libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YTransText.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YTransText.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YTransText_h
00026 #define YTransText_h
00027 
00028 #include <libintl.h>
00029 #include <string>
00030 
00031 
00032 /**
00033  * Helper class for translated strings: Stores a message in the original
00034  * (untranslated) version along with the translation into the current locale.
00035  **/
00036 class YTransText
00037 {
00038 public:
00039 
00040     /**
00041      * Constructor with both original and translated message.
00042      **/
00043     YTransText( const std::string & orig,
00044                 const std::string & translation )
00045         : _orig( orig ), _translation( translation ) {}
00046 
00047     /**
00048      * Constructor that automatically translates the original message.
00049      **/
00050     YTransText( const std::string & orig ) : _orig( orig )
00051     {
00052         _translation = gettext( _orig.c_str() );
00053     }
00054 
00055     /**
00056      * Copy constructor.
00057      **/
00058     YTransText( const YTransText & src )
00059     {
00060         _orig           = src.orig();
00061         _translation    = src.translation();
00062     }
00063 
00064     /**
00065      * Assignment operator.
00066      **/
00067     YTransText & operator= ( const YTransText & src )
00068     {
00069         _orig           = src.orig();
00070         _translation    = src.translation();
00071 
00072         return *this;
00073     }
00074 
00075     /**
00076      * Return the original message.
00077      **/
00078     const std::string & orig()          const { return _orig;           }
00079 
00080     /**
00081      * Return the translation.
00082      **/
00083     const std::string & translation()   const { return _translation;    }
00084 
00085     /**
00086      * Return the translation.
00087      * ( alias, just as a shortcut )
00088      **/
00089     const std::string & trans()         const { return _translation;    }
00090 
00091     /**
00092      * Set the original message. Does not touch the translation, so make sure
00093      * you change both if you want to keep them synchronized!
00094      **/
00095     void setOrig( const std::string & newOrig ) { _orig = newOrig; }
00096 
00097     /**
00098      * Set the translation.
00099      **/
00100     void setTranslation( const std::string & newTrans ) { _translation = newTrans; }
00101 
00102     /**
00103      * operator< : Compares translations.
00104      **/
00105     bool operator< ( const YTransText & other ) const
00106         { return _translation < other.translation(); }
00107 
00108     /**
00109      * operator> : Compares translations.
00110      **/
00111     bool operator> ( const YTransText & other ) const
00112         { return _translation > other.translation(); }
00113 
00114     /**
00115      * operator== : Compares translations.
00116      **/
00117     bool operator== ( const YTransText & other ) const
00118         { return _translation == other.translation(); }
00119 
00120 
00121 private:
00122 
00123     std::string _orig;
00124     std::string _translation;
00125 
00126 };
00127 
00128 
00129 
00130 #endif // YTransText_h
 All Classes Functions Variables Enumerations Friends