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

前端 未结 6 1143
夕颜
夕颜 2021-02-04 12:08

(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 bo

6条回答
  •  萌比男神i
    2021-02-04 12:14

    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"
    
    

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

提交回复
热议问题