Xamarin.IOS:本地化不起作用 [英] Xamarin.IOS: localization does not work
问题描述
我有一个Xamarin.IOS应用程序,并尝试本地化某些图像. 作为指导,我读了这篇文章: https://developer.xamarin.com/guides /ios/advanced_topics/localization_and_internationalization/
I have a Xamarin.IOS application and try to localize some images. As a guideline I took this article: https://developer.xamarin.com/guides/ios/advanced_topics/localization_and_internationalization/
我尝试显示图像"ImageInstructionStep1"
I try to display the image "ImageInstructionStep1"
这是我的资源"文件夹的屏幕截图:
Here is a screenshot of my Ressources Folder:
所有图像都具有构建动作"BundleResource". 我使用以下代码在代码中分配图像:
All images have the build action "BundleResource". I assign the image in the code with this line:
imageInstructionStep.Image = UIImage.FromBundle("ImageInstructionStep1");
然后我在Info.Plist中注册了本地化版本:
And I registered the localizations in my Info.Plist:
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleLocalizations</key>
<array>
<string>de</string>
<string>fr</string>
<string>it</string>
</array>
但是它总是显示英文版本.
But it always displays the english version.
以此方式启动应用时,我检查了应用的语言环境:
I checked the locale the app has when I start it with this:
NSLocale.CurrentLocale.LocaleIdentifier;
NSLocale.AutoUpdatingCurrentLocale.LocaleIdentifier;
,两者都给出"de_US".我的期望是,这将加载德国本地化.
and both give as a result "de_US". My expectations would have been that this would load the german localization.
我还尝试清理并重新构建应用程序至模拟器,包括在没有成功之前将其从模拟器中删除.
Also I tried clean and rebuild the app to the simulator, including remove it from the simulator before without success.
也许是在旁注:我在resx文件中本地化的所有文本均按预期以德语显示.
Maybe interessting as a sidenote: all my textes who are localized in resx file are shown in german as expected.
我想念什么?
推荐答案
因此,正如我在评论中指出的那样,您应该将后备资源放入Base.lproj
文件夹中.
So as I pointed out in the comments, you should put fallback resources into the Base.lproj
folder.
关于InfoPlist.strings
的问题,请记住,它们仅适用于Info.plist
中的字符串,因此是在您请求权限等时.对于da.lproj
,它可能如下所示:
As for your issue with InfoPlist.strings
, keep in mind that they are applied only for strings in your Info.plist
, so that is when you are asking for permissions etc. This could look as follows for da.lproj
:
"NSLocationWhenInUseUsageDescription" = "Vil du tillade App'en til at bruge din lokation?";
"NSCalendarsUsageDescription" = "Ost";
以此类推.
对于其他字符串,例如OK,Cancel和其他按钮,您将需要为每个文件夹添加一个Localizable.strings
文件,其内容如下:
As for other strings, such as OK, Cancel and other buttons, you will need to add a Localizable.strings
file for each folder with contents like:
"Back" = "Tilbage";
"Done" = "Færdig";
"Cancel" = "Anuller";
这篇关于Xamarin.IOS:本地化不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!