Gu.Localization icon indicating copy to clipboard operation
Gu.Localization copied to clipboard

Translation in WPF IValueConverter

Open Enlooo opened this issue 3 years ago • 0 comments

App: WPF .Net 4.6.1

I set the language of the main window to Language = System.Windows.Markup.XmlLanguage.GetLanguage(CultureInfo.GetCultureInfo("de").IetfLanguageTag);

In any IValueConverter i get 'de-DE' as culture, which has 'de' as parent. So translating like

internal class CultureReturningConverter : IValueConverter
    {
        private static ITranslation SomeTranslation 
                = Translation.GetOrCreate(Properties.Resources.ResourceManager, nameof(Properties.Resources.SomeTranslation));

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return SomeTranslation.Translate(culture);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

is not possible, because the Translator doesn't know 'de-DE'.

grafik

Is it a wanted behavior or a bug? Should the Translator also check the parent culture on Translate(culture)?

Or is it simply a fault of mine?

Enlooo avatar Dec 09 '21 16:12 Enlooo