Why won't my app find the default satellite build resources in the US?

I am creating a multilingual application with WPF. I use static resources, strings stored in .resx / res files, so that the text appears in the user's culture.

Here is part of the project directory structure:

  • Resources
    • GreetingWindowRes.resx (this is the default value for en-US)
    • GreetingsWindowRes.de-DE.resx

In .csproj I have: <UICulture>en-US</UICulture>

In AssemblyInfo.cs: [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]

After compilation, I see how resource files appear:

  • ru-US / MyApp.resources.dll
  • de-DE / MyApp.resources.dll

Therefore, I am bound to a static string resource in GreetingWindow.xaml:

 <windows:MyWindowBase x:Class="CommanderDotNET.MyApp.Windows.GreetingWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:windows="clr-namespace:MyApp.Windows" xmlns:res="clr-namespace:MyApp.Resources"> <Label Content="{x:Static res:GreetingWindowRes.FirstGreetingText}" /> </windows:MyWindowBase> 

The results baffle me:

  • If UICulture is set to de-DE, the label text is displayed in German.
  • If UICulture is set to en-US, System.Windows.Markup.StaticExtension throws a XamlParseException. The error I see for XAML should be the reason:

Could not find resources suitable for the specified culture or neutral culture. Make sure "MyApp.Resources.GreetingWindowRes.en-US.resources" was correctly embedded or linked into the "MyApp" assembly at compile time, or that all necessary satellite assemblies are downloadable and fully signed.

What am I doing wrong?

DECISION:

After many searches, I found a good explanation here: http://www.west-wind.com/weblog/posts/2009/Jun/04/Resx-and-BAML-Resources-in-WPF

Apparently, when using UltimateResourceFallbackLocation.Satellite + <UICulture> for the main language, you will need to have both ResxResource.resx and GreetingWindowRes.en-US.resx for the main language (unpleasant duplication).

But, if you want to use Resx resources and do not localize BAML, this is not the way, and the situation is much better. The correct way to use Resx resources:

  • AssemblyInfo.cs: [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
  • .csproj: DO NOT add <UICulture>
  • Resource naming: ResxResource.resx (primary language) + ResxResource.de-DE.resx (secondary language)
+6
source share
1 answer

I think that when you install UICulture, you should have the corresponding resx file. So, to solve your problem, you must create a file for the en-US culture (this will be the same as Resource.resx).

I think (but I could be wrong) that Resource.resx is used for the default culture or the culture that the PC has.

+3
source

Source: https://habr.com/ru/post/955182/


All Articles