Xamarin.iOS localization of NSLocationWhenInUseUsageDescription

好久不见. 提交于 2019-12-12 14:42:28

问题


Is there a way to localise the NSLocationWhenInUseUsageDescription in Info.plist in the Xamarin Studio? Or any possibility to localise the complete Info.plist would be a solution as well.

I tried the following steps as it looks analogue to the How to localise a string inside the iOS info.plist file? but it does not work for me.

So these are the steps:
In both en.proj and de.proj:
I added an empty file InfoPlist.strings

In Info.plist:
I have set the key of the "NSLocationWhenInUseUsageDescription" to "NSLocationWhenInUseUsageDescriptionMessage".

In InfoPlist.strings:
I added the "NSLocationWhenInUseUsageDescriptionMessage" as key in the strings files and the corresponding transitions in each, but it seems not to work -> the raw string "NSLocationWhenInUseUsageDescriptionMessage" is shown when the user is asked for the permission.


回答1:


I had similar problem (only I used "Always" instead of "WhenInUse". Here's what worked:

In both en.lproj and de.lproj add the file InfoPlist.strings. Each of the files contains only one line:

"NSLocationAlwaysUsageDescription" = "Your location needed, because...";

In Info.plist, the string doesn't matter anymore, because it will be taken from the InfoPlist.string file. The relevant lines in Info.plist look like this:

<key>NSLocationAlwaysUsageDescription</key>
<string>No text needed here.</string>

Maybe you forgot the semicolon in the strings-files? Or your two folders were named *.proj instead of *.lproj?




回答2:


We faced a similar issue for the localization of NSLocationWhenInUseUsageDescription. The translation was shown on the iOS simulator but never on real devices. After we fixed our CFBundleLocalizations array from upper case language codes to lower case in the Info.plist the permission description was translated correctly for all languages.

Not correct:

<key>CFBundleLocalizations</key>
<array>
    <string>EN</string>
    <string>DE</string>
    <string>BG</string>
    <string>PL</string>
    <string>FR</string>
    <string>CS</string>
</array>

Correct:

<key>CFBundleLocalizations</key>
<array>
    <string>en</string>
    <string>de</string>
    <string>bg</string>
    <string>pl</string>
    <string>fr</string>
    <string>cs</string>
</array>


来源:https://stackoverflow.com/questions/26175820/xamarin-ios-localization-of-nslocationwheninuseusagedescription

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!