You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/07/14 21:37:21 UTC

git commit: CB-4602 ios: Use normalized values for getPreferredLanguage.

Repository: cordova-plugin-globalization
Updated Branches:
  refs/heads/master bf3b9d778 -> bbed836ec


CB-4602 ios: Use normalized values for getPreferredLanguage.

close #15


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/bbed836e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/bbed836e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/bbed836e

Branch: refs/heads/master
Commit: bbed836ec5368a135036765eb801c0ead00426d9
Parents: bf3b9d7
Author: Eric Weiterman <ew...@us.ibm.com>
Authored: Thu Jul 3 11:10:50 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Jul 14 15:37:07 2014 -0400

----------------------------------------------------------------------
 src/ios/CDVGlobalization.m | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/bbed836e/src/ios/CDVGlobalization.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVGlobalization.m b/src/ios/CDVGlobalization.m
index 8bc53e4..5afa700 100644
--- a/src/ios/CDVGlobalization.m
+++ b/src/ios/CDVGlobalization.m
@@ -40,6 +40,20 @@
     NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0];
 
     if (language) {
+        //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]];
+            }
+        }
+        
         language = [language stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
 
         NSDictionary* dictionary = [NSDictionary dictionaryWithObject:language forKey:@"value"];