Cocos2d-x 3.2 Monopoly game project development-Part 2 internationalization-solve Chinese garbled characters, cocos2d-x Project Development

Source: Internet
Author: User

Cocos2d-x 3.2 Monopoly game project development-Part 2 internationalization-solve Chinese garbled characters, cocos2d-x Project Development

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:

<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE plist PUBLIC "-// Apple Computer // dtd plist 1.0 // EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version = "1.0"> <dict> <key> single_game </key> <string> single player </string> <key> multi_game </key> <string> multiplayer games </string> ....................................... </Dict> </plist>

2. string_en.plist is used to display English characters:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict>    <key>single_game</key>    <string>Single Game</string>……………………..</dict></plist>

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. h" LanguageString * 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 (); break;} case kmeanagechinese: if the system is Chinese, load the string_zh.plist file {strings = Dictionary: createWithContentsOfFile ("string_zh.plist"); strings-> retain (); break ;}}} string * retStr = static_cast <String *> (strings-> objectForKey (strName); // obtain the return retStr String 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 );


<A target = _ blank href = "http://download.csdn.net/detail/lideguo1979/8342891"> click to download the Code </a>
http://download.csdn.net/detail/lideguo1979/8342891



To be continued ......................

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.