This is how I modified the cocos2d-x code to distinguish between simplified and traditional Chinese. Please note that this is for cocos2d-x v3.0 +.
For iOS, change cocos2d_libs.xcodeproj / platform / ios / CCApplication-ios.mm
LanguageType Application::getCurrentLanguage() { // get the current language and country config NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSArray *languages = [defaults objectForKey:@"AppleLanguages"]; NSString *currentLanguage = [languages objectAtIndex:0]; // get the current language code.(such as English is "en", Chinese is "zh" and so on) NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage]; NSString * languageCode = [temp objectForKey:NSLocaleLanguageCode]; LanguageType ret = LanguageType::ENGLISH; if ([languageCode isEqualToString:@"zh"]) { /** CHANGE THE FOLLOWING LINES */ NSString* scriptCode = [temp objectForKey:NSLocaleScriptCode]; NSString* countryCode = [temp objectForKey:NSLocaleCountryCode]; // On iOS, either chinese hong kong or chinese taiwan are traditional chinese. if ([scriptCode isEqualToString:@"Hant"] || [countryCode isEqualToString:@"HK"] || [countryCode isEqualToString:@"TW"]) { ret = LanguageType::CHINESE_TRADITIONAL; // You need to add these enum values to LanguageType } else { ret = LanguageType::CHINESE_SIMPLIFIED; // You need to add these enum values to LanguageType } } else if ([languageCode isEqualToString:@"en"]) { ret = LanguageType::ENGLISH; } ..... .....
For Android, change cocos2d / cocos / platform / android / CCApplication-android.cpp
LanguageType Application::getCurrentLanguage() { std::string languageName = getCurrentLanguageJNI(); const char* pLanguageName = languageName.c_str(); const char* languageCode = getCurrentLanguageCode(); LanguageType ret = LanguageType::ENGLISH; if (0 == strcmp("zh", languageCode)) { if (languageName.find("TW") != std::string::npos) { ret = LanguageType::CHINESE_TRADITIONAL; } else { ret = LanguageType::CHINESE_SIMPLIFIED; } } else if (0 == strcmp("en", languageCode)) { ret = LanguageType::ENGLISH; } else if (0 == strcmp("fr", languageCode)) ..... .....
and also change libcocos2d / org / cocos2dx / lib / Cocos2dxHelper.java
public static String getCurrentLanguage() { // This would return language code as well as region code, eg zh_CN return Locale.getDefault().toString(); }
source share