你可能知道iOS 8需要NSLocationWhenInUseUsageDescription键来使用用户的位置。我已经添加了这个键和一些一般信息到我的信息plist。
如何在plist文件中使用翻译字符串?
——更新——
我已经有一个Localizable字符串。我只是想知道我能不能用一些 NSLocalizedString(MYSTRING,nil)在plist字符串内。我知道我可以创建多个文件的信息。plist的本地化,但我想知道是否有一个更简单的方法。
你可能知道iOS 8需要NSLocationWhenInUseUsageDescription键来使用用户的位置。我已经添加了这个键和一些一般信息到我的信息plist。
如何在plist文件中使用翻译字符串?
——更新——
我已经有一个Localizable字符串。我只是想知道我能不能用一些 NSLocalizedString(MYSTRING,nil)在plist字符串内。我知道我可以创建多个文件的信息。plist的本地化,但我想知道是否有一个更简单的方法。
当前回答
如果有些东西不工作,请确保您添加:
“本地化资源可以混合”= YES
进入info.plist。在我的例子中是InfoPlist。Strings文件被忽略了。
其他回答
除了已接受的答案(项目在Flutter上,但基本与本地相同):
我有文件夹Base。lproj, en。lproj xx.kproj。等等。每个字符串。 这个文件有这样的行(键周围没有引号,末尾有一个分号):
NSLocationWhenInUseUsageDescription = "我解释为什么我需要这个";
检查你的你的项目>你的语言:
另外,检查项目。pbxproj文件,位于XXX.xcodeproj/project.pbxproj: 它应该有你所有的语言代码(en, fr等)
但即便如此,它也没有起作用。最后,我注意到信息中的CFBundleLocalizations键。plist文件。(要在XCode中以原始键值的形式打开它,请在信息栏上用鼠标右键。plist文件->打开作为>源代码) 确保数组中的值是代码而不是完整的单词,例如fr而不是French等。
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>ru</string>
<string>lv</string>
</array>
再次检查您的设备是否设置为您正在测试的语言。干杯
注:“开发语言”不会影响您的问题,不要费心更改它。
iOS本地化。plist
如果在InfoPlist.string中设置key,可以跳过在.plist中定义key
.plist
InfoPlist.string
"NSPhotoLibraryAddUsageDescription" = "To download image";
逐步本地化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文件!
正如RGML所说,您可以创建一个InfoPlist。字符串,本地化它,然后添加你的键和值,像这样: "NSLocationWhenInUseUsageDescription" = "Help To locate me!";
它将添加到您的信息的关键。Plist指定的语言。
在我的情况下,本地化没有工作,原因是名称中的'-'符号。 例如:“aero-Info.plist” 和本地化文件:“aero-InfoPlist。字符串”和“aeroInfoPlist。字符串“没有工作。