I have a wpf application and I’m starting to localize it. The strategy for localization I chose was to create my custom MarkupExtension class.
I won’t be using the .res files since at my company there is a solution that is already made which creates an encrypted map with all the strings and it requires int keys to refer to each string. So I wrote a custom generator that creates an enum with all the ‘int’ keys (could be a static class with ints, it doesn’t really matter).
So I want to refer to each of these enum keys at my XAML files, doing:
<Label Content="{l:Translator {x:Static l:TranslatedEnums.MainWindow_WelcomeMessage}}" />
The created enum is TranslatedEnums and my translator class is called Translator (dhu).
But after reading the x:Static documentation and the type converters documentation, the following question came to my mind:
Does the “compiled xaml” (baml) actually evaluates each of these types (via x:Static) at runtime or compile-time?
I’m asking this because one of the reasons I’m referring to the enum value statically is so that I don’t have the exact enum string key, but rather it’s value, which would make hacking the application a little bit harder.
If the resolution is done at runtime, then I could narrow my previous code to:
<Label Content="{l:Translator MainWindow_WelcomeMessage}" />
Which would require the lookup for the enum value by my own, but this is a one-liner:
TranslatedEnums result;
Enum.TryParse(key, out result);
Which would make the Xaml code smaller (which is good), but it would fail at compile-time if the key didn’t exist (which is not a problem).
It’s actually at xaml load-time (as stated here). if you only load your xaml onece, you could consider it at run-time.