有Swift相当于NSLocalizedString(...)?在Objective-C,我们通常使用:
NSString *string = NSLocalizedString(@"key", @"comment");
Run Code Online (Sandbox Code Playgroud)
我怎样才能在Swift中实现同样的目标?我发现了一个功能:
func NSLocalizedString(
key: String,
tableName: String? = default,
bundle: NSBundle = default,
value: String = default,
#comment: String) -> String
Run Code Online (Sandbox Code Playgroud)
但是,它很长并且根本不方便.
我一直在我的应用程序中使用本地化,但由于某种原因,一些字符串(不是所有字符串)都不会翻译,我看到键而不是值.我试图通过这样做来检查应用程序是否找到了本地化文件:
NSString *enPath = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
NSString *hePath = [[NSBundle mainBundle] pathForResource:@"he" ofType:@"lproj"];
NSString *ruPath = [[NSBundle mainBundle] pathForResource:@"ru" ofType:@"lproj"];
NSString *esPath = [[NSBundle mainBundle] pathForResource:@"es" ofType:@"lproj"];
NSString *frPath = [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
NSString *arPath = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
Run Code Online (Sandbox Code Playgroud)
而且没有一个是零.
我已经检查了本地化文件的名称,Localizable.strings它应该是这样的.还要检查文件中是否存在密钥Localizable.strings,确实存在.
我也尝试过:
也尝试做这个问题的一切.
重要的是要说这不仅仅是模拟器/缓存问题.它也在下载应用程序的设备上显示.(我有企业帐户).
我还能做些什么来识别或解决问题?
localization objective-c localizable.strings nslocalizedstring ios
我创建两个Localizable.strings文件,一个用于英语,第二个用于阿拉伯语:
/* The number 1 */
"LABEL_ONE" = "label number one";
Run Code Online (Sandbox Code Playgroud)
我使用此代码来获取字符串值:
[self.Lable1 setText:NSLocalizedString(@"LABEL_ONE", @"The number 1")];
Run Code Online (Sandbox Code Playgroud)
但应用程序显示"LABEL_ONE"而不是"标签第一"?有什么问题 ?谢谢
我有:
-(IBAction)about {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"About", @"Title of AlertView")
message:@"App name \n© My name \n2010"
delegate:self
cancelButtonTitle:NSLocalizedString(@"Back", @"Cancel Button Title")
otherButtonTitles:nil];
[alert show];
[alert release];
}
Run Code Online (Sandbox Code Playgroud)
在Localizable.strings中:
/* Title of AlertView */
"About" = "Über";
/* Cancel Button Title */
"Back" = "Zurück";
Run Code Online (Sandbox Code Playgroud)
我的问题:当语言是德语时它是德语但是当我将语言改为英语时,警报视图仍然是德语
怎么了?