Search code examples
uwplocalization

Localization in multiple projects solution


I have a solution in UWP with 3 different projects (for example: A, B and C). B is the library where A and C projects access to.

I have generated the translations for the A project (using XLF files for the translations) and works OK. I'm using Multilingual App Toolkit (MAT).

Now I have started the translations for the B project (resx files and xlf files are in the B project as in A)

enter image description here

Despite I have activated MAT also in B project, I can't add new translation language to B, so I have created the files manually. Builds with only one warning:

GENERATEPROJECTPRIFILE : warning PRI257: 0xdef00522 - Resources found for language(s) 'es,en-us,eu' but no resources found for default language(s): ''. Change the default language or qualify resources with the default language. http://go.microsoft.com/fwlink/?LinkId=231899

It seems like project B doesn't have a default language despite of that it's set in the solution (Package.appxmanifest).

When running the app, none of the localized strings in the B project are shown.

Any idea how can I handle this problem?

Edit 1: I have corrected the warning changing the default language for the project in the Assemby Info. Still, strings are not visible.

Edit 2: The code in the A project and in the B is the same:

ResourceLoader.GetForCurrentView().GetString("FileName_StringName");

Other detail that might be of interest is that B project classes are (mostly) static.

When initiating the app one of the first thing that happens it's the selection of the app level language:

// Hard coded language override     
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "eu"; 
            Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Reset();   
           Windows.ApplicationModel.Resources.Core.ResourceContext.GetForViewIndependentUse().Reset();

Edit 3: This is what dumped PRI to XML file contains:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PriInfo>
    <ResourceMap name="CoreTPA" version="1.0" primary="true">
        <Qualifiers>
            <Language>ES,EN-US,EU</Language>
        </Qualifiers>
        <ResourceMapSubtree name="CoreTPA">
            <ResourceMapSubtree name="Resources">
                <NamedResource name="AuroraForecastImages_GetForecast_ErrorDeserializingData" uri="ms-resource://CoreTPA/CoreTPA/Resources/AuroraForecastImages_GetForecast_ErrorDeserializingData">
                    <Candidate qualifiers="Language-EU" type="String">
                        <Value>Error deserializing data</Value>
                    </Candidate>
                    <Candidate qualifiers="Language-ES" isDefault="true" type="String">
                        <Value>Error deserializing data</Value>
                    </Candidate>
                    <Candidate qualifiers="Language-EN-US" type="String">
                        <Value>Error deserializing data</Value>
                    </Candidate>
                </NamedResource>
                <NamedResource name="AuroraForecastImages_GetForecast_ErrorGettingDataFromServerIsNetworkWorkingCorrectly" uri="ms-resource://CoreTPA/CoreTPA/Resources/AuroraForecastImages_GetForecast_ErrorGettingDataFromServerIsNetworkWorkingCorrectly">
                    <Candidate qualifiers="Language-EU" type="String">
                        <Value>Error getting data from server. 
Is network working correctly?</Value>
                    </Candidate>
                    <Candidate qualifiers="Language-ES" isDefault="true" type="String">
                        <Value>Error getting data from server. 
Is network working correctly?</Value>
                    </Candidate>
                    <Candidate qualifiers="Language-EN-US" type="String">
                        <Value>Error getting data from server. 
Is network working correctly?</Value>
                    </Candidate>
                </NamedResource>
            </ResourceMapSubtree>
        </ResourceMapSubtree>
        <ResourceMapSubtree name="Files">
            <ResourceMapSubtree name="CoreTPA">
                <NamedResource name="Core_ml.xml" uri="ms-resource://CoreTPA/Files/CoreTPA/Core_ml.xml">
                    <Candidate type="Path">
                        <Value>CoreTPA\Core_ml.xml</Value>
                    </Candidate>
                </NamedResource>
            </ResourceMapSubtree>
        </ResourceMapSubtree>
    </ResourceMap>
</PriInfo>

Solution

  • By testing, the localized resources used by project B come from project A(if project A calls project B) or project C(if project C calls project B) instead of the localized resources added in project B.

    Therefore, there is no need to add resource files manually in project B. You need to add your string resources in project A or project C instead of project B.