Bukk94
Bukk94

Reputation: 429

C# WPF Localization - Ignoring other cultures and loading default Resources

I'm trying to localize my app, I've created several Resources.[culture].resx but program ignores them all and always loads default Resources.resx.

I have this code in App construtor (and in OnStartup event)

System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

My resources are called Resources.en-US.resx, Resources.cs-CZ.resx and Resources.resx

Code in WPF is

xmlns:p="clr-namespace:WpfThermalLabelEditorApp.Properties"
Title="{x:Static p:Resources.Title}" 

This should load en-US localization but it doesn't. Loads default. I tried to delete AssemblyInfo and even putting <UICulture> tags into csproj

Upvotes: 0

Views: 1521

Answers (3)

Bukk94
Bukk94

Reputation: 429

Well, after 2 days I've solved my problem. My solution was correct. I have no idea what was wrong but I've created a new project, moved all my data to a new one and suddenly everything worked as a charm.

Here is a few usefull links:

Upvotes: 0

Lahna200
Lahna200

Reputation: 551

I came across the same problem, the solution was to clean and rebuild the project. No need to create new project.

Upvotes: 0

Capn Jack
Capn Jack

Reputation: 1241

Not sure if this is the answer, but FWIW: I always set both CurrentCulture and CurrentUICulture like so;

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(languageAbbreviation);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageAbbreviation);

And be sure to double check the abbreviation you use is the same for all references. That should fix your problem.

EDIT1: Make sure your resource files are set to public, the access modifier should be somewhere near the top when you're viewing the resource file. Double check this says public and rebuild. Also, to call your resource file key do so like this:

<TextBlock xmlns:local="clr-namespace:WpfApplication2" Text="{x:Static local:Resource1.myname}"/>

Where...

  • "WpfApplication2" is replaced with your project name
  • "Resource1" is replace with the name of your resource file (without culture id, e.g. for your case it would just be Resources)
  • "myname" is replaced with the key you want

Upvotes: 1

Related Questions