I want to localize a .Net Core application with .resx files. Can anyone give me a complete step-by-step solution? I'm new at WPF and .Net-Core. When I change the current culture in code nothing happens. Here is my code:
<ToolBar>
<Button Content="{x:Static strings:Resource.NewCustomer}" Command="{Binding NewCustomerDelegateCommand}"/>
</ToolBar>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
base.OnStartup(e);
}
}
When localizing WPF application you have several choices.
Using native WPF's approach (with using UID), see: MSDN. This approach has drawbacks explained more in detail in the article, but generally saying:
Using the resx's strongly-typed resource class generated by PublicResXFileCodeGenerator / ResXFileCodeGenerator.
(see custom tool in the properties window in the VS for the resx file; PS: the second generator creates internal class, so keep in mind that it will be usable only in the same assembly where xaml being localized exists and only with WPF Binding, not with Static markup extension)
This approach is similar to the one you’ve tried to apply, meaning in the xaml you use Binding (or x:Static) to the properties of the generated strongly-typed resource class. The drawback of this approach is that the generated strongly-typed resource class does not provide any notification whenever culture/language is changed. Other words, you can provide strings, labels etc., but they will be resolved at the time when xaml is parsed/loaded. After that it becomes fixed content:
You can find on the market already available solutions for localizing WPF application using resx files, e.g. have a look: https://www.qube7.com/guides/localization.html
The full source code of the Resource markup extension you’ll find here: Resource.cs
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