Search code examples
wpfxamlglobalizationmultilingual

Multilanguage in WPF


Can you recommend a good way to implement a Multilanguage system for a WPF app? The method I'm using right now involves XML, classes and a xaml extension. It Works fine in most of cases, but when I have to deal with dynamic labels or dynamic text in general it require some extra effort. I would like to let the programmer working only in the main problem and forgot the lang issues.


Solution

  • I am using the WPF Localization Extension. It is a really easy way to localize any type of DependencyProperty on DependencyObjects.

    • is in a real stable state
    • supports binding-like writing style like Text = {LocText ResAssembly:ResFile:ResKey}
    • works with the .resx-fallback mechanism (e.g. en-us -> en -> independent culture)
    • supports culture forcing (e.g. "this has to be English all the time")
    • works with normal dependency properties
    • works with control templates
    • can be used in XAML (really :P) without any additional namespaces
    • can be used in code behind to bind localized values to dynamic generated controls
    • implements INotifyPropertyChanged for advanced use
    • supports string formatting e.g. "this is the '{0}' value"
    • supports prefix and suffix values (currently with LocText extension)
    • is in use in productive systems (like my public relation product)
    • switching of the language to runtime affects NO timeslice
    • can be used with any resource file (.resx) across all assemblies (also the dynamic loaded one at runtime)
    • doesn't need any initializing process (like "call xyz to register a special localize dictionary")
    • is available at design-time (MS Expression Blend, MS Visual Studio 2008 (Normal and SP1)
    • change of the chosen language is possible at design-time
    • can localize any type of data type, as long as a converter (TypeConverter) for it exists (extends LocalizeExtension)
    • has built in support for Text, upper Text, lower Text, Images, Brushes, Double and Thickness
    • doesn't affects any memory leaks
    • leaves the UID property untouched
    • offers a SpecificCulture to use as IFormatProvider (e.g. (123.20).ToString(LocalizeDictionary.SpecificCulture) = "123.20" or "123,20")
    • offers some functionality to check and get resource values in code behind
    • doesn't alter the culture on Thread.CurrentCulture or Thread.CurrentUICulture (can be changed easily)