본문 바로가기
프로그래밍/iOS

localize

by 백룡화검 2012. 2. 17.

출처 : http://stackoverflow.com/questions/1669645/how-to-force-nslocalizedstring-to-use-a-specific-language

I have found another solution that allows you to update the language strings, w/o restarting the app and compatible with genstrings:

Put this macro in the Prefix.pch:

#define currentLanguageBundle [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"]]



and where ever you need a localized string use:

NSLocalizedStringFromTableInBundle(@"GalleryTitleKey", nil, currentLanguageBundle, @"")

To set the language use:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"de"] forKey:@"AppleLanguages"];

Works even with consecutive language hopping like:

NSLog(@"test %@", NSLocalizedStringFromTableInBundle(@"NewKey", nil, currentLanguageBundle, @""));
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"fr"] forKey:@"AppleLanguages"];
NSLog(@"test %@", NSLocalizedStringFromTableInBundle(@"NewKey", nil, currentLanguageBundle, @""));
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"it"] forKey:@"AppleLanguages"];
NSLog(@"test %@", NSLocalizedStringFromTableInBundle(@"NewKey", nil, currentLanguageBundle, @""));
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"de"] forKey:@"AppleLanguages"];
NSLog(@"test %@", NSLocalizedStringFromTableInBundle(@"NewKey", nil, currentLanguage
http://stackoverflow.com/questions/1669645/how-to-force-nslocalizedstring-to-use-a-specific-language

'프로그래밍 > iOS' 카테고리의 다른 글

iPhone 에서 OAuth 라이브러리 사용하기  (0) 2012.02.29
OAuthConsumer를 이용한 xAuth  (0) 2012.02.29
Advance Localization in ios apps  (0) 2012.02.17
로컬라이징  (0) 2012.02.17
문자열 지역화  (0) 2012.02.17