Avoid useless computations on iOS 9+
This commit is contained in:
parent
0a9afe87c2
commit
f7e5fb9caa
19
ios/RNI18n.m
19
ios/RNI18n.m
|
@ -1,3 +1,4 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "RNI18n.h"
|
||||
|
||||
@implementation RNI18n
|
||||
|
@ -6,15 +7,23 @@ RCT_EXPORT_MODULE();
|
|||
|
||||
- (NSDictionary *)constantsToExport {
|
||||
NSArray *preferredLanguages = [NSLocale preferredLanguages];
|
||||
NSMutableArray *languages = [NSMutableArray array];
|
||||
|
||||
for (id language in preferredLanguages) {
|
||||
[languages addObject:[language stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
|
||||
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
|
||||
return @{
|
||||
@"language": [preferredLanguages objectAtIndex:0],
|
||||
@"languages": preferredLanguages
|
||||
};
|
||||
}
|
||||
|
||||
NSMutableArray *forcedLanguageTags = [NSMutableArray array];
|
||||
|
||||
for (id l in preferredLanguages) {
|
||||
[forcedLanguageTags addObject:[l stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
|
||||
}
|
||||
|
||||
return @{
|
||||
@"language": [languages objectAtIndex:0],
|
||||
@"languages": languages
|
||||
@"language": [forcedLanguageTags objectAtIndex:0],
|
||||
@"languages": forcedLanguageTags
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue