Improve ios language detection
This commit is contained in:
parent
86d0a76eda
commit
524456d7ba
19
ios/RNI18n.m
19
ios/RNI18n.m
|
@ -6,8 +6,23 @@ RCT_EXPORT_MODULE();
|
|||
|
||||
- (NSString*) getCurrentLocale
|
||||
{
|
||||
NSString *localeString=[[NSLocale preferredLanguages] objectAtIndex:0];
|
||||
return localeString;
|
||||
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;
|
||||
}
|
||||
|
||||
- (NSDictionary *)constantsToExport
|
||||
|
|
Loading…
Reference in New Issue