2011-12-02 1 views

답변

3

AppleLanguages의 값을 변경을 통해 언어를 변경할 수 있었다. 현지화 된 텍스트로 고유 한 NSBundle을로드하고 대신 해당 NSBundle을 사용할 수 있습니다. 현지화 된 언어 파일이 누락 된 경우 앱이 실행되지 않으므로 올바른 언어를 설정해야합니다. AppDelegate에 구현 위

, 사용자 정의 NSBundle 선언 추가 :

static NSBundle *bundle = nil; 

을 그리고 당신이 번들로 원하는 언어로드 :

[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"he", nil] forKey:@"AppleLanguages"]; 

NSLocale* locale = TTCurrentLocale(); 
NSString *path = [[NSBundle mainBundle] pathForResource:[locale localeIdentifier] ofType:@"lproj" ]; 
bundle = [[NSBundle bundleWithPath:path] retain]; 

당신은 당신의 AppDelegate에에서 사용자 지정 기능을 추가 할 것 NSLocalizedString 대신에 지역화 된 텍스트도 얻으십시오.

/////////////////////////////////////////////////////////////////////////////////////////////////// 
+ (NSString*)get:(NSString*)key { 
    return [bundle localizedStringForKey:key value:nil table:nil]; 
} 

더 쉽게 작업하기 위해 pch 파일에 정적 함수를 추가 할 수 있습니다.

#import "AppDelegate.h" 

#define MyLocalizedString(key, alt) [AppDelegate get:key] 
+0

여기서 두 번째 코드 블록을 삽입합니까? 내 애플 리케이션 대리인에서? 그리고 "changeLanguageToSpanish"버튼에 무엇을 넣을 수 있습니까? – KKendall

+0

이 아직 관련성이 있습니까? – Dejell