0

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#.
Goliatr
  • 13
  • 3
  • You can use resource dictionaries. A resource per phrase/word. One per language with matching keys. These can be plain text .xaml files. You can xamlreader.load into a resource dictionary in memory. You can transform XML to xaml if you wanted but an uncompiled xaml file is fairly readable. – Andy Jun 20 '23 at 18:07

1 Answers1

0

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.

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • Thank you for the answer! I've never done anything like that, where can I even start? Do you know of any tutorial or an article describing how to achieve this? I'm okay with rebuilding in case of adding/removing items, since I would have to make changes to the code anyway, but I hate to do this in case of typos. Also, having a human readable format of these files seems easier to work with the translation team, as this would just be a matter of exchanging files, without any extra exporting/importing/copy-pasting. – Goliatr Jun 21 '23 at 19:55
  • I've looked into the issue why these files are always "new" (even if I use build instead of rebuild). And only the dlls of resources have this issue, other dlls (from views/viewmodels) work as expected with SVN, i.e, they are recognized as new only if the source files contain changes. I came to the conclusion that these resources are "new" because somehow, a timestamp is encoded in the dll. But I will try doing as you suggested, maybe I missed something. Oh, and the project is under git source control, only the resulting application is under the SVN source control. – Goliatr Jun 21 '23 at 19:56
  • @Goliatr The translation team would get the resx-files, and they should be used to dealing with these. Sure, that means you need to receive the translation before you build/publish. But I would argue that you should publish complete, versioned, tested, packages of your applications, including program files, translations, images, documentation etc. Otherwise you are just increasing the risk of some version mismatch or other issue creeping in. – JonasH Jun 22 '23 at 06:27