36 lines
882 B
Mathematica
Raw Normal View History

2017-04-07 13:26:49 +02:00
#import <UIKit/UIKit.h>
2017-03-30 01:31:43 +02:00
#import "RNI18n.h"
@implementation RNI18n
RCT_EXPORT_MODULE();
- (NSMutableArray *)toLanguageTags:(NSArray *)languages {
NSMutableArray *languageTags = [NSMutableArray array];
2017-03-30 01:46:08 +02:00
for (id l in languages) {
[languageTags addObject:[l stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
2017-04-07 13:26:49 +02:00
}
return languageTags;
}
2017-04-07 13:26:49 +02:00
- (NSArray *)getPreferredLanguages {
NSArray *preferredLanguages = [NSLocale preferredLanguages];
2017-03-30 01:46:08 +02:00
return [[[UIDevice currentDevice] systemVersion] floatValue] >= 9
? preferredLanguages
: [self toLanguageTags:preferredLanguages];
}
- (NSDictionary *)constantsToExport {
return @{ @"languages": [self getPreferredLanguages] };
}
RCT_EXPORT_METHOD(getLanguages:(RCTPromiseResolveBlock)resolve
rejecter:(__unused RCTPromiseRejectBlock)reject) {
resolve([self getPreferredLanguages]);
2017-03-30 01:31:43 +02:00
}
@end