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
20namespace astyle {
21
22using 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//-----------------------------------------------------------------------------
31class Translation;
32
33class ASLocalizer
34{
35public: // 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
46private: // functions
47 void setTranslationClass();
48
49private: // 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
63class 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{
71public:
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
80protected:
81 void addPair(const string& english, const wstring& translated);
82 // variables
83 vector<pair<string, wstring> > m_translationVector;
84
85private:
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
98class Bulgarian : public Translation
99{ public: Bulgarian(); };
100
101class ChineseSimplified : public Translation
102{ public: ChineseSimplified(); };
103
104class ChineseTraditional : public Translation
105{ public: ChineseTraditional(); };
106
107class Dutch : public Translation
108{ public: Dutch(); };
109
110class English : public Translation
111{ public: English(); };
112
113class Estonian : public Translation
114{ public: Estonian(); };
115
116class Finnish : public Translation
117{ public: Finnish(); };
118
119class French : public Translation
120{ public: French(); };
121
122class German : public Translation
123{ public: German(); };
124
125class Greek : public Translation
126{ public: Greek(); };
127
128class Hindi : public Translation
129{ public: Hindi(); };
130
131class Hungarian : public Translation
132{ public: Hungarian(); };
133
134class Italian : public Translation
135{ public: Italian(); };
136
137class Japanese : public Translation
138{ public: Japanese(); };
139
140class Korean : public Translation
141{ public: Korean(); };
142
143class Norwegian : public Translation
144{ public: Norwegian(); };
145
146class Polish : public Translation
147{ public: Polish(); };
148
149class Portuguese : public Translation
150{ public: Portuguese(); };
151
152class Romanian : public Translation
153{ public: Romanian(); };
154
155class Russian : public Translation
156{ public: Russian(); };
157
158class Spanish : public Translation
159{ public: Spanish(); };
160
161class Swedish : public Translation
162{ public: Swedish(); };
163
164class Ukrainian : public Translation
165{ public: Ukrainian(); };
166
167
168#endif // ASTYLE_LIB
169
170} // namespace astyle
171
172#endif // ASLOCALIZER_H
173