Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17885] iOS 8.1: Titanium.Locale.currentLanguage only returns "en" as language

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionNot Our Bug
Resolution Date2014-10-29T07:52:12.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
LabelsTCSupportTriage
Reporteraee Q
AssigneeEric Merriman
Created2014-10-20T05:54:26.000+0000
Updated2017-03-23T21:19:20.000+0000

Description

In IOS 8.1 simulator (not on device), Titanium.Locale.currentLanguage can only return "en", no matter what the system language is set to. This is the code that sets the default locale: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiLocale.m#L31

Comments

  1. Ingo Muschenetz 2014-10-20

    You might review TIDOC-1162 for an alternate approach.
  2. aee Q 2014-10-21

    Ti.Locale.currentLanguage returns same result. But it is ok on ios8.1 device.
  3. Shuo Liang 2014-10-21

    Tested with Ti.Locale.currentLanguage on Xocde 6, iPhone 6 simulator. It works well.
  4. aee Q 2014-10-21

    Yes,Xocde 6 is ok, only on xcode6.1,ios8.1 simulator
  5. Ingo Muschenetz 2014-10-21

    [~aee] Please provide a code sample, and you say it _only_ fails on iOS 8.1 simulator, not on 8.1 device? [~sliang] can you please test on Xcode 6.1 with iOS 8.1?
  6. Shuo Liang 2014-10-22

    Tested with Xcode 6.1, problem can be reproduced.

    Reproduced Step:

    1.Update Xcode to 6.1. 2.Run the following simple app on iOS 8.1 simulator. 3.Got "en" language result. 4.Change language setting to Chinese.

    Actual Result:

    Still got "en" language result.

    Expect Result:

    should be "zh-cn". Also tried French, same problem.
       var win = Ti.UI.createWindow({  
           backgroundColor: '#fff',
       });
        
       Ti.API.info(Ti.Locale.currentLanguage);
       alert(Ti.Locale.currentLanguage);
       
       win.open();
       
  7. Fokke Zandbergen 2014-10-22

    I just drafted up a project in Xcode 6.1 using both the [official](https://developer.apple.com/library/Mac/qa/qa1391/_index.html) and [Titanium](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiLocale.m#L31-L41)'s code:
           NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
           NSDictionary * globalDomain = [defaults persistentDomainForName:@"NSGlobalDomain"];
           NSArray * languages = [globalDomain objectForKey:@"AppleLanguages"];
           NSLog(@"%@\n", languages);
           
           NSArray* languages2 = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
           NSLog(@"%@\n", languages2);
       
    and ran this on my iPhone 6 running 8.1 that has Dutch (nl) as the default language and correctly got:
       2014-10-22 08:52:45.580 loale[764:229685] (
           nl,
           en
       )
       2014-10-22 08:52:45.581 loale[764:229685] (
           nl,
           en
       )
       
    Running the same code in iOS 8.1 Simulator gives:
       2014-10-22 08:59:03.854 loale[3687:210933] (null)
       2014-10-22 08:59:03.857 loale[3687:210933] (
           en
       )
       
    Running the same code in iOS 7.1 Simulator (build from Xcode 6.1) gives:
       2014-10-22 09:02:41.046 loale[3824:607] (
           nl,
           en,
           fr,
           de,
           "zh-Hans",
           "zh-Hant",
           ja,
           it,
           es,
           ko,
           pt,
           "pt-PT",
           da,
           fi,
           nb,
           sv,
           ru,
           pl,
           tr,
           uk,
           ar,
           hr,
           cs,
           el,
           he,
           ro,
           sk,
           th,
           id,
           ms,
           "en-GB",
           ca,
           hu,
           vi
       )
       2014-10-22 09:02:41.047 loale[3824:607] (
           nl,
           en,
           fr,
           de,
           "zh-Hans",
           "zh-Hant",
           ja,
           it,
           es,
           ko,
           pt,
           "pt-PT",
           da,
           fi,
           nb,
           sv,
           ru,
           pl,
           tr,
           uk,
           ar,
           hr,
           cs,
           el,
           he,
           ro,
           sk,
           th,
           id,
           ms,
           "en-GB",
           ca,
           hu,
           vi
       )
       
  8. Chee Kiat Ng 2014-10-24

    Thanks [~fokke] for the testing and results. After reviewing Xcode 6.1 release notes, simulator has some changes that might have caused this. https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/xc6_release_notes.html Particularly the following: *Settings changed in the Settings app on iOS Simulator may not persist. (18238018)* *In some situations, [NSLocale currentLocale] may return en_US instead of the chosen locale in the iOS 8.1 simulator. (18512161)* Which is why Titanium.Locale.currentLanguage works in device and NOT simulator.
  9. Lee Morris 2017-03-23

    Closing ticket with reference to the above comments.

JSON Source