English 中文(简体)
简化/传统中文
原标题:cocos2d-x localization simplified/traditional chinese

在iPhone的cocos2d中,我只需要使用“hans”和“hant”。 但在cocos2d-x中,

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;

指出只有中国人(简化/传统,也许)的zh(中国人)才有zh(简化/传统)

我怎样才能区分他们呢?

EDIT: 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/Cocos2dxHelper.java,

替换

return Locale.getDefault().getLanguage();

return Locale.getDefault().toString();

因此,您可以在下列应用中获得zh_CN、zh_TW::getCrentLanguage (), 另外,您必须更新应用中的应用:::getCrentLanguage () (地址为cocos2d-x-2.x.x/cocos2dx/platform/android/application.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;
}
问题回答

我测试了以下关于cocos2D Helloworld 的代码。 我可以使用“ 强势”- Hans < / 强势” 和“强势”- HANT < /强势” 来分离简化/传统代码。

步骤1. 在 Hello WorldLayer.m 中,您需要在顶部添加此行, 否则无法编译 :

#import <Foundation/NSLocale.h>

步骤2. 现在,你可以找到语言。例如,

-(id)init{
    NSString* currentLang = [[NSLocale preferredLanguages] objectAtIndex:0] ;
    NSLog(@"Language: %@", currentLang);
}

这里我如何修改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();
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签