Hello
I’ve come to need the use of getCurrentLanguage() method to have the I18n in a project. I realized it was made only to support English and Chinese.
I have made some little changes to extend it to the EFIGS’s languages. It is not a big modification but it may interest someone around here.
I made the changes for iPhone and Android, not for Wophone.
Changes in CCApplication_ios.mm
ccLanguageType CCApplication::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];
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;
}
return ret;
}
Changes in CCApplication_android.cpp
ccLanguageType CCApplication::getCurrentLanguage()
{
char* pLanguageName = getCurrentLanguageJNI();
ccLanguageType ret = kLanguageEnglish;
if (0 == strcmp("zh", pLanguageName))
{
ret = kLanguageChinese;
}
else if (0 == strcmp("en", pLanguageName))
{
ret = kLanguageEnglish;
}
else if (0 == strcmp("fr", pLanguageName))
{
ret = kLanguageFrench;
}
else if (0 == strcmp("it", pLanguageName))
{
ret = kLanguageItalian;
}
else if (0 == strcmp("de", pLanguageName))
{
ret = kLanguageGerman;
}
else if (0 == strcmp("es", pLanguageName))
{
ret = kLanguageSpanish;
}
return ret;
}
Changes in CCCommon.h
typedef enum LanguageType
{
kLanguageEnglish = 0,
kLanguageChinese,
kLanguageFrench,
kLanguageItalian,
kLanguageGerman,
kLanguageSpanish,
} ccLanguageType;