OMGPOP OMGPOP - 19 days ago 9x
Android Question

cocos2d-x localization simplified/traditional chinese

i need to separate simplified/traditional chinese. in cocos2d for iPhone, i simply use "hans" and "hant". but in cocos2d-x, i dive into the code and here is the code for CCApplication:

ccLanguageType ret = kLanguageEnglish;
if ([languageCode isEqualToString:@"zh"])
ret = kLanguageChinese;
else if ([languageCode isEqualToString:@"en"])
ret = kLanguageEnglish;
else if ([languageCode isEqualToString:@"fr"]){
ret = kLanguageFrench;
else if ([languageCode isEqualToString:@"it"]){
ret = kLanguageItalian;
else if ([languageCode isEqualToString:@"de"]){
ret = kLanguageGerman;
else if ([languageCode isEqualToString:@"es"]){
ret = kLanguageSpanish;
else if ([languageCode isEqualToString:@"ru"]){
ret = kLanguageRussian;

return ret;

note that only 'zh' for chinese (both simplified/traditional, maybe)

so how can i distinguish them?

I use cocos2d-x and need to work with android. not just iPhone. Mickey's answer works for iPhone only. thanks.


You need to do some changes in cocos2dx android jni: in cocos2d-x-2.x.x/cocos2dx/platform/android/java/src/org/cocos2dx/lib/,


return Locale.getDefault().getLanguage();


return Locale.getDefault().toString();

Thus, you can get zh_CN, zh_TW in CCApplication::getCurrentLanguage(), also, you must update the implementations in CCApplication::getCurrentLanguage() (locates cocos2d-x-2.x.x/cocos2dx/platform/android/CCApplication.cpp):

ccLanguageType CCApplication::getCurrentLanguage()
    std::string languageName = getCurrentLanguageJNI();
    if (languageName.find("zh_CN") == 0) {
        return kLanguageChineseCN; // need define this value by yourself
    } else if (languageName.find("zh_TW") == 0) {
        return kLanguageChineseTW; // need define this value by yourself
    } else if (languangeName.find("en") == 0) {
        return kLanguageEnglish;
    } ...

    return kLanguageEnglish;