1 Reply
      Latest reply on Feb 17, 2018 12:45 PM by Macho Man Randy Savage
      toru239 Level 1 Level 1 (0 points)

        I found that I get a different value about current locale from NSLocale between iOS 11 and iOS 10.

         

        NSLocale.current.languageCode
        
        
        
        

         

        When I set device language to Japanese and English at setting application, I get "en" at iOS 11  "ja" at iOS 10.

        But after I add Japanese string files to my application (a.k.a Localizations), I get "ja" at iOS 11.

         

        This behavior is mentioned at StackOverflow, but are there any official references?

        https://stackoverflow.com/a/46206511/4834226

        > Under iOS 10 and earlier, currentLocale would directly represent the user's chosen language and region, regardless of what localizations your app supports.

        > iOS 11 fixes this inconsistency. While one could argue that this change breaks lots of apps that only support one (or just a few) language, it actually makes the app more consistent.

        • Re: NSLocale returns different current locale at iOS 11 and 10
          Macho Man Randy Savage Level 3 Level 3 (375 points)

          I think the change in behavior makes sense sort of for many things, but would be nice if there was a way to opt out and get the real device locale even if your app doesn't support the user's native language.

           

          For example something like this:

           

          +(NSLocale*)deviceLocale; //Device locale, even if the app is not localized in the given language.
          
          

           

          My app displays dates and I've had a couple users complain that they want the date formatted in the style of their language. Even though my app isn't localized in their language, they don't care, they want the date the way they want it.


          Does anyone know of a way to get the device locale like +currentLocale used to?

           

          Edit to answer my own question, below seems to work:

           

          NSString *localeID = NSLocale.preferredLanguages.firstObject;
          NSLocale *deviceLocale = [NSLocale localeWithLocaleIdentifier:localeID];
          //use the locale