无法访问本地化资源.NET从Windows Phone的8.1 ​​4.5 PCL [英] Unable to access localized resources in .NET 4.5 PCL from Windows Phone 8.1

查看:145
本文介绍了无法访问本地化资源.NET从Windows Phone的8.1 ​​4.5 PCL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦访问便携式类库本地化字符串资源针对.NET 4.5。

I have troubles accessing localized string resources in Portable Class Library targeting .NET 4.5.

我允许用户选择第一页上的语言,并本地化体验进一步页。我试图做到这一点刚刚得到的代码资源

I am allowing the user to select the language on first page and have localized experience on further pages. I am trying to achieve that just by getting resource with code

MyTextBloxk.Text = PasswordResetMethod_Page.Title;



PasswordResetMethod_Page距离的.resx自动生成的类

PasswordResetMethod_Page is the auto-generated class from the .resx

一切工作正常的WP 8.1模拟器,但是当我尝试将它部署到真正的设备,我得到

Everything works fine on the WP 8.1 emulator, but when I try to deploy it to the real device I get

错误:DEP6810:MdilXapCompile.exe失败,错误代码1004见
日志文件
'C:\Projects\WP81-ResourceBug\ResourceBugRepro.WP81\obj\Debug\MDIL\ 。MDILXapCompileLog.txt'
了解更多详情。

Error : DEP6810 : MdilXapCompile.exe failed with error code 1004. See log file 'C:\Projects\WP81-ResourceBug\ResourceBugRepro.WP81\obj\Debug\MDIL\MDILXapCompileLog.txt' for more details.

错误:编译过滤参数指定不存在的文件:
C:\Projects\WP81 -ResourceBug\ResourceBugRepro.WP81\obj\Debug\MSIL\ar\ResourceLib.resources.dll

Error: Compile filter argument specified non-existent file: C:\Projects\WP81-ResourceBug\ResourceBugRepro.WP81\obj\Debug\MSIL\ar\ResourceLib.resources.dll

无效参数

要重现:


  1. 克隆回购的 https://github.com/konradbartecki/WP81-ResourceBug

  2. 设置WP8.1作为启动项目

  3. 部署到设备

在模拟器上工作得很好,不起作用部署到实际设备时

Works fine on the emulator, does not work when deploying to real device

推荐答案

不幸的是,解决方法描述的便携式类库时MissingManifestResourceException博客没有为我工作也很好。
我已经开发了我自己的解决方法。事实证明,如果你使用的是.resx文件只能存储字符串值,那么你就可以轻松地将它们转换为.resw。

Unfortunately the workaround described on Phil Hoff blog did not work for me too well. I have developed my own workaround. It turns out if you are using .resx files to store string values only, then you can easily convert them to .resw.

所以我在做什么会自动将所有从PCL .resx文件,并把它变成我的Windows Phone 8.1的项目结构化的本地文件夹,并使用该工具,我写刷新他们每构建。

So what I am doing is automatically converting all .resx files from PCL and placing it into native structured folders in my Windows Phone 8.1 project and refreshing them every build using this tool that I wrote.

https://github.com/konradbartecki/ResxHell

然后我可以轻松地访问我的字符串资源从这样的代码

Then I can easily access my string resources from code like this

var resourceLoader = new ResourceLoader();
var localizedText = resourceLoader.GetString("MyCustomReswFile/MyCustom");

有关很好的结合我结束了创建ValueConventer和小本地化辅助类,看看这个要点是: 从.resw文件的例子绑定

For nice binding I ended up creating ValueConventer and small localization helper class, take a look at this gist: Binding from .resw files example

随着使用的,你可以做以下的在你的XAML页面:

With the use of that you can do following in your xaml pages:

//For resource in file Page.Login.resw and string ID "NotUserYet"
<TextBlock Text="{Binding ConverterParameter=Page.Login/NotUserYet, Converter={StaticResource ResString}, Mode=OneWay, Source={StaticResource ResString}}"/>


字符串localizedtext = LocalizationHelper.GetString(MyCustomReswFile MyStringId);

这篇关于无法访问本地化资源.NET从Windows Phone的8.1 ​​4.5 PCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆