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