Xcode iOS gets a list of all localizations

How to get a list of all available localizations?

I have an application with five localizations. I need to know if the current locale is on this list, and if not, back up it. But how do you know if the current locale is on this list?

+6
source share
2 answers

The easiest way to find out if the current locale is supported or not is to add a special β€œtest” line (for example, @"IsSupported" = @"Yes" ) to all five localizations that you support. Then a simple check will be performed:

 BOOL supported = [NSLocalizedString(@"IsSupported", nil) isEqualToString:@"Yes"]; 
+2
source

For me, the decision did not work if the language was not supported - the application simply returned to English and, since the IsSupported line was contained in the English line file, 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; } 
+8
source

All Articles