2011-02-25 1 views
5

저는 iPhone 앱을 현지화/국제화하는 과정에 있으며 질문이 있습니다. 내 앱의 한 곳에서 올해의 12 개월 목록을 보여줍니다. 현재 비 지역화 상태이므로 NSArray에 1 월부터 12 월까지 하드 코딩됩니다. NSCalendar 프로그래밍 방식으로이 NSArray 개월 사용자의 로캘을 기반으로 작성하고 싶습니다. 이 작업을 수행하는 가장 좋은 방법은 무엇입니까?프로그래밍 방식으로 현지화 된 달력 월 이름의 NSArray를 빌드하는 방법은 무엇입니까?

답변

11

당신은 NSDateFormatter에서 달의 지역화 된 이름을 얻을 수 있습니다 : 그냥 직접 달 수,

NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
for (int i = 0; i < 12; ++i) { 
    NSString *monthName = [[df monthSymbols] objectAtIndex:i]; 
    [...] 
} 
[df release]; 
+4

멋진 사용! 안타깝게도 시뮬레이터에서는 작동하지 않습니다. 잘못된 방법 이었지만 ... 제가 장치에서 시도 할 때까지 ... tks Volker – meronix

+0

시뮬레이터에서 작동하지 않는다고 언급 해 주셔서 감사합니다. –

2

반복 할 필요가 없습니다를 :

NSDateFormatter dateFormatter = [[NSDateFormatter alloc] init]; 
NSLog(@"Months = %@", dateFormatter.monthSymbols); 

스위프트 :

let dateFormatter = NSDateFormatter() 
print("Months = \(dateFormatter.monthSymbols)") 
0

스위프트 버전 .... 놀이터에서 시도했습니다

로케일을 제공하거나 결과

var str = "Hello, playground" 

var formatter = NSDateFormatter() 

formatter.locale = NSLocale(localeIdentifier: "sv_SE") 
//formatter.locale = NSLocale.currentLocale() // use this to find it automatically 

print(formatter.monthSymbols) 

currentlocale

"["januari", "februari", "mars", "april", "maj", "juni", "juli", "augusti", "september", "oktober", "november", "december"]\n"