Improve ios language detection

This commit is contained in:
Mathieu Acthernoene 2017-03-30 01:46:08 +02:00
parent 86d0a76eda
commit 524456d7ba
1 changed files with 17 additions and 2 deletions

View File

@ -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