Localized UI with XAML files

Related to changes suggested in PR 1645 I have made a few changes to how xaml files are being loaded. These changes allow loading different xaml files for specific languages, or merging localized string dictionaries

Under new method:

  • If a localized version of a xaml file (e.g. Window.xaml) files exists that would be loaded. For example if user locale is set to Farsi (fa) and Window.fa.xaml exists, that would be loaded as main window.
  • If a localized resource dictionary xaml file e.g. Window.ResourceDictionary.fa.xaml exist that would be merged into the ResourceDictionary of main xaml file Window.xaml

I have added two unit test buttons for these two methods:

Test XAML (Localized)

Test XAML (Localized Resource)

This is available in WIP installer (added unit tests for two methods or ui localization · eirannejad/pyRevit@73ee4fa · GitHub)

3 Likes

How to localize the text that is inside the code?

Kinda up to you at this point. I haven’t figured out an easy way to do that. You can use the xaml resource files as well and reference those from the Window Resources. Maybe we can add a method to read those in a non-ui script as well

Can I use get_locale_string from WPFWindow? or this method has been abandoned by mistake?