I'm in the process of translating a WPF window. I'm using WPF Localize Extension . So far I only have a Spanish translation for testing purposes in <Resource>.es.resx
file . At design time translations work . So I guess I'm on the right track .
I have included menu items to translate the GUI dynamically at run time . Initially I tried this (naïve) command ...
public class CmdTranslateUI : ICommand
{
bool ICommand.CanExecute(object parameter)
{
// TODO: Query available translations
return true;
}
public event EventHandler CanExecuteChanged;
void ICommand.Execute(object parameter)
{
LocalizeDictionary.Instance.Culture = new CultureInfo(
(string) parameter);
}
}
... and menu items for each language are bound to it in XAML this way .
<MenuItem Header="Español" CommandParameter="es-ES">
<MenuItem.Command>
<l:CmdTranslateUI />
</MenuItem.Command>
</MenuItem>
The fact is that such approach is not working . Culture info remains set to "en-US"
anyway . I read that on setting LocalizeDictionary.Instance.Culture
its DictionaryEvent
is triggered, so I thought this would update the GUI automatically . Obviously I'm wrong .
On the other hand , it seems current thread's culture won't influence library behavior either.
So I ask ...
Q:
- What's the recommended approach to translate a window at run time with WPF Localize Extension ?
- How could I list available translations ?
Thanks in advance .