运行时更改Three20中的语言/本地化

是否有可能在运行时更改Three20语言/本地化而不重新启动应用程序?

目前,我设法通过改变main.m中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]