2013-02-26 15 views
1

我有一個iOS應用程序,我需要爲en_NZ(澳大利亞)本地化en_NZ(新西蘭)本地化使用相同的資源。iPhone上的默認語言環境(en_NZ到en_AU)

而不是重複我的資源文件是否有辦法讓我這樣做,如果有人與en_NZ的地區使用應用程序它將默認爲en_AU資源?

+0

這可能是你尋找什麼http://stackoverflow.com/a/13017789/786845 – Shaun 2013-02-26 06:08:34

+0

那麼,這是否意味着在en_NZ信息的plist我指定EN_AU作爲本地開發區域? – SomeGuy 2013-02-26 06:24:54

回答

0

您可以用下面的辦法:
1)創建EN_AU資源

2)檢查,如果當前區域是en_NZ

NSString *currentLanguage = [[NSLocale preferredLanguages] objectAtIndex:0]; 
// or 
NSString *langID = [[NSLocale preferredLanguages] objectAtIndex:0]; 
NSString *lang = [[NSLocale currentLocale] displayNameForKey:NSLocaleLanguageCode value:langID]; 

NSBundle *xBundle; 

3)的情況下,en_NZ:

// find the path to the bundle based on the locale 
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings" inDirectory:nil forLocalization:@"en_AU"]; 

// load it! 
xBundle = [[NSBundle alloc] initWithPath:[bundlePath stringByDeletingLastPathComponent]]; 

4)如果不是en_NZ:

xBundle = nil; 

5)在代碼中使用:

NSLocalizedStringFromTableInBundle(@"yourStr2Localize", nil, xBundle, nil);  
1

試試這個:

1)獲取郎

NSUserDefaults* apple_defaults = [NSUserDefaults standardUserDefaults]; 
    NSArray* languagesList = [apple_defaults objectForKey: @"AppleLanguages"]; 
    NSString* lang = [languagesList objectAtIndex: 0]; 

2)然後轉換他

if ([lang isEqualToString:@"en_NZ"]) 
    { 
     lang = @"en_AU"; 
    } 

你可以使用lang爲您的應用程序爲EN_AU代替en_NZ

相關問題