Cocos2d-x 3.2 Monopoly game project development-Part 1 internationalization-Solving Chinese Garbled text

Source: Internet
Author: User

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 );

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.