Multilingual / Register own Service

Topics: Questions
Jun 27, 2014 at 1:10 PM

I read the documentation multilingual in catel. And I tell you what I try to achive.

I override the LanguageService and called it DbLanguageService. Not doing the same like in the example but has also to do with database.
    class DbLanguageService : LanguageService
        protected override string GetString(ILanguageSource languageSource, string resourceName, CultureInfo cultureInfo)
            return base.GetString(languageSource, resourceName, cultureInfo) ?? resourceName;
My service do nothing else then if the resourceName is not found return the given resourceName instead of null.

Now I want to display value from Database in my view.

<TextBlock Text="{Binding Name}" />

Name is a property in Viewmodel mapped to a Property in model. Property is filled from database.

The value of Name in Database is "Left"

Now I try to search the Name "Left" in Resources if the resource for the prefered Language is not found the resource key itself should be displayed.

With my own service its not a problem to do this in viewmodel.

GetString() returns the resourcekey if the reosurce is found.

But how to do this in view?

<TextBlock Text="{catel:LanguageBinding Name}" />

-> Now LanguageService search in the resources with the key "Name". Not with the value in the Property Name in viewmodel
Jun 27, 2014 at 2:25 PM
Maybe its easier to forget the bla bla before.

The only thing which is important

<TextBlock Text="{catel:LanguageBinding Name}" />

How to search in resources with the value of Name not with the Key "Name" itself.

I tried to resolve in this way;
<TextBlock  Text="{Binding Name, Converter={StaticResource LanguageConverter}}" />
  class LanguageConverter :  IValueConverter
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            var resource = value as string;

            if (resource != null)
                var languageService = ServiceLocator.Default.ResolveType<ILanguageService>();
                resource = languageService.GetString(resource);
            return resource;

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            throw new NotImplementedException();
The only problem is how to reload the bindings if the language is changed?