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