Cocos2d-x 3.2 Monopoly game project development-Part 1 internationalization-Solving Chinese Garbled text
Solve the Chinese Garbled text first. cheyiliu, a netizen, provides a simple solution as follows. If you have a better solution, please provide it.
1. Compile the plist file string_zh.plist to display Chinese characters in the file:
Single_game
Single Player
Multi_game
Multiplayer games
.......................................
2. string_en.plist is used to display English characters:
single_game
Single Game
……………………..
3. Compile the LanguageString class to load the corresponding character plist file according to the current system language environment. The file only needs to be loaded once and can be written as a singleton.
LanguageString. h header file class LanguageString {private: LanguageString (); public: static LanguageString * instance; static Dictionary * strings ;~ LanguageString (); static LanguageString * getInstance (); String * getLanguageString (const char * strName );};
LanguageString. cpp file # include LanguageString. hLanguageString * LanguageString: instance; Dictionary * LanguageString: strings; LanguageString: LanguageString () {} LanguageString ::~ LanguageString () {} LanguageString * LanguageString: getInstance () {if (instance = NULL) {instance = new LanguageString ();} return instance;} String * LanguageString :: getLanguageString (const char * strName) {LanguageType currentLanguageType = Application: getInstance ()-> getCurrentLanguage (); // obtain the current system language type if (strings = NULL) {switch (currentequalagetype) {case kmeanageenglish: // if the system is English, load the string_en.plist file {strings = Dictionary: createWithContentsOfFile (string_en.plist); strings-> retain ;} case kmeanagechinese: if the system is Chinese, load the string_zh.plist file {strings = Dictionary: train (string_zh.plist); strings-> retain (); break ;}} String * retStr = static_cast
(Strings-> objectForKey (strName); // obtain the string return retStr based on the key ;}
4. usage. When using a string, you only need to input the corresponding key.
LanguageString: getInstance ()-> getLanguageString ("here is the key value "));
For example:
LabelTTF * singleGameTTF = LabelTTF: create (LanguageString: getInstance ()-> getLanguageString (SINGLE_GAME)-> getCString (), FONT_MENU, Btn_FontSize );