即时更改 iOS 应用程序的语言

问题描述:

我正在编写一个 iOS 应用程序,我希望用户能够在其中更改 UI 语言,而不受 iPhone 或 iPad 语言的影响.问题是,如何在语言更改时为当前显示的视图重新加载适当的 NIB 文件,以及如何加载适当的 .strings 文件以便 NSLocalizedString 正常工作?

I'm writing an iOS app, where I want the user to be able to change the UI language independent of the iPhone's or iPad's language. The question is, how do I reload the appropriate NIB file for the currently displayed view when the language changes and how do I load the appropriate .strings file so that NSLocalizedString works appropriately?

这应该可以解决问题,假设 de 是用户选择的新语言.还要确保您正在重新启动当前视图.

This should do the trick, assuming that de is the new language selected by the user. Also assure that you are reinitiating the current view.

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