What you want is the current language, the following code should return the code:
NSArray *languagesArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]; NSString *currentLanguage = [languagesArray objectAtIndex:0];
Then you can do the following
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.lproj/mydatabase.db", currentLanguage]];
You might want to check if a path exists and is it a valid file if you don’t use any default path, for example for English (en.lproj)
Edit: There is another way you can do this using your preferred NSLocale languages, because then you will get a list of preferred languages, so some updated code for the first bit would be:
NSArray *languagesArray = [NSLocale preferredLanguages]; NSString *currentLanguage = [languagesArray objectAtIndex:0];
You end up with something like this:
NSString *pathComponent = [NSString stringWithFormat:@"%@.lproj/mydatabase.db", currentLanguage]; NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pathComponent]; NSString *activePath = nil;
Please note that the above code has not been verified, but should be sufficient. You may need to change it a bit ...
source share