Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically build NSArray of localized calendar month names?

I am in the process of localizing/internationalizing my iPhone app and have a question. In one place in my app, I show a list of the 12 months of the year. As it is in its currently non-localized state, I simply have the months January - December hard-coded into an NSArray. I'd like to use NSCalendar to programmatically build this NSArray of months based on the user's locale. What is the best way to do this?

like image 224
Jason Avatar asked Feb 25 '11 05:02

Jason


1 Answers

You can get the localized name of the month from the NSDateFormatter:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
for ( int i = 0; i < 12; ++i ) {
    NSString *monthName = [[df monthSymbols] objectAtIndex:i];
    [...]
}
[df release];
like image 169
Volker Voecking Avatar answered Oct 17 '22 01:10

Volker Voecking