What is the best way to localize a WPF application, sans LocBAML?
Asked Answered
T

5

21

There seems to be no good way to localize a WPF application. MSDN seems to think that littering my XAML with x:Uid's, generating CSV files, and then generating new assemblies (using their sample code!) is the answer. Worse, this process doesn't address how to localize images, binary blobs (say, PDF files), or strings that are embedded in code.

So, how might you localize an application that:

  1. Contains several assemblies
  2. Contains images and other binary blobs (eg: PDF docs) that need to be localized
  3. Has string data that isn't in XAML (eg: MessageBox.Show("Hello World");)
Teresita answered 17/9, 2008 at 20:19 Comment(2)
The answer you accepted has several answers incide. Can you point out what did you choose?Plotter
It has been so long, I forget! Doh!Teresita
R
8

Not an expert here, but "littering" your xaml with x:Uids is not worse than "littering" your Windows Forms code with all the string table nonsense you have to do for localizing them.

As far as I understand, WPF apps still support "all the Framework CLR resources including string tables, images, and so forth." which means you can have localized resources.

Of course, it would be much simpler if you created a markup extension that handled much of this nonsense for you. You can find an example of someone doing this here. And there was another, similar solution at http://blog.taggersoft.com/2008/07/wpf-application-localization-pattern_29.html, but that link no longer works.

Reborn answered 17/9, 2008 at 20:44 Comment(1)
Hey, folks, as of this comment, this answer is almost eight years old. Please seek out more up-to-date information about localizing WPF applications. No need to upvote the answer, just upvote this comment/leave details about what you find!Reborn
A
11

You should have a look at the article and code available here. It describes different ways of localizing WPF apps, using LocBaml, custom markup extensions, or attached properties. IMHO the best solution is to use the markup extensions and Resx resources. The code contains a localization framework for doing that.

Awfully answered 2/7, 2009 at 18:57 Comment(0)
R
8

Not an expert here, but "littering" your xaml with x:Uids is not worse than "littering" your Windows Forms code with all the string table nonsense you have to do for localizing them.

As far as I understand, WPF apps still support "all the Framework CLR resources including string tables, images, and so forth." which means you can have localized resources.

Of course, it would be much simpler if you created a markup extension that handled much of this nonsense for you. You can find an example of someone doing this here. And there was another, similar solution at http://blog.taggersoft.com/2008/07/wpf-application-localization-pattern_29.html, but that link no longer works.

Reborn answered 17/9, 2008 at 20:44 Comment(1)
Hey, folks, as of this comment, this answer is almost eight years old. Please seek out more up-to-date information about localizing WPF applications. No need to upvote the answer, just upvote this comment/leave details about what you find!Reborn
H
0

You can use the old "ResX" files which support all of your mentioned scenarios. How this can be accomplished in a WPF application is explained here:

WPF Application Framework (WAF) => See Localization Sample

Headset answered 2/7, 2009 at 18:45 Comment(0)
G
0

try the Gnu GetText utilities, and supporting applications. It does generate C# classes based around ResourceManager and ResourceSets, and of course you can reuse the translations for other parts of your application - eg web pages, native code, or iphone etc.

Gona answered 2/2, 2011 at 14:9 Comment(0)
D
0

I had the same issue with own WPF application and decided to write a lightweight localization library. It allows translating xaml resource dictionary files and switching between supported languages at runtime.

You can look into Armat.Localization GitHub repository for more details and refer to "armat.localization.wpf" NuGet package in WPF applications. Cloning / Building the source code with appropriate demo application will give you enough understanding about how the Armat.Localization library works.

The main idea is following:

  • Extract all localizable contents from WPF controls into WPF Resource Dictionary file(s)
  • Make Resource Dictionaries localizable by changing the root xaml element to "Armat.Localization.Wpf.LocalizableResourceDictionary"
  • Use the Localization Designer (from the same repo) to create translation file for all supported languages
  • Provide a language selector in WPF application for switching between supported languages

Markdown files in Localization.Core and Localization.Wpf projects will guide you through the general usage patterns, and the Localization.Demo application will serve you as a sample localizable WPF project.

Devitrify answered 10/10, 2023 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.