Skip to content

Commit

Permalink
Use built-in language code resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
koraktor committed Sep 21, 2015
1 parent cef59fe commit 5afee2c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions Suitcase/Classes/SCLanguage.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,26 @@ + (NSLocale *)currentLanguage {
return [NSLocale localeWithLocaleIdentifier:currentLanguage];
}

+ (void)setLanguage:(NSString *)lang {
NSRange dashRange = [lang rangeOfString:@"-"];
if (dashRange.location != NSNotFound) {
lang = [lang substringToIndex:dashRange.location];
}
+ (void)setLanguage:(NSString *)localeIdentifier {
NSString *languageCode = [NSLocale componentsFromLocaleIdentifier:localeIdentifier][(NSString *)kCFLocaleLanguageCode];

#if DEBUG
NSLog(@"Changing preferred language to: %@", lang);
NSLog(@"Changing preferred language to: %@", languageCode);
#endif

NSString *path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj" ];
NSString *path = [[NSBundle mainBundle] pathForResource:languageCode ofType:@"lproj" ];

if (path == nil) {
#if DEBUG
NSLog(@"%@ unavailable, falling back to en.", lang);
NSLog(@"%@ unavailable, falling back to en.", languageCode);
#endif

lang = @"en";
path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj" ];
languageCode = @"en";
path = [[NSBundle mainBundle] pathForResource:languageCode ofType:@"lproj" ];
}

bundle = [NSBundle bundleWithPath:path];
path = [iaskRootBundle pathForResource:lang ofType:@"lproj" ];
path = [iaskRootBundle pathForResource:languageCode ofType:@"lproj" ];
iaskBundle = [NSBundle bundleWithPath:path];
}

Expand Down

0 comments on commit 5afee2c

Please sign in to comment.