你可能知道iOS 8需要NSLocationWhenInUseUsageDescription键来使用用户的位置。我已经添加了这个键和一些一般信息到我的信息plist。

如何在plist文件中使用翻译字符串?

——更新——

我已经有一个Localizable字符串。我只是想知道我能不能用一些 NSLocalizedString(MYSTRING,nil)在plist字符串内。我知道我可以创建多个文件的信息。plist的本地化,但我想知道是否有一个更简单的方法。


当前回答

使用InfoPlist时。字符串文件(在XCode中,它应该放在信息旁边。Plist文件-真实的文件位置可能在项目中的任何地方

)小心使用键的短名称进行翻译。

我试图使用隐私-相机使用描述,但工作密钥是NSCameraUsageDescription

其他回答

使用InfoPlist时。字符串文件(在XCode中,它应该放在信息旁边。Plist文件-真实的文件位置可能在项目中的任何地方

)小心使用键的短名称进行翻译。

我试图使用隐私-相机使用描述,但工作密钥是NSCameraUsageDescription

我强烈建议阅读苹果的指南,并查看以下列出的WWDC资源: 国际化与本土化主题

具体来说,当您向项目中添加一种新语言时,您有机会选择要包含哪些InfoPlist文件(如果您有多个目标,则会有多个Info plist文件)。你所需要做的就是点击本地化下的+,并选择一种新的语言来添加支持。

添加完成后,它将在适当的lproj目录中为给定语言创建必要的字符串文件。

——编辑

需要明确的是,iOS会根据用户当前选择的语言,将Plist条目的键作为本地化字符串文件中的键,为Plist文件替换字符串。

逐步本地化Info.plist:

Find in the Xcode the folder Resources (is placed in root) Select the folder Resources Then press the main menu File->New->File... Select in section "Resource" Strings File and press Next Then in Save As field write InfoPlist ONLY ("I" (eye) capital and "P" capital - the l (ell) after the P should not be capital) Then press Create Then select the file InfoPlist.strings that created in Resources folder and press in the right menu the button "Localize" Then you Select the Project from the Project Navigator and select the The project from project list In the info tab at the bottom you can as many as language you want (There is in section Localizations) The language you can see in Resources Folder To localize the values ("key") from info.plist file you can open with a text editor and get all the keys you want to localize You write any key as the example in any InfoPlist.strings like the above example

“NSLocationAlwaysAndWhenInUseUsageDescription”=“blabla”;

“NSLocationAlwaysUsageDescription”=“blabla2”;

这就是所有的工作,你已经本地化了你的信息。plist文件!

iOS本地化。plist

如果在InfoPlist.string中设置key,可以跳过在.plist中定义key

.plist

InfoPlist.string

"NSPhotoLibraryAddUsageDescription" = "To download image";

在我的情况下,本地化没有工作,原因是名称中的'-'符号。 例如:“aero-Info.plist” 和本地化文件:“aero-InfoPlist。字符串”和“aeroInfoPlist。字符串“没有工作。