Salome HOME
Update copyrights
[modules/shaper.git] / src / Config / Config_Translator.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
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 #ifndef Config_Translator_H
21 #define Config_Translator_H
22
23 #include "Config_def.h"
24 #include <Events_InfoMessage.h>
25
26 #include <string>
27 #include <map>
28
29
30 /// The definition provides collection and writing of missed translations
31 //#define MISSED_TRANSLATION
32
33 /**
34  * \class Config_Translator
35  * \ingroup Config
36  * \brief Class for messages translation on different languages. It can load TS
37  * files wich contain translation string and provides translations of messages from source code
38  */
39 class Config_Translator
40 {
41 public:
42   /// A data type of dictionary <KeyString, ResultString>
43   typedef std::map<std::string, std::string> Dictionary;
44
45   /// A data type of Translator with structure <Context, Dictionary>
46   typedef std::map<std::string, Dictionary> Translator;
47
48   /**
49   * Load translations from TS file
50   * \param theFileName a TS file name with full path
51   */
52   static CONFIG_EXPORT bool load(const std::string& theFileName);
53
54   /**
55   * Returns translation from the given info message.
56   * If translation is not exists then it returns a string
57   * from the info data without translation
58   * \param theInfo an info message
59   */
60   static CONFIG_EXPORT std::string translate(const Events_InfoMessage& theInfo);
61
62   /**
63   * Returns translation from the given data.
64   * If translation is not exists then it returns a string 
65   * from the info data without translation
66   * \param theContext context of the message (Feature Id)
67   * \param theMessage a message which dave to be translated
68   * \param theParams a list of parameters (can be empty)
69   */
70   static CONFIG_EXPORT std::string translate(const std::string& theContext,
71     const std::string& theMessage,
72     const std::list<std::string>& theParams = std::list<std::string>());
73
74
75   /**
76   * Returns codec for the context
77   * \param theContext the context
78   */ 
79   static CONFIG_EXPORT std::string codec(const std::string& theContext);
80
81   /**
82   * Returns codec for the context
83   * \param theInfo the info
84   */ 
85   static CONFIG_EXPORT std::string codec(const Events_InfoMessage& theInfo);
86
87 #ifdef _DEBUG
88 #ifdef MISSED_TRANSLATION
89   static CONFIG_EXPORT void saveMissedTranslations();
90 #endif
91 #endif
92
93
94 private:
95   /// A map of translations
96   static Translator myTranslator;
97
98   /// aMap of codecs for contexts
99   static Dictionary myCodecs;
100
101 #ifdef _DEBUG
102 #ifdef MISSED_TRANSLATION
103   static Translator myMissed;
104 #endif
105 #endif
106 };
107
108 #endif