xcode 使用 .strings 文件的 NSLocationWhenInUseUsageDescription 本地化不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30454382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:12:04  来源:igfitidea点击:

NSLocationWhenInUseUsageDescription localization using .strings file not working

iosxcodelocalizationinfo.plist

提问by Can Poyrazo?lu

I've completed translating my app to Turkish using Base Localization. However, I also need to translate NSLocationWhenInUseUsageDescriptionkey in my Info.plist file. I did exactly what I did for everything else:

我已使用 Base Localization 将我的应用程序翻译成土耳其语。但是,我还需要翻译NSLocationWhenInUseUsageDescriptionInfo.plist 文件中的密钥。我做了我为其他所有事情所做的一切:

Went to File inspector and checked Turkish:

去文件检查员并检查土耳其语:

enter image description here

在此处输入图片说明

Then I went to the new strings resource and completed my translation by adding this key to the localization file:

然后我转到新的字符串资源并通过将此键添加到本地化文件来完成我的翻译:

enter image description here

在此处输入图片说明

"NSLocationWhenInUseUsageDescription" = "[my Turkish description of location permissions]";

"NSLocationWhenInUseUsageDescription" = "[my Turkish description of location permissions]";

Saved, compiled, even deleted app from device and rebuilt, but no avail. When my app asks for location permissions, the explanation underneath is still the English one (I've tried including the English translation as well under Base translation file, but it didn't change anything).

从设备中保存、编译甚至删除应用程序并重建,但无济于事。当我的应用程序请求位置权限时,下面的解释仍然是英文解释(我已经尝试在基本翻译文件下包括英文翻译,但它没有改变任何内容)。

Everything else is Turkish, translated just fine. It's just the location permission that doesn't translate. I've also seen How to localise a string inside the iOS info.plist file?and added the "Localized resources can be mixed" = YESkey (of course, as CFBundleAllowMixedLocalizations, not literally that sentence) to my original plist but that also didn't change anything.

其他一切都是土耳其语,翻译得很好。这只是不翻译的位置许可。我还看到了如何本地化 iOS info.plist 文件中的字符串?并将"Localized resources can be mixed" = YES密钥(当然, as CFBundleAllowMixedLocalizations,而不是字面上的那个句子)添加到我原来的 plist 中,但这也没有改变任何东西。

How can I solve the problem?

我该如何解决问题?

采纳答案by Can Poyrazo?lu

I've started over. Removed the translations, cleaned the project, and tried again. It worked. I have no idea why it didn't initially though.

我重新开始了。删除翻译,清理项目,然后再试一次。有效。我不知道为什么它最初没有。

回答by Zakaria Braksa

Here's what ended up working for me in Xcode 7.1.

这就是最终在Xcode 7.1.

First, go to project directory and manually create two InfoPlist.stringsfiles, the first inside the en.lprojfolder and the second inside the fr.lprojfolder.

首先,转到项目目录并手动创建两个InfoPlist.strings文件,第一个在en.lproj文件夹内,第二个在fr.lproj文件夹内。

Both files should have the following content :

这两个文件都应具有以下内容:

NSLocationWhenInUseUsageDescription = "YOUR TEXT HERE";

Since the files won't show up automatically in Xcode, you have to manually add both to the project bundle, this can be achieve via right-clicking the project name in Xcode and choosing the Add files to Xoption, then selecting the files you just created.

由于文件不会自动显示在 Xcode 中,您必须手动将它们添加到项目包中,这可以通过在 Xcode 中右键单击项目名称并选择Add files to X选项,然后选择您刚刚创建的文件来实现。



Also if you want to test the result & make sure things work, changing the Application Languagein Edit Scheme > Run > Optionsisn't enough.

此外,如果您想测试结果并确保一切正常,仅更改Application LanguageinEdit Scheme > Run > Options是不够的。

You need to change the simulatoror the devicelanguage via Settings > General > Language & Region > iPhone Language

您需要通过以下方式更改模拟器设备语言Settings > General > Language & Region > iPhone Language

回答by DonMizzi

My problem seems to be case sensitive:

我的问题似乎区分大小写:

My InfoPlist.stringshad a lower "i" in finder and Xcode (infoPlist), but needs to be upper.

InfoPlist.strings在 finder 和 Xcode (infoPlist) 中有一个较低的“i”,但需要更高。

I changed file name and reference in the source Xcode Project and it works (or deleted and re-create with the right name).

我更改了源 Xcode 项目中的文件名和引用,它可以工作(或删除并使用正确的名称重新创建)。