简体   繁体   English

xcode / iphone中的字符串和语言

[英]strings and languages in xcode/iphone

Hi I have a problem with my strings and I have already checked this link and did what was told there but it doesn't work 嗨,我的琴弦有问题,我已经检查了此链接,并按提示进行了操作,但无法正常工作

So for the xib files I have a diferent version for each language and it works. 因此,对于xib文件,我对每种语言都有不同的版本,并且可以正常工作。 but I have also a file named Localization.strings which for now only contains one string: 但我还有一个名为Localization.strings的文件,该文件目前仅包含一个字符串:

"password" = "passwords are not the same"; “ password” =“密码不相同”;

Then in my code I try to access the localized string: 然后在我的代码中,我尝试访问本地化的字符串:

NSString *tp=[[NSString alloc] initWithString:NSLocalizedString(@"password", nil)];

so tp is supposed to have the string "passwords are not the same" but no it returns "password". 因此,tp应该具有字符串“ passwords is not same”,但不返回“ password”。 I have been wondering if it is the right way to write strings maybe you have to write the value itself on the left side??? 我一直在想这是否是写字符串的正确方法,也许您必须在左侧写值本身? Anyway I have two versions spanish and english and in both the same thing happens. 无论如何,我有两种版本的西班牙语和英语,并且发生在同一件事中。 I have deleted app from the iphone cleaned, changed language and reinstalled and nothing works. 我已从iPhone删除了应用程序,已清理,更改语言并重新安装,但没有任何效果。

thanks 谢谢

You problem is the naming of your strings -file. 您的问题是字符串 -file的命名。 The default file that NSLocalizedString() do it's lookup in is Localizable.strings . NSLocalizedString()进行查找的默认文件是Localizable.strings

So rename Localization.strings to Localizable.string . 因此,将Localization.strings重命名为Localizable.string You could also use a specific file for your lookup if you want too (if you for example split your localized strings into several strings -files). 如果需要的话,也可以使用特定的文件进行查找(例如,如果将本地化的字符串拆分为多个字符串 -files)。 Using: 使用方法:

NSString *tp = NSLocalizedStringFromTable(@"password", @"Localization", nil);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM