Salome HOME
Merge branch 'BR_internationalization'
[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 //#define MISSED_TRANSLATION
17
18 /**
19  * \class Config_Translator
20  * \ingroup Config
21  * \brief Class for messages translation on different languages. It can load TS
22  * files wich contain translation string and provides translations of messages from source code
23  */
24 class Config_Translator
25 {
26 public:
27   /// A data type of dictionary <KeyString, ResultString>
28   typedef std::map<std::string, std::string> Dictionary;
29
30   /// A data type of Translator with structure <Context, Dictionary>
31   typedef std::map<std::string, Dictionary> Translator;
32
33   /**
34   * Load translations from TS file
35   * \param theFileName a TS file name with full path
36   */
37   static CONFIG_EXPORT bool load(const std::string& theFileName);
38
39   /**
40   * Returns translation from the given info message.
41   * If transdlation is not exists then it returns a string 
42   * from the info data without translation
43   * \param theInfo an info message
44   */
45   static CONFIG_EXPORT std::string translate(std::shared_ptr<Events_InfoMessage> theInfo);
46
47   /**
48   * Returns translation from the given data.
49   * If transdlation is not exists then it returns a string 
50   * from the info data without translation
51   * \param theContext context of the message (Feature Id)
52   * \param theMessage a message which dave to be translated
53   * \param theParams a list of parameters (can be empty)
54   */
55   static CONFIG_EXPORT std::string translate(const std::string& theContext,
56     const std::string& theMessage, 
57     const std::list<std::string>& theParams = std::list<std::string>());
58
59
60   /**
61   * Returns codec for the context
62   * \param theContext the context
63   */ 
64   static CONFIG_EXPORT std::string codec(const std::string& theContext);
65
66 #ifdef _DEBUG
67 #ifdef MISSED_TRANSLATION
68   static CONFIG_EXPORT void saveMissedTranslations();
69 #endif
70 #endif
71
72
73 private:
74   /// A map of translations
75   static Translator myTranslator;
76
77   /// aMap of codecs for contexts
78   static Dictionary myCodecs;
79
80 #ifdef _DEBUG
81 #ifdef MISSED_TRANSLATION
82   static Translator myMissed;
83 #endif
84 #endif
85 };
86
87 #endif