mirror of
https://github.com/status-im/react-native-languages.git
synced 2025-01-14 18:24:30 +00:00
37 lines
817 B
Objective-C
Executable File
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
|