Search code examples
c#wpfvisual-studioxamllocalization

WPF Localization without resx files


I am currently using .resx files to localize my app. Works great, I can use the resources both in XAML and in C# code and I can also change language at runtime. But the resulting .dll resources are always rebuilt and are seen by SVN as "new" files, even thought they don't contain any changes. Also, if I want to change any text for whatever reason, I will have to rebuild the app again.

Is there an alternative way to localize my app? Preferably I would have:

  • Resources in human readable format (such as xml/json), so that any typos can be corrected by simply modifying the contents of the file, without rebuilding the app.
  • Keep the ability to switch language at runtime.
  • Use these resource in both XAML and C#.

Solution

  • Sure! you can create your own resource management system, using json, or whatever you want as the backing storage. But it is probably more work than you think.

    Notably, you might need to write your own code generator so you can refer to the language file using properties, and thus IDE hints etc, and not strings. And this would cause it to suffer some of the same problems as the resx-file. Notably that you need to recompile the application, since you do not know if strings where added and removed, or if they are used in the application. But it could allow changes to existing strings, and 'live' reload.

    However, I would suggest fixing your actual problems instead:

    But the resulting .dll resources are always rebuilt

    Then you have some incorrect configuration of your build system. A project should only be rebuild if its files, or any dependencies, have changed. A possible reason for rebuilds are files set as "copy always" in the properties. If you have issues, create a new project with a resx-file, check that it does not rebuild without changes, and compare settings with your actual project.

    always rebuilt and are seen by SVN as "new" files

    The standard practice is to not commit dlls or other built files into source control. See svn ignore. Building the software is the job of the Continous Integration system.

    A possible alternative would be to use xaml resource dictionaries for translation strings. I think that should allow live changes, but I have not used this method.