File indexing completed on 2024-03-24 04:38:43
0001 // ASLocalizer.h 0002 // Copyright (c) 2016 by Jim Pattee <jimp03@email.com>. 0003 // This code is licensed under the MIT License. 0004 // License.txt describes the conditions under which this software may be distributed. 0005 0006 0007 #ifndef ASLOCALIZER_H 0008 #define ASLOCALIZER_H 0009 0010 #include <string> 0011 #include <vector> 0012 0013 namespace astyle { 0014 0015 using namespace std; 0016 0017 #ifndef ASTYLE_LIB 0018 0019 //----------------------------------------------------------------------------- 0020 // ASLocalizer class for console build. 0021 // This class encapsulates all language-dependent settings and is a 0022 // generalization of the C locale concept. 0023 //----------------------------------------------------------------------------- 0024 class Translation; 0025 0026 class ASLocalizer 0027 { 0028 public: // functions 0029 ASLocalizer(); 0030 virtual ~ASLocalizer(); 0031 string getLanguageID() const; 0032 const Translation* getTranslationClass() const; 0033 #ifdef _WIN32 0034 void setLanguageFromLCID(size_t lcid); 0035 #endif 0036 void setLanguageFromName(const char* langID); 0037 const char* settext(const char* textIn) const; 0038 0039 private: // functions 0040 void setTranslationClass(); 0041 0042 private: // variables 0043 Translation* m_translation; // pointer to a polymorphic Translation class 0044 string m_langID; // language identifier from the locale 0045 string m_subLangID; // sub language identifier, if needed 0046 string m_localeName; // name of the current locale (Linux only) 0047 size_t m_lcid; // LCID of the user locale (Windows only) 0048 }; 0049 0050 //---------------------------------------------------------------------------- 0051 // Translation base class. 0052 //---------------------------------------------------------------------------- 0053 0054 class Translation 0055 // This base class is inherited by the language translation classes. 0056 // Polymorphism is used to call the correct language translator. 0057 // This class contains the translation vector and settext translation method. 0058 // The language vector is built by the language sub classes. 0059 // NOTE: This class must have virtual methods for typeid() to work. 0060 // typeid() is used by AStyleTestI18n_Localizer.cpp. 0061 { 0062 public: 0063 Translation() {} 0064 virtual ~Translation() {} 0065 string convertToMultiByte(const wstring& wideStr) const; 0066 size_t getTranslationVectorSize() const; 0067 bool getWideTranslation(const string& stringIn, wstring& wideOut) const; 0068 string& translate(const string& stringIn) const; 0069 0070 protected: 0071 void addPair(const string& english, const wstring& translated); 0072 // variables 0073 vector<pair<string, wstring> > m_translation; // translation vector 0074 0075 private: 0076 mutable string m_mbTranslation; 0077 }; 0078 0079 //---------------------------------------------------------------------------- 0080 // Translation classes 0081 // One class for each language. 0082 // These classes have only a constructor which builds the language vector. 0083 //---------------------------------------------------------------------------- 0084 0085 class Bulgarian : public Translation 0086 { public: Bulgarian(); }; 0087 0088 class ChineseSimplified : public Translation 0089 { public: ChineseSimplified(); }; 0090 0091 class ChineseTraditional : public Translation 0092 { public: ChineseTraditional(); }; 0093 0094 class Dutch : public Translation 0095 { public: Dutch(); }; 0096 0097 class English : public Translation 0098 { public: English(); }; 0099 0100 class Estonian : public Translation 0101 { public: Estonian(); }; 0102 0103 class Finnish : public Translation 0104 { public: Finnish(); }; 0105 0106 class French : public Translation 0107 { public: French(); }; 0108 0109 class German : public Translation 0110 { public: German(); }; 0111 0112 class Greek : public Translation 0113 { public: Greek(); }; 0114 0115 class Hindi : public Translation 0116 { public: Hindi(); }; 0117 0118 class Hungarian : public Translation 0119 { public: Hungarian(); }; 0120 0121 class Italian : public Translation 0122 { public: Italian(); }; 0123 0124 class Japanese : public Translation 0125 { public: Japanese(); }; 0126 0127 class Korean : public Translation 0128 { public: Korean(); }; 0129 0130 class Norwegian : public Translation 0131 { public: Norwegian(); }; 0132 0133 class Polish : public Translation 0134 { public: Polish(); }; 0135 0136 class Portuguese : public Translation 0137 { public: Portuguese(); }; 0138 0139 class Romanian : public Translation 0140 { public: Romanian(); }; 0141 0142 class Russian : public Translation 0143 { public: Russian(); }; 0144 0145 class Spanish : public Translation 0146 { public: Spanish(); }; 0147 0148 class Swedish : public Translation 0149 { public: Swedish(); }; 0150 0151 class Ukrainian : public Translation 0152 { public: Ukrainian(); }; 0153 0154 0155 #endif // ASTYLE_LIB 0156 0157 } // namespace astyle 0158 0159 #endif // ASLOCALIZER_H