Game Development Community

dev|Pro Game Development Curriculum

iTorque2D Code Snippet: localization

by Paul Jan · 01/11/2012 (6:38 pm) · 0 comments

A little something I added to iPhoneFileio.mm to expose the locale of the phone to Torquescript (yay localization)

iTorque2D 1.5

ConsoleFunction(getiPhoneCountryCode, const char *, 1, 1, "getiPhoneCountryCode() Returns the current country code of the iPhone")
{
    NSLocale *locale = [NSLocale currentLocale];
    NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
    
	const char* tOutput = [countryCode UTF8String];
    
    return tOutput;
}


ConsoleFunction(getiPhoneCountryName, const char *, 1, 1, "getiPhoneCountryName() Returns the current country name of the iPhone")
{
    NSLocale *locale = [NSLocale currentLocale];
    NSString *countryCode = [locale objectForKey: NSLocaleCountryCode];
    
    NSString *countryName = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
    
	const char* tOutput = [countryName UTF8String];
    
    return tOutput;
}


ConsoleFunction(getiPhoneCurrentLanguage, const char *, 1, 1, "getiPhoneCurrentLanguage() Returns the current language of the iPhone")
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLanguage = [languages objectAtIndex:0];
    
	const char* tOutput = [currentLanguage UTF8String];
    
    return tOutput;
}