iphone - 如何在我的应用程序中使用 UIKit 本地化字符串

标签 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));

这将从 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/UIKit.framework

读取字符串文件

以下语言在 NSUserDefaultUIKit.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];

关于iphone - 如何在我的应用程序中使用 UIKit 本地化字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6909885/

相关文章:

iPhone 等待动画结束

iphone - writeToFile 未将新条目保存到 plist 中

php - iOS 到 PHP 的错误编码(非英语变成乱码)

ios - UIAlertView 中的键盘关闭动画

iphone - 需要帮助呈现 View Controller

ios - 从后台线程显示的 UIAlertView 没有委托(delegate)创建 EXC_BAD_ACCESS

iOS - 未调用警报 View 的 segue

iphone - 在Interface Builder中访问animationDuration和animationRepeatCount

iphone - 如何在 iPhone 上将 UIWebView 的内容居中

ios - 试图用未知的演示者解雇 UIAlertController