mirror of
https://github.com/status-im/react-native-i18n.git
synced 2025-01-24 02:50:10 +00:00
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*) getCurrentLocale
|
||||||
{
|
{
|
||||||
NSString *localeString=[[NSLocale preferredLanguages] objectAtIndex:0];
|
NSString *preferredLanguage = [[NSLocale preferredLanguages] objectAtIndex:0];
|
||||||
return localeString;
|
|
||||||
|
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
|
- (NSDictionary *)constantsToExport
|
||||||
|
Loading…
x
Reference in New Issue
Block a user