react-native-i18n/ios/RNI18n.m

34 lines
782 B
Mathematica
Raw Normal View History

2017-03-29 23:31:43 +00:00
#import "RNI18n.h"
@implementation RNI18n
RCT_EXPORT_MODULE();
- (NSString*) getCurrentLocale
{
2017-03-29 23:46:08 +00:00
NSString *preferredLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
if ([preferredLanguage rangeOfString:@"-"].location != NSNotFound) {
return preferredLanguage;
}
if ([preferredLanguage rangeOfString:@"_"].location != NSNotFound) {
return [preferredLanguage stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
}
NSString *countryCode = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
if (countryCode != nil) {
return [NSString stringWithFormat:@"%@-%@", preferredLanguage, countryCode];
}
return preferredLanguage;
2017-03-29 23:31:43 +00:00
}
- (NSDictionary *)constantsToExport
{
return @{ @"locale": [self getCurrentLocale] };
}
@end