Xamarin.Android 中基于 RESX 的本地化

RESX-based localization in Xamarin.Android

我正在尝试研究这个主题,但仍然不清楚是否可以在 Xamarin.Android 中实现基于 RESX 的本地化。在我个人的尝试中,我无法获得任何本地化字符串,只能获得中性文化字符串。

我也可以看到像 this one 这样的帖子,其中指出它应该有效 Android:

This works fine for Android and windows phone.

但我也可以看到类似 that one 的帖子,其中本地化无法正常工作。

所以我的问题很简单。如何在 Xamarin 中为 Android 构建基于 RESX 的本地化应用程序?

[回答我自己的问题]

嗯,首先,是的,Xamarin.Android 中基于 RESX 的本地化是可能的,并且按预期工作。

其次,由于缺乏对细节的关注,我已经浪费了很多时间来尝试使其正常工作。我已经阅读文章 Localizing Xamarin.Forms Apps with RESX Resource Files 好几遍,但我总是省略故障排除部分。确实有一把钥匙:

Doesn't work in DEBUG mode (Android only)

If the translated strings are working in your RELEASE Android builds but not while debugging, right-click on the Android Project and select Options > Build > Android Build and ensure that the Fast assembly deployment is NOT ticked. This option causes problems with loading resources and should not be used if you are testing localized apps.

第三,在尝试寻找一些替代方法来解决我的问题时,我发现文章 Generating Localized Resources in Mono for Android Using T4. In pair with the cool NuGet package from Daniel Cazzulino described in the article How to transform T4 templates on build without installing a Visual Studio SDK 中描述的方法很有趣我能够为 Android 平台构建一个简单的替代方案基于我来自 WPF 项目的 RESX。

希望对大家有所帮助。