Martin Suchan
Martin Suchan

Reputation: 10620

How to always install all localized resources in Windows Store UWP app?

By default Windows Store UWP apps install only resources specific for the target machine. For instance if the app is localized into 5 different languages and user has machine in en-US, only en-US resources are installed.

The problem is if I want to have in my app on-demand language switching. Even thought I published app with fr-FR resources, I cannot switch to fr-FR because this language pack is not installed.

Is there a way or setting to force all resources to download when the app is installed from Windows Store?

Note one way, how to solve this is not package the app as appxbundle, but once the app is published as appxbundle, it's not possible to go back to non-appxbundle format.

Edit, the accepted solution below worked, I just added this config to my .csproj file and now it downloads all resource files during the installation:

<AppxBundleAutoResourcePackageQualifiers>Scale|DXFeatureLevel</AppxBundleAutoResourcePackageQualifiers>
<AppxDefaultResourceQualifiers>Language=cs-CZ;de-DE;en-US;es-ES;fr-FR;it-IT;pt-PT;ru-RU</AppxDefaultResourceQualifiers>

Upvotes: 8

Views: 1381

Answers (3)

Rohit Arnav
Rohit Arnav

Reputation: 1

follow this link for your anser.. https://msdn.microsoft.com/en-us/library/dn482043.aspx

Upvotes: -1

Zhendong Wu - MSFT
Zhendong Wu - MSFT

Reputation: 1829

Note one way, how to solve this is not package the app as appxbundle, but once the app is published as appxbundle, it's not possible to go back to non-appxbundle format.

If you need to keep the appxbundle, but still want to keep all the language resource installed. You can include the resources by adding a configuration file to your app package or modify your project file directly.

In this way, users can change language preferences offline and their devices can switch to the best resources for the new settings.

For detailed steps, please follow Ensure that resources are installed on a device regardless of whether a device requires them, which targets on Windows Store 8.1 app, but it works to UWP app as well. Also, you can check @Amy Peng's answer in this thread on MSDN forum .

Upvotes: 6

Martin Zikmund
Martin Zikmund

Reputation: 39072

I think the system will not allow you to force this without cheating the conventions.

As a workaround, you could name the resource files in such manner that the system itself doesn't recognize it is dealing with localized resources - instead of having Resources.en-US.resw, Resources.fr-FR.resw, etc., you could name them Resources_enUS.resw, Resources_frFR.resw for example.

Then you could have a LocalizationService class, that would accept the culture tag as constructor parameter and manually load the resources for that specific culture:

public class LocalizationService
{
    private readonly ResourceLoader _loader = null;

    public LocalizationService(string culture)
    {
        culture = culture.Replace("-", "");
        _loader = ResourceLoader.GetForCurrentView($"Resources_{culture}");
    }
}

Then you could just create the LocalizationService with the requested culture

var localizer = new LocalizationService( "fr-FR" )

Upvotes: 1

Related Questions