daengl
daengl

Reputation: 241

Use PCL resx strings in UWP

I have a solution with 3 projects:

  1. Portable class library containing functions and LocalizedStrings.resx files for localization
  2. WPF application for Windows 7
  3. Universal app for Windows 10

In my WPF app I use the following code to access the strings from the resx files:

private ResourceManager localizedStrings;

public MainWindow()
{
    localizedStrings = new ResourceManager(typeof(LocalizedStrings));

    InitializeComponent();

    tbTest.Text = localizedStrings.GetString("headerToolData");

Now I want to use the same code in my UWP app but it doesn't work. I always get the value for the language set as "Default language" in the package manifest.

How can I correctly access strings defined in an resx file included in a pcl in UWP apps?

Upvotes: 2

Views: 1164

Answers (2)

Marcel Wolterbeek
Marcel Wolterbeek

Reputation: 3702

When your localized resources are not located in your startup project, you can specify the supported languages in the package.appxmanifest:

  <Resources>
    <Resource Language="de-AT"/>
    <Resource Language="en-US"/>
  </Resources>

Upvotes: 2

Corcus
Corcus

Reputation: 1090

Something that comes to mind as a reason why you get only the default language in the UWP application is that the app doesn't know it should support other languages.

The way a UWP would know that is through convention. In a UWP you would normally have a folder named Strings and subfolders for all supported cultures, which would contain resw files.

I am guessing you don't have this structure in your UWP app. To test if this is the case try creating this structure and add at least one file in the folders containing at least one resource.

If this doesn't work you may want to look at these two links Shared localization for WP8 and W Share localization files between WP8 and Win8

They are writen for Win8 but they should work the same for UWP.

In short what they suggest is to create a class to expose the localized resources.

Upvotes: 2

Related Questions