NSLocale currentLocale always returns “en_US” not user's current language

后端 未结 9 1678
夕颜
夕颜 2020-11-30 21:28

I\'m in the processes of internationalizing an iPhone app - I need to make programmatic changes to certain views based on what the user\'s current locale is. I\'m going nut

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 21:41

    I had an issue where formatting month names came out in english on a device set to french language.

    My solution was to use this:

        NSLocale *locale = [NSLocale localeWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0] ];
        [self.monthNameFormatter setLocale:locale];
        [self.monthNameFormatter setDateFormat:@"MMMM"];
        [self.monthNameFormatter stringFromDate:myDate];
    

提交回复
热议问题