mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5847 from newnon/develop_small_improvements
Adds getCurrentLanguageCode() which returns iso 639-1 language code
This commit is contained in:
commit
da0c15c982
|
@ -100,6 +100,14 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual LanguageType getCurrentLanguage() = 0;
|
virtual LanguageType getCurrentLanguage() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get current language iso 639-1 code
|
||||||
|
@return Current language iso 639-1 code
|
||||||
|
* @js NA
|
||||||
|
* @lua NA
|
||||||
|
*/
|
||||||
|
virtual const char * getCurrentLanguageCode() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get target platform
|
@brief Get target platform
|
||||||
* @js NA
|
* @js NA
|
||||||
|
|
|
@ -86,6 +86,14 @@ Application* Application::sharedApplication()
|
||||||
return Application::getInstance();
|
return Application::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Application::getCurrentLanguageCode()
|
||||||
|
{
|
||||||
|
static char code[3]={0};
|
||||||
|
strncpy(code,getCurrentLanguageJNI().c_str(),2);
|
||||||
|
code[2]='\0';
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
LanguageType Application::getCurrentLanguage()
|
LanguageType Application::getCurrentLanguage()
|
||||||
{
|
{
|
||||||
std::string languageName = getCurrentLanguageJNI();
|
std::string languageName = getCurrentLanguageJNI();
|
||||||
|
|
|
@ -73,6 +73,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual LanguageType getCurrentLanguage();
|
virtual LanguageType getCurrentLanguage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get current language iso 639-1 code
|
||||||
|
@return Current language iso 639-1 code
|
||||||
|
*/
|
||||||
|
virtual const char * getCurrentLanguageCode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get target platform
|
@brief Get target platform
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -75,6 +75,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual LanguageType getCurrentLanguage();
|
virtual LanguageType getCurrentLanguage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get current language iso 639-1 code
|
||||||
|
@return Current language iso 639-1 code
|
||||||
|
*/
|
||||||
|
virtual const char * getCurrentLanguageCode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get target platform
|
@brief Get target platform
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -78,6 +78,21 @@ Application* Application::sharedApplication()
|
||||||
return Application::getInstance();
|
return Application::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Application::getCurrentLanguageCode()
|
||||||
|
{
|
||||||
|
static char code[3]={0};
|
||||||
|
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];
|
||||||
|
[languageCode getCString:code maxLength:2 encoding:NSASCIIStringEncoding];
|
||||||
|
code[2]='\0';
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
LanguageType Application::getCurrentLanguage()
|
LanguageType Application::getCurrentLanguage()
|
||||||
{
|
{
|
||||||
// get the current language and country config
|
// get the current language and country config
|
||||||
|
|
|
@ -151,6 +151,20 @@ Application* Application::sharedApplication()
|
||||||
return Application::getInstance();
|
return Application::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Application::getCurrentLanguageCode()
|
||||||
|
{
|
||||||
|
static char code[3]={0};
|
||||||
|
char *pLanguageName = getenv("LANG");
|
||||||
|
if (!pLanguageName)
|
||||||
|
return "en";
|
||||||
|
strtok(pLanguageName, "_");
|
||||||
|
if (!pLanguageName)
|
||||||
|
return "en";
|
||||||
|
strncpy(code,pLanguageName,2);
|
||||||
|
code[2]='\0';
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
LanguageType Application::getCurrentLanguage()
|
LanguageType Application::getCurrentLanguage()
|
||||||
{
|
{
|
||||||
char *pLanguageName = getenv("LANG");
|
char *pLanguageName = getenv("LANG");
|
||||||
|
|
|
@ -72,6 +72,13 @@ public:
|
||||||
/* override functions */
|
/* override functions */
|
||||||
virtual LanguageType getCurrentLanguage();
|
virtual LanguageType getCurrentLanguage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get current language iso 639-1 code
|
||||||
|
@return Current language iso 639-1 code
|
||||||
|
*/
|
||||||
|
virtual const char * getCurrentLanguageCode();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Resource root path.
|
* Sets the Resource root path.
|
||||||
* @deprecated Please use FileUtils::getInstance()->setSearchPaths() instead.
|
* @deprecated Please use FileUtils::getInstance()->setSearchPaths() instead.
|
||||||
|
|
|
@ -80,6 +80,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual LanguageType getCurrentLanguage();
|
virtual LanguageType getCurrentLanguage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get current language iso 639-1 code
|
||||||
|
@return Current language iso 639-1 code
|
||||||
|
*/
|
||||||
|
virtual const char * getCurrentLanguageCode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get target platform
|
@brief Get target platform
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -134,6 +134,21 @@ Application* Application::sharedApplication()
|
||||||
return Application::getInstance();
|
return Application::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Application::getCurrentLanguageCode()
|
||||||
|
{
|
||||||
|
static char code[3]={0};
|
||||||
|
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];
|
||||||
|
[languageCode getCString:code maxLength:2 encoding:NSASCIIStringEncoding];
|
||||||
|
code[2]='\0';
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
LanguageType Application::getCurrentLanguage()
|
LanguageType Application::getCurrentLanguage()
|
||||||
{
|
{
|
||||||
// get the current language and country config
|
// get the current language and country config
|
||||||
|
|
|
@ -190,6 +190,16 @@ LanguageType Application::getCurrentLanguage()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Application::getCurrentLanguageCode()
|
||||||
|
{
|
||||||
|
LANGID lid = GetUserDefaultUILanguage();
|
||||||
|
const LCID locale_id = MAKELCID(lid, SORT_DEFAULT);
|
||||||
|
static char code[3] = { 0 };
|
||||||
|
GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, code, sizeof(code));
|
||||||
|
code[2] = '\0';
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
Application::Platform Application::getTargetPlatform()
|
Application::Platform Application::getTargetPlatform()
|
||||||
{
|
{
|
||||||
return Platform::OS_WINDOWS;
|
return Platform::OS_WINDOWS;
|
||||||
|
|
|
@ -68,6 +68,8 @@ public:
|
||||||
virtual void setAnimationInterval(double interval);
|
virtual void setAnimationInterval(double interval);
|
||||||
virtual LanguageType getCurrentLanguage();
|
virtual LanguageType getCurrentLanguage();
|
||||||
|
|
||||||
|
virtual const char * getCurrentLanguageCode();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Get target platform
|
@brief Get target platform
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
|
|
||||||
@interface AppController : NSObject <UIApplicationDelegate> {
|
@interface AppController : NSObject <UIApplicationDelegate> {
|
||||||
UIWindow *window;
|
UIWindow *window;
|
||||||
RootViewController *viewController;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property(nonatomic, readonly) RootViewController* viewController;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -53,20 +53,20 @@ static AppDelegate s_sharedApplication;
|
||||||
numberOfSamples: 0];
|
numberOfSamples: 0];
|
||||||
|
|
||||||
// Use RootViewController manage CCEAGLView
|
// Use RootViewController manage CCEAGLView
|
||||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
_viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
||||||
viewController.wantsFullScreenLayout = YES;
|
_viewController.wantsFullScreenLayout = YES;
|
||||||
viewController.view = eaglView;
|
_viewController.view = eaglView;
|
||||||
|
|
||||||
// Set RootViewController to window
|
// Set RootViewController to window
|
||||||
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
|
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
|
||||||
{
|
{
|
||||||
// warning: addSubView doesn't work on iOS6
|
// warning: addSubView doesn't work on iOS6
|
||||||
[window addSubview: viewController.view];
|
[window addSubview: _viewController.view];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// use this method on ios6
|
// use this method on ios6
|
||||||
[window setRootViewController:viewController];
|
[window setRootViewController:_viewController];
|
||||||
}
|
}
|
||||||
|
|
||||||
[window makeKeyAndVisible];
|
[window makeKeyAndVisible];
|
||||||
|
|
Loading…
Reference in New Issue