Search code examples
c#wpfxamlinternationalizationgettext

How can I use GNU gettext in xaml and resx


I'm in a WPF project. I want to use GNU gettext library. But they already used *.xaml and *.resx for i18n.

in *.xaml

Text="{cmn:Locale ResourceName=MessageSymbol}"

Message symbols are used in *.xaml. And the symbols are defined in each locale *.resx (e.g. Resources.en-US.resx)

But this way is not efficient as I think. We should handle many *.resx by hands. And translators can't understand *.resx format. then don't have Visual Studio. All the process is automatic in GNU gettext. That's why I want to use GNU gettext.

I can't give up using *.xaml for layout design.

How can I use GNU gettext in xaml?


Solution

  • In a similar case (it was Silverlight), I successfully used Vernacular: https://github.com/rdio/vernacular

    It's not GNU gettext per se, but use the same file formats and ways of working. That means your translators can use their tools inputing and outputting .po files.

    To give you some examples, here's how it look in C#:

    Console.WriteLine (Catalog.GetString ("Hello, World");
    

    There are plenty of overrides: for plurals, gender, and additional translators comments: https://github.com/rdio/vernacular/blob/master/Vernacular.Catalog/Vernacular/Catalog.cs

    In xaml, it looks like this:

    <TextBlock i18n:Catalog.Message="Hello, World!" />
    

    Catalog.Message is an attached DependencyProperty in this case, so it applies to a lot of controls (all ContentControl plus some more)

    The tool used to extract the translations from the assemblies (as opposed to gettext, where the extraction is done on source code) and xaml output a .po. The same tool can also transform to and from .resx, so you end up with only a single file (.po) to translate.

    NOTE: I'm contributing to this project from time to time, so my views could be biased.