Skip to content

Instantly share code, notes, and snippets.

@qwzybug
Created April 22, 2014 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwzybug/11189889 to your computer and use it in GitHub Desktop.
Save qwzybug/11189889 to your computer and use it in GitHub Desktop.
//
// 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