Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use a portable library with localized resources in a Universal app?

(There's a link at the bottom to a solution with repro of the problem.)

I've been using a portable library with .resx resources for quite some time as it worked for both Windows Store apps and Windows Phone apps. I tried to use it with a Universal app as well, and it works for the Windows Store part, but does not work for Windows Phone.

The problem occurs only when I try to deploy the app on a device (built with the Release configuration). If I just Build it, it does not give an error (but it still can't be deployed on the device successfully). I get the following error:

Error : DEP6810 : MdilXapCompile.exe failed with error code 1004. See log file
'...\Phone App Test\Phone App Test\obj\Release\MDIL\MDILXapCompileLog.txt' for more details.

And in that file:

Error: Compile filter argument specified non-existent file:
...\Phone App Test\Phone App Test\obj\Release\MSIL\en-US\PCL.resources.dll
Invalid argument

The file truly isn't there, but the app does not support the en-US culture anyway, only the library does, so I don't think this file should be needed.

Any idea how I can resolve this issue?

Here's a simple solution with the problem: link

like image 753
yasen Avatar asked Oct 07 '14 14:10

yasen


1 Answers

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 and use natively in Windows Phone 8.1.

So what I am doing is copying and converting resources from PCL and placing as native .resw resources in Windows Phone project every build automatically using the tool I made - ResxHell. Just follow the instructions on the repository and you can then reach resources like this

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

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

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}}"/>

or string localizedtext = LocalizationHelper.GetString("MyCustomReswFile", "MyStringId");

like image 198
Konrad Bartecki Avatar answered Oct 04 '22 02:10

Konrad Bartecki