Created
April 22, 2014 18:40
-
-
Save qwzybug/11189889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIApplication+DisplayedLanguage.m | |
// Crossfader | |
// | |
// Created by Devin Chalmers on 4/14/14. | |
// | |
// | |
#import "UIApplication+DisplayedLanguage.m.h" | |
#import "NSArray_Functional.h" | |
@implementation UIApplication (DJZ) | |
- (NSString *)displayedLanguage; | |
{ | |
static NSString *displayedLanguage = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
NSArray *supportedLanguages = [[NSBundle mainBundle] pathsForResourcesOfType:@"lproj" inDirectory:nil]; | |
supportedLanguages = [supportedLanguages mapNoNils:^id(NSString *path) { | |
return path.lastPathComponent.stringByDeletingPathExtension; | |
}]; | |
displayedLanguage = [[NSLocale preferredLanguages] firstObjectCommonWithArray:supportedLanguages]; | |
if (!displayedLanguage) displayedLanguage = @"en"; | |
}); | |
return displayedLanguage; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment