views:

44

answers:

3

I have a very common question. What is the best way to do localization in a WPF app. Well, I searched in SO and Binged a lot too. But I could not find any pointers which is really simple and elegant.

Assume that I have to display in UI something like:

In English: Orgnanization - Beoing

In French: Organizzazione - Beoing


        <StackPanel Orientation="Horizontal">
            <TextBlock Text="Organization -"></TextBlock>
            <TextBlock Text="{Binding Path=OrganizationName}"></TextBlock>
        </StackPanel>

Basically, I need to assign the localized text to Organization Label TextBlock. Should I separate the hyphen from "Organization -" and put it in a separate label?

Please let me know, how do I do that

thanks

123Developer.

A: 

We have an application that can switch UI languages at runtime and has the ability to use new UI languages by copying the appropriate resources to a certain directory. Using some sort of compiled resoures for this is way too inflexible in terms of distributuon etc. So we have our language resources in a ResourceDictionary as System:Strings - one ResourceDictionary in a separate XAML file for each language. The XAML files are tagged as Content in VS and copied. You can use them as DynamicResources in XAML or via a Localizer instance in C#. This concept has proofed very useful in our application.

banzai
+1  A: 

Have a look at this Whitepaper, If I remember correctly it explains how to use Resource dictionary in xaml for localization -

This project includes a whitepaper with code samples to help Windows Presentation Foundation (WPF) developers localize their applications. The whitepaper compares LocBaml and classic Resx approaches with pros and cons.

http://wpflocalization.codeplex.com/

akjoshi
+2  A: 

I Bind all the labels, etc. in my application to an object that I use for displaying the different languages. I store all the strings in a database and just retrieve the proper strings based on the language the user has selected. This has the advantage of instantly updating during run-time. This way the user does not need to restart the application like you would if you chose to make the windows 'Localizable'.

Stewbob