react-native-languages/ios/ReactNativeLanguages.m
2017-10-09 14:51:06 +02:00

37 lines
817 B
Objective-C
Executable File

#import "ReactNativeLanguages.h"
#import <UIKit/UIKit.h>
@implementation ReactNativeLanguages
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (NSMutableArray *)ensureLanguageTags:(NSArray *)languages
{
NSMutableArray *sanitizedLanguages = [NSMutableArray array];
for (id language in languages) {
[sanitizedLanguages addObject:[language stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
}
return sanitizedLanguages;
}
- (NSDictionary *)constantsToExport
{
NSArray *preferredLanguages = [[[UIDevice currentDevice] systemVersion] floatValue] >= 9
? [NSLocale preferredLanguages]
: [self ensureLanguageTags:[NSLocale preferredLanguages]];
return @{
@"language": [preferredLanguages objectAtIndex:0],
@"languages": preferredLanguages
};
}
@end