1 // ASLocalizer.h
2 // Copyright (c) 2017 by Jim Pattee <jimp03@email.com>.
3 // This code is licensed under the MIT License.
4 // License.md describes the conditions under which this software may be distributed.
5 
6 
7 #ifndef ASLOCALIZER_H
8 #define ASLOCALIZER_H
9 
10 #include <string>
11 #include <vector>
12 
13 namespace astyle {
14 
15 using namespace std;
16 
17 #ifndef ASTYLE_LIB
18 
19 //-----------------------------------------------------------------------------
20 // ASLocalizer class for console build.
21 // This class encapsulates all language-dependent settings and is a
22 // generalization of the C locale concept.
23 //-----------------------------------------------------------------------------
24 class Translation;
25 
26 class ASLocalizer
27 {
28 public:		// functions
29 	ASLocalizer();
30 	virtual ~ASLocalizer();
31 	string getLanguageID() const;
32 	const Translation* getTranslationClass() const;
33 #ifdef _WIN32
34 	void setLanguageFromLCID(size_t lcid);
35 #endif
36 	void setLanguageFromName(const char* langID);
37 	const char* settext(const char* textIn) const;
38 
39 private:	// functions
40 	void setTranslationClass();
41 
42 private:	// variables
43 	Translation* m_translation;		// pointer to a polymorphic Translation class
44 	string m_langID;				// language identifier from the locale
45 	string m_subLangID;				// sub language identifier, if needed
46 	string m_localeName;			// name of the current locale (Linux only)
47 	size_t m_lcid;					// LCID of the user locale (Windows only)
48 };
49 
50 //----------------------------------------------------------------------------
51 // Translation base class.
52 //----------------------------------------------------------------------------
53 
54 class Translation
55 // This base class is inherited by the language translation classes.
56 // Polymorphism is used to call the correct language translator.
57 // This class contains the translation vector and settext translation method.
58 // The language vector is built by the language sub classes.
59 // NOTE: This class must have virtual methods for typeid() to work.
60 //       typeid() is used by AStyleTestI18n_Localizer.cpp.
61 {
62 public:
Translation()63 	Translation() {}
~Translation()64 	virtual ~Translation() {}
65 	string convertToMultiByte(const wstring& wideStr) const;
66 	size_t getTranslationVectorSize() const;
67 	bool getWideTranslation(const string& stringIn, wstring& wideOut) const;
68 	string& translate(const string& stringIn) const;
69 
70 protected:
71 	void addPair(const string& english, const wstring& translated);
72 	// variables
73 	vector<pair<string, wstring> > m_translation;		// translation vector
74 
75 private:
76 	mutable string m_mbTranslation;
77 };
78 
79 //----------------------------------------------------------------------------
80 // Translation classes
81 // One class for each language.
82 // These classes have only a constructor which builds the language vector.
83 //----------------------------------------------------------------------------
84 
85 class Bulgarian : public Translation
86 { public: Bulgarian(); };
87 
88 class ChineseSimplified : public Translation
89 { public: ChineseSimplified(); };
90 
91 class ChineseTraditional : public Translation
92 { public: ChineseTraditional(); };
93 
94 class Dutch : public Translation
95 { public: Dutch(); };
96 
97 class English : public Translation
98 { public: English(); };
99 
100 class Estonian : public Translation
101 { public: Estonian(); };
102 
103 class Finnish : public Translation
104 { public: Finnish(); };
105 
106 class French : public Translation
107 { public: French(); };
108 
109 class German : public Translation
110 { public: German(); };
111 
112 class Greek : public Translation
113 { public: Greek(); };
114 
115 class Hindi : public Translation
116 { public: Hindi(); };
117 
118 class Hungarian : public Translation
119 { public: Hungarian(); };
120 
121 class Italian : public Translation
122 { public: Italian(); };
123 
124 class Japanese : public Translation
125 { public: Japanese(); };
126 
127 class Korean : public Translation
128 { public: Korean(); };
129 
130 class Norwegian : public Translation
131 { public: Norwegian(); };
132 
133 class Polish : public Translation
134 { public: Polish(); };
135 
136 class Portuguese : public Translation
137 { public: Portuguese(); };
138 
139 class Romanian : public Translation
140 { public: Romanian(); };
141 
142 class Russian : public Translation
143 { public: Russian(); };
144 
145 class Spanish : public Translation
146 { public: Spanish(); };
147 
148 class Swedish : public Translation
149 { public: Swedish(); };
150 
151 class Ukrainian : public Translation
152 { public: Ukrainian(); };
153 
154 
155 #endif	//  ASTYLE_LIB
156 
157 }	// namespace astyle
158 
159 #endif	//  ASLOCALIZER_H
160