CB-9409 check that localeIdentifier has underscore
CB-9409 change the condition checking for underscore. This closes #39
github: close #39
diff --git a/src/ios/CDVGlobalization.m b/src/ios/CDVGlobalization.m
index 49691a0..7ba1f6f 100644
--- a/src/ios/CDVGlobalization.m
+++ b/src/ios/CDVGlobalization.m
@@ -39,14 +39,17 @@
//Format to match other devices
if(language.length <= 2) {
NSLocale* locale = [NSLocale currentLocale];
- NSRange underscoreIndex = [[locale localeIdentifier] rangeOfString:@"_" options:NSBackwardsSearch];
- NSRange atSignIndex = [[locale localeIdentifier] rangeOfString:@"@"];
- //If localeIdentifier did not contain @, i.e. did not have calendar other than Gregoarian selected
- if(atSignIndex.length == 0)
- language = [NSString stringWithFormat:@"%@%@", language, [[locale localeIdentifier] substringFromIndex:underscoreIndex.location]];
- else {
- NSRange localeRange = NSMakeRange(underscoreIndex.location, atSignIndex.location-underscoreIndex.location);
- language = [NSString stringWithFormat:@"%@%@", language, [[locale localeIdentifier] substringWithRange:localeRange]];
+ NSString* localeId = [locale localeIdentifier];
+ NSRange underscoreIndex = [localeId rangeOfString:@"_" options:NSBackwardsSearch];
+ NSRange atSignIndex = [localeId rangeOfString:@"@"];
+ if (underscoreIndex.location != NSNotFound) {
+ //If localeIdentifier did not contain @, i.e. did not have calendar other than Gregoarian selected
+ if(atSignIndex.length == 0)
+ language = [NSString stringWithFormat:@"%@%@", language, [localeId substringFromIndex:underscoreIndex.location]];
+ else {
+ NSRange localeRange = NSMakeRange(underscoreIndex.location, atSignIndex.location-underscoreIndex.location);
+ language = [NSString stringWithFormat:@"%@%@", language, [localeId substringWithRange:localeRange]];
+ }
}
}