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