Developing localizable feature in old application wasn’t painless. 🙂
In Windows environment, thanks to .Net framework this feature is very easy.
WPF doesn’t miss the point (ehm locbaml?? ;)) so realizing localizable applications is very easy indeed.
Since I’m still a WPF newbie developer, I found old resx files is still the simple solution.
I run through this very helpfull post WPF Localization – RESX Option by Toad.
Here is a step-by-step summary:
- Added “Resource” folder to wpf project
- Added resx files, based on languages to support (ie: Resource.en-US.resx, Resource.it-IT.resx, … and Resources.resx of couse)
- Changed resx files from Internal to Public
- Added resource namespace in Window1.xaml:
xmlns:resx="clr-namespace:WpfApplication1.Resources"
- Setted property’s binding to desidered controls:
<TextBlock Text="{x:Static resx:Resource.SampleMessage}" />
- To test different languages, pre_setting language in App class constructor:
public partial class App : Application { static App() { Resource.Culture = new System.Globalization.CultureInfo("it-IT"); } }
So standard Window1.xaml can result like this
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:resx="clr-namespace:WpfApplication1.Resources" Title="Window1" Height="100" Width="300"> <Grid> <TextBlock Text="{x:Static resx:Resource.SampleMessage}" /> </Grid> </Window>
XAML binding let resource available in designer window:
Ta-daaa! 🙂
source: WPF Localization – RESX Option
Technorati tags: WPFLocalization