mirror of
https://github.com/status-im/react-native-i18n.git
synced 2025-01-09 11:45:54 +00:00
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"
|
#import "RNI18n.h"
|
||||||
|
|
||||||
@implementation RNI18n
|
@implementation RNI18n
|
||||||
@ -6,15 +7,23 @@ RCT_EXPORT_MODULE();
|
|||||||
|
|
||||||
- (NSDictionary *)constantsToExport {
|
- (NSDictionary *)constantsToExport {
|
||||||
NSArray *preferredLanguages = [NSLocale preferredLanguages];
|
NSArray *preferredLanguages = [NSLocale preferredLanguages];
|
||||||
NSMutableArray *languages = [NSMutableArray array];
|
|
||||||
|
|
||||||
for (id language in preferredLanguages) {
|
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
|
||||||
[languages addObject:[language stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
|
return @{
|
||||||
|
@"language": [preferredLanguages objectAtIndex:0],
|
||||||
|
@"languages": preferredLanguages
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableArray *forcedLanguageTags = [NSMutableArray array];
|
||||||
|
|
||||||
|
for (id l in preferredLanguages) {
|
||||||
|
[forcedLanguageTags addObject:[l stringByReplacingOccurrencesOfString:@"_" withString:@"-"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return @{
|
return @{
|
||||||
@"language": [languages objectAtIndex:0],
|
@"language": [forcedLanguageTags objectAtIndex:0],
|
||||||
@"languages": languages
|
@"languages": forcedLanguageTags
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user