Zha*_*ang 8 iphone uialertview
我们正在构建iOS游戏,我们公司需要取消按钮,UIAlertView应始终根据用户的设备语言进行本地化.
看起来UIKit框架中有这样一个字符串,如何在我自己的应用程序中访问它?
或者,使用本地化取消按钮创建UIAlertView的任何其他方法?
谢谢
自己回答:
以下代码解决了问题:
NSBundle* uikitBundle = [NSBundle bundleForClass:[UIButton class]];
NSString *language = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
NSBundle *languageBundle = [NSBundle bundleWithPath:[uikitBundle pathForResource:language ofType:@"lproj"]];
NSLog(@"%@: %@", language, NSLocalizedStringFromTableInBundle(@"Cancel", @"Localizable", languageBundle, nil));
Run Code Online (Sandbox Code Playgroud)
这个从中读取字符串文件 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/UIKit.framework
以下语言NSUserDefault与UIKit.framework文件夹之间有不同的名称:fr en zh-Hans it de ja nl es pt-PT nb zh-Hant en-GB.它们应该由代码处理.
UIKit 中已有字符串的简单方法
NSBundle* uikitBundle = [NSBundle bundleForClass:[UIButton class]];
NSString *cancel = [uikitBundle localizedStringForKey:@"Cancel" value:nil table:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2614 次 |
| 最近记录: |