0
votes

currently, I am working on an extensible WPF application. Extensibility is achieved using a simple plugin system where each plugin is contained in itˋs own project, providing also an appropriate Viewmodel and a View, exposed as a DataTemplate.

I am now thinking about localization with resx files (which is pretty Standard). This works Fine for the main application but I was wondering how I can do this also for the plugins.

Thought about having localized resx files also within the plugins and binding to them in the plugin view. Is that a feasible route or are there any best practices to adhere to?

1

1 Answers

0
votes

WPF has it's own system for resources built right into the fundamentals.

Rather than using resx, a common wpf approach is to instead use resource dictionaries.

Each string you would substitute is an entry in a base resource dictionary. Usually english.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:WpfApp1"
                    xmlns:sys="clr-namespace:System;assembly=System.Runtime"
                    >
    <sys:String x:Key="Submit">Submit</sys:String>

Then used as a dynamicresource

    <Button Content="{DynamicResource Submit}"

You then build resource dictionaries for each other language which have matching x:Keys. When you merge one of these into application.current.resources the new values will be picked up.

This offers the option to have geometries, pictures and colours substituted in the same way. Often using multiple layers of resource dictionaries "over laid" in the way described above. This approach can then handle branding as well as localisation all in one.

There is another plus.

Resource dictionaries do not have to be compiled in order to merge them. You can have a resource dictionary which is editable by super user or substituted by department / organisation.

You can explicitly load a flat file into a resource dictionary using xamlreader.load(). Meaning your app can use a service to download the greek, french or whatever resource dictionary. Save that to local appdata for their user. Each time the user starts the app, that file is then merged in and they see the appropriate language text.