2017-04-07 11:26:49 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
2017-03-29 23:31:43 +00:00
|
|
|
#import "RNI18n.h"
|
|
|
|
|
|
|
|
@implementation RNI18n
|
|
|
|
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
|
2017-05-17 10:48:51 +00:00
|
|
|
- (NSMutableArray *)toLanguageTags:(NSArray *)languages {
|
|
|
|
NSMutableArray *languageTags = [NSMutableArray array];
|
2017-03-29 23:46:08 +00:00
|
|
|
|
2017-05-17 10:48:51 +00:00
|
|
|
for (id l in languages) {
|
|
|
|
[languageTags addObject:[l stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
|
2017-04-07 11:26:49 +00:00
|
|
|
}
|
|
|
|
|
2017-05-17 10:48:51 +00:00
|
|
|
return languageTags;
|
|
|
|
}
|
2017-04-07 11:26:49 +00:00
|
|
|
|
2017-05-19 12:57:55 +00:00
|
|
|
- (NSArray *)getPreferredLanguages {
|
2017-05-17 10:48:51 +00:00
|
|
|
NSArray *preferredLanguages = [NSLocale preferredLanguages];
|
2017-03-29 23:46:08 +00:00
|
|
|
|
2017-05-19 12:57:55 +00: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-29 23:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|