ios 判断系统语言是简体中文还是繁体中文

     cocos2d-x中可以用 如下的方法来判断是否是中文还是其他的语言

      

       //default language is local language
        ccLanguageType currentLanguageType = CCApplication::sharedApplication()->getCurrentLanguage();
        switch (currentLanguageType)
        {
            case kLanguageEnglish:
                language_ = "english";
                break;
            case kLanguageChinese:
                language_ = "zhcn";
                break;

            default:
                language_ = "english";
                break;
        }
    }
  但是,我想判断到底是简体中文,还是繁体中文,翻了下cocos2d-x的 ccLanguageType的定义里面没有哦。


CCApplication::sharedApplication()->getCurrentLanguage(); 这个的实现,自己改下了下如下的方法。   于是我找了下 的方法。

  

//是否是繁体中文
bool  LanguageManager::isTaiWanChinese()
{
    // get the current language and country config
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLanguage = [languages objectAtIndex:0];
    
    if ( [currentLanguage isEqualToString:@"zh-Hant"])
    {
        return  true;
    }
    else
    {
        return  false;
    }
    
}

 然后,就可以用下面的代码来判断是否是 简体中文还是繁体中文了

  

        //default language is local language
        ccLanguageType currentLanguageType = CCApplication::sharedApplication()->getCurrentLanguage();
        switch (currentLanguageType)
        {
            case kLanguageEnglish:
                language_ = "english";
                break;
            case kLanguageChinese:
                //判断是否是简体的还是繁体的
                
                //如果是繁体的
                if (isTaiWanChinese() == true)
                {
                    language_ = "zhcnt";
                }
                //是简体的
                else
                {
                    language_ = "zhcn";
                }
                
                break;

            default:
                language_ = "english";
                break;
        }
    }


你可能感兴趣的:(ios 判断系统语言是简体中文还是繁体中文)