Salome HOME
55dbd60078bb7ba24aa3e641598322db0bf9a192
[modules/gui.git] / src / Qtx / QtxTranslator.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:      QtxTranslator.cxx
21 // Author:    Alexander SOLOVYOV
22 //
23 #include "QtxTranslator.h"
24
25 /*!
26   \class QtxTranslator
27   \brief Extended version of QTranslator
28
29   In addition to the functionality provided by QTranslator class, QtxTranslator
30   allows translating resources defined in the global context (i.e. common resources).
31   The QtxTranslator can be used to workaround QTranslator's limitation which 
32   does not allow to process messages with global context.
33
34   For the current moment global context should be specified in translation
35   (*.ts) files as "@default" string. For example:
36   \verbatim
37   <!DOCTYPE TS><TS>
38   <context>
39     <name>@default</name>
40     <message>
41         <source>MY_MESSAGE</source>
42         <translation>My translated message</translation>
43     </message>
44   </context>
45   </TS>
46   \endverbatim
47 */
48
49 #define GLOBAL_CONTEXT "@default"
50
51 /*!
52   \brief Constructor.
53 */
54 QtxTranslator::QtxTranslator( QObject* parent )
55 : QTranslator( parent )
56 {
57 }
58
59 /*!
60   \brief Destructor.
61 */
62 QtxTranslator::~QtxTranslator()
63 {
64 }
65
66 /*!
67   \brief Returns the translation for the key.
68   \param context message context
69   \param sourceText message source name
70   \param disambiguation message comment (optional)
71   \param n optional numeral to choose the appropriate form of translation
72   \return Translated text if found or \a sourceText otherwise
73 */
74 QString QtxTranslator::translate( const char* context, const char* sourceText, const char* disambiguation, int n ) const
75 {
76   QString res = QTranslator::translate( context, sourceText, disambiguation, n );
77   if ( res.isNull() )
78     res = QTranslator::translate( GLOBAL_CONTEXT, sourceText, disambiguation, n );
79   return res;
80 }
81