I'm creating a multi-language application with WPF. I'm using static resources, strings stored in .resx/res files to have text appear in the culture of the user.
Here's a part of the project's directory structure:
In the .csproj, I have: <UICulture>en-US</UICulture>
In the AssemblyInfo.cs: [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
After compilation, I can see the resource files appear:
So I bind 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 are puzzling to me:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MyApp.Resources.GreetingWindowRes.en-US.resources" was correctly embedded or linked into assembly "MyApp" at compile time, or that all the satellite assemblies required are loadable and fully signed.
What am I doing wrong?
After lots of searching, 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>
, you would need to have both ResxResource.resx and GreetingWindowRes.en-US.resx files for the main language (nasty duplication).
But, if you only want to use Resx resources, and no BAML localization, this is not the way to go, and the situation is a lot better. The proper way with only Resx resources:
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
<UICulture>
I think that when you set an UICulture you must have the corresponding resx file. So, To solve your problem you must create a file for en-US culture (that will be the same as Resources.resx).
I think (but I can be wrong) that the Resources.resx is used for the default culture, or the culture that the PC has.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With