File indexing completed on 2024-05-26 04:42:21

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