简体   繁体   中英

How to localize WPF Application with RESX files in subdirectories

My team has some WPF projects written using XAML. We recently added a large number of local specific RESX files to each project. In order to keep things tidy, I was asked to store these files in [Project]>Localization>[locale]

Now, when we run the application on a non en-US locale, strings are pulled from the appropriate RESX file. We've tried to update Namespaces in the properties of the RESX files, as well as setting them to Public so that a resulting Designer is created. The only way that we can get things to work is by moving the locale RESX files directly into the Project's Properties directory.

Is there anyway to update the XAML to search for locale RESX files in a subdirectory?

EDIT XAML Codebase and Solution Explorer

I've attached an image of the problem for clarification.

Some code changes that we've tried:
1) We attempted to set the Namespace for xmlns:res="clr-namespace:[PROJECT].CoreUI. Localization "
2) Attempted to set the Namespace to xmlns:res="clr-namespace:[PROJECT]. CoreUI "
3) We've also attempted to change the Custom Tool Namespace of the RESX file to match the current namespace My.Properties as well as CoreUI.Properties

We've also confirmed that the Access Modifiers for both Resources.resx and Resources.ru.resx (for example) are set to Public and that both Build Actions show "Embedded Resource"

Thanks for the help!

My colleague actually stumbled upon another post in here that we somehow missed during out countless searching:

Put translated resx files in a different folder in Visual Studio?

In short, we were thinking about making the project search down into subdirectories for the RESX files. In actuality, we need the RESX file to search for the already created designer further up in the chain.

<ItemGroup>
<EmbeddedResource Include="Localization\ar\Resources.ar.resx" >
<ManifestResourceName>$(TargetName).Properties.%(Filename)</ManifestResourceName>
</EmbeddedResource>

Entering the ManifestResourceName appears to tell the RESX file that we already have a Designer created and not to make a new one.

Thanks again for everyone's help!

You've to first include your folder in the namespace and mention project name like:

xmlns:resx="clr-namespace:Prism_Modules.MyResources;assembly=Prism_Modules"

Also you must include:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Finally, you should call values in resources as:

<dxb:BarButtonItem x:Name="menuFile" Content="{x:Static resx:Resources.mnuFile}"  }" />

When moving .resx file to another folder/project, the .Designer.cs file that exposes resource members will still point to the old namespace and also Visual Studio will place it outside the .resx file.

To fix this, I simply deleted the generated .Designer.cs file and then after opening and saving .resx file, the Designer.cs file got generated with proper namespace and I could normally refer to it even from other projects. To generate .Designer.cs file for resource languages/files that have none just open .resx file and use the Access Modifier combobox and VS will create it for you.

I hope I was of any help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM