Salome HOME
Translated messages providing for SOLVER_ERROR attribute, code improvement
[modules/shaper.git] / src / Config / Config_Translator.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Config_Translator.h
4 // Created:     31 May 2016
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef Config_Translator_H
8 #define Config_Translator_H
9
10 #include "Config_def.h"
11 #include <Events_InfoMessage.h>
12
13 #include <string>
14 #include <map>
15
16
17 /// The definition provides collection and writing of missed translations
18 //#define MISSED_TRANSLATION
19
20 /**
21  * \class Config_Translator
22  * \ingroup Config
23  * \brief Class for messages translation on different languages. It can load TS
24  * files wich contain translation string and provides translations of messages from source code
25  */
26 class Config_Translator
27 {
28 public:
29   /// A data type of dictionary <KeyString, ResultString>
30   typedef std::map<std::string, std::string> Dictionary;
31
32   /// A data type of Translator with structure <Context, Dictionary>
33   typedef std::map<std::string, Dictionary> Translator;
34
35   /**
36   * Load translations from TS file
37   * \param theFileName a TS file name with full path
38   */
39   static CONFIG_EXPORT bool load(const std::string& theFileName);
40
41   /**
42   * Returns translation from the given info message.
43   * If transdlation is not exists then it returns a string 
44   * from the info data without translation
45   * \param theInfo an info message
46   */
47   static CONFIG_EXPORT std::string translate(std::shared_ptr<Events_InfoMessage> theInfo);
48
49   /**
50   * Returns translation from the given data.
51   * If translation is not exists then it returns a string 
52   * from the info data without translation
53   * \param theContext context of the message (Feature Id)
54   * \param theMessage a message which dave to be translated
55   * \param theParams a list of parameters (can be empty)
56   */
57   static CONFIG_EXPORT std::string translate(const std::string& theContext,
58     const std::string& theMessage, 
59     const std::list<std::string>& theParams = std::list<std::string>());
60
61
62   /**
63   * Returns codec for the context
64   * \param theContext the context
65   */ 
66   static CONFIG_EXPORT std::string codec(const std::string& theContext);
67
68 #ifdef _DEBUG
69 #ifdef MISSED_TRANSLATION
70   static CONFIG_EXPORT void saveMissedTranslations();
71 #endif
72 #endif
73
74
75 private:
76   /// A map of translations
77   static Translator myTranslator;
78
79   /// aMap of codecs for contexts
80   static Dictionary myCodecs;
81
82 #ifdef _DEBUG
83 #ifdef MISSED_TRANSLATION
84   static Translator myMissed;
85 #endif
86 #endif
87 };
88
89 #endif