ios - NSDateFormatter and current language in iOS11 -


it appears default behavior nsdateformatter has been changed in ios11. code used work , produced date formatter according selected iphone/ipad language prior ios11:

 _dateformatterinstance = [[nsdateformatter alloc] init];  _dateformatterinstance.timezone = [nstimezone systemtimezone]; 

looks in ios11 have explicitly specify locale property it:

 _dateformatterinstance = [[nsdateformatter alloc] init];  _dateformatterinstance.timezone = [nstimezone systemtimezone];  _dateformatterinstance.locale = [nslocale localewithlocaleidentifier:[[nslocale preferredlanguages] firstobject]]; 

can confirm findings?

this isn't problem nsdateformatter, it's change in how ios 11 supports localization.

under ios 11, [nslocale currentlocale] returns languages supported app's localizations. if app supports english (as base localization), no matter language user selects on device, currentlocale return english.

under ios 10 , earlier, currentlocale directly represent user's chosen language , region, regardless of localizations app supports.

classes such nsdateformatter default using nslocale currentlocale. no matter language app supported through localization, classes nsdateformatter show text in language set on device, different language being used app.

ios 11 fixes inconsistency. while 1 argue change breaks lots of apps support 1 (or few) language, makes app more consistent.

to make of clear, consider example. create simple test app base localization in english. if run app ios 10 , device's language set english, see english text , see dates formatted english. if change device's language french , restart app, user sees english text in app (since localization) dates show french month , weekday names.

now run same app under ios 11. ios 10, if device's language english see in english. if change device's language french , run app, ios 11 sees app supports english , currentlocale returns english, not french. user sees english text (due app's localization) , dates still in english.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -