Indoor
Indoor

Reputation: 561

Ho to get month/weekday symbols from NSDateFormatter in current language (iPhone)

In particular I'm interested in shortStandaloneWeekdaySymbols. I'm using this code:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSArray *shortWeekdaySymbols = [dateFormatter shortStandaloneWeekdaySymbols];

But if iPhone region format is set to US but language to French/German/any other, NSDateFormatter returns English strings (mon tue ...). But I want to respect the language settings and get weekday names in the current language (standard Clock app does this for example). Is this possible?

The only way I can think of to do this would be to get the current user language (how?) and set locale on the date formatter to this language's region.

Upvotes: 1

Views: 5943

Answers (2)

Alex Curylo
Alex Curylo

Reputation: 4770

The only way you can think of, "get the current user language (how?) and set locale on the date formatter to this language's region" is correct. This is how.

[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0]] autorelease]];

Upvotes: 10

tt.Kilew
tt.Kilew

Reputation: 6084

Try to look here Detecting current iPhone input language

Upvotes: 0

Related Questions