这里我如何修改cocos2d-x代码来区分简化和传统中文。 注意, 这是用于cocos2d- x v3. 0+ 的 cocos2d- x v3. 0+ 。
对于iOS, 修改cocos2d_libs.xcodeproj/platform/ios/ application-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;
}
.....
.....
对于机器人,修改cocos2d/cocos/platform/androd/ application-androd.cpp 修改cocos2d/cococs/platform/and和crod/ application-androd.cpp 修改cocos2d/cocococs/platf/platf/andcoplication-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))
{
/** Change the following lines */
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))
.....
.....
并修改 libcocos2d/org/cococos2dx/lib/Cocos2dxHelper.java
public static String getCurrentLanguage() {
// This would return language code as well as region code, e.g. zh_CN
return Locale.getDefault().toString();
}