Checking language

Hi there
Is there a way to know what’s the iphone language setting? I use it for my iphone apps to automatically enable the users language if available but I have no clue how this can be done with unity.

Joaquin

yes thats possible to find out through using the corresponding iOS native function in a plugin.

within unity: no

Actually you don’t need any plugin, you can get the language of your device with player prefs, simply put this in xcode, overwriting the previous function with this one

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
	NSString *currentLanguage = [languages objectAtIndex:0];
	
	[[NSUserDefaults standardUserDefaults] setObject:currentLanguage forKey:@"language"];
	[[NSUserDefaults standardUserDefaults] synchronize];
	
	printf_console("-> applicationDidFinishLaunching()\n");
	[self startUnity:application];
}

And then get the language in any unity script with

var languageString : String = PlayerPrefs.GetString("language");

would be wiser to have a function that gets this and returns it directly and put that in an own mm file

  1. This one here will get lost every single time you build without append, if you update to a new unity version etc
  2. playerprefs should commonly not be used out of my view unless really required becaues they are permanentely in ram and are loaded at application start
  3. Using a function to request it at any time also works with fast app switch and switching lnaguage while the app was running. this caching here won’t.

I agree with you in some points dreamora, but maybe beacuse I’m a programmer this solution is enough for my needs. Having a single string in memory won’t be a big deal.
Of course a plugin with a postprocess build that handles the code each time you make a new build is a better option, but is good to know more different ways to do the same thing