cocos2d与cocos2dx多语言问题(读取文件中得信息)

cocos2dx多语言的核心代码所有的内容就在下面这个方法中

void getInfomations(){

        std::string defLanguage;

       cocos2d::LanguageType la = cocos2d::Application::getInstance() -> getCurrentLanguage();

        switch (la) {

            case cocos2d::LanguageType::CHINESE:

                defLanguage = "chinese";

                break;

                

            default:

                break;

        }红色部分是判断设备语言

        

        //读取plist

        const char *testPlistPath = "BSPlistDatas\\MutlLanguage.plist";

        std::string fullPath = cocos2d::CCFileUtils::getInstance() -> fullPathFromRelativeFile("MutlLanguage.plist",testPlistPath); 墨绿色是设置plist文件的路径

        cocos2d::CCDictionary *plistDic = cocos2d::CCDictionary::createWithContentsOfFile(fullPath.c_str());

        

        cocos2d::CCDictionary *levelDic = dynamic_cast<cocos2d::CCDictionary *>(plistDic -> objectForKey("language"));    黄色部分是根据plist路径来读取plist里卖弄的内容

        

        cocos2d::CCDictionary* langDic = NULL;

        if(defLanguage == "chinese")

        {

            langDic = dynamic_cast<cocos2d::CCDictionary*>(levelDic->objectForKey("chinese"));

        }

        else{

            langDic = dynamic_cast<cocos2d::CCDictionary*>(levelDic->objectForKey("english"));

        }

        //cocos2d::CCDictionary* farScene = dynamic_cast<cocos2d::CCDictionary*>(levelDic->objectForKey("bg_far_scene"));

        btnP = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("play"));      //play按键文字

        btnO = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("options"));      //options按键文字

        btnR = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("records"));      //records按键文字

        btnH = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("help"));      //help按键文字

        btnMe = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("menu"));      //play按键文字

        btnRe = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("reset"));      //options按键文字

        btnPa = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("pass"));      //records按键文字

        btnOn = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("on"));      //help按键文字

        btnOff = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("off"));      //play按键文字

        btnSo = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("sound on/off"));      //options按键文字

        btn1On = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("1-10 only"));      //options按键文字

        btnBa = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("back"));      //records按键文字

        btnPl = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("played"));      //help按键文字

        btnSol = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("solved"));      //play按键文字

        btnPad = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("passed"));      //options按键文字

        btnNe = dynamic_cast<cocos2d::CCString*>(langDic->objectForKey("next"));      //records按键文字

        //cocos2d::CCPoint point = cocos2d::PointFromString(farScene->valueForKey("pos")->getCString());

        

        cocos2d::CCLog("path = %s", btnP -> getCString());

        cocos2d::CCLog("pos = %s", btnO -> getCString());

    }

附带plist的source code格式的文件信息,方便读者理解

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>language</key>

<dict>

<key>english</key>

<dict>

<key>play</key>

<string>Play</string>

<key>options</key>

<string>Options</string>

<key>records</key>

<string>Records</string>

<key>help</key>

<string>Help</string>

<key>menu</key>

<string>Menu</string>

<key>reset</key>

<string>Reset</string>

<key>pass</key>

<string>Pass</string>

<key>on</key>

<string>On</string>

<key>off</key>

<string>Off</string>

<key>sound on/off</key>

<string>Sound On/off</string>

<key>1-10 only</key>

<string>1-10 Only</string>

<key>back</key>

<string>Back</string>

<key>played</key>

<string>Played</string>

<key>solved</key>

<string>Solved</string>

<key>passed</key>

<string>Passed</string>

<key>next</key>

<string>Next</string>

</dict>

<key>chinese</key>

<dict>

<key>play</key>

<string>开始</string>

<key>options</key>

<string>设置</string>

<key>records</key>

<string>记录</string>

<key>help</key>

<string>帮助</string>

<key>menu</key>

<string>菜单</string>

<key>reset</key>

<string>重置</string>

<key>pass</key>

<string>跳过</string>

<key>on</key>

<string>开</string>

<key>off</key>

<string>关</string>

<key>sound on/off</key>

<string>声音 开/关</string>

<key>1-10 only</key>

<string>1-10 什么</string>

<key>back</key>

<string>返回</string>

<key>played</key>

<string>关卡</string>

<key>solved</key>

<string>完成</string>

<key>passed</key>

<string>跳过</string>

<key>next</key>

<string>前进</string>

</dict>

</dict>

</dict>

</plist>

-----------------------------------------------------------------------------------------------------

以下是cocos2d的多语言的解决方案(网址)

http://www.himigame.com/iphone-cocos2d/608.html


转载于:https://my.oschina.net/u/1432769/blog/310124

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值