Reputation: 3556
How do I get a list of all available localizations?
I have an app with five localizations. I need to know whether the current locale is in that list and if not, create a fallback. But how do I find out if the current locale is in that list?
Upvotes: 8
Views: 3318
Reputation: 736
For me accepted solution didn't work, if Language was not supported - App simply fall back to English and, as English strings file contained "IsSupported" string - it returned "YES".
I had to use this solution
NSString* currentLanguage = [NSLocale preferredLanguages][0];
NSArray* supportedLocalizations = [[NSBundle mainBundle] localizations];
if ([supportedLocalizations containsObject:currentLanguage]) {
isLocalizedToCurrentLanguage = YES;
}
else {
isLocalizedToCurrentLanguage = NO;
}
Upvotes: 12
Reputation: 726489
The simplest way to find out if the current locale is supported or not would be to add a special "test" string (say, @"IsSupported" = @"Yes"
) to all five localizations that you support. Then a simple check will work:
BOOL supported = [NSLocalizedString(@"IsSupported", nil) isEqualToString:@"Yes"];
Upvotes: 2