XAMLMarkupExtensions/WPFLocalizeExtension

Multiple resource files

Closed this issue · 2 comments

Hi dear person in front of the monitor,

Its not an issue, more likely a help request.

Im not able to copy the example (maybe its my fault) how to use multiple resource files.
I want to use several translation files to have a better organization.

There are these lines which is fine.
lex:ResxLocalizationProvider.DefaultAssembly="NameSpace.SubNameSpace"
lex:ResxLocalizationProvider.DefaultDictionary="ResourceName"

I can use the "ResourceName" resource. So thats cool.

What should I write If I want to refer an other resx file?

The other translations should come from binding.
In the database I only store identifiers which matches the ID in the resx files.
Text="{lex:Loc {Binding TODO}}" <- this can pull the corresponding ID from the default resx file and thats fine.
But what about if it should come from an another file?

Im looking for something like this:
Text="{lex:Loc NameSpace.SubNameSpace.ResxFileName {Binding TODO}}"

How should the binding look like?

Thanks in advance.

Hello, @Ataegina!
Unfortunately, Binding supports only default provider. But if you use ResxLocalizationProvider, it's possible just to specify the full key. You can do it with converter:

<TextBlock Text="{lex:Loc {Binding language, Converter={local:NamespaceConverter}}}">
public class NamespaceConverter  : TypeValueConverterBase, IValueConverter
{
    /// <inheritdoc />
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return $"HelloWorldWPF:Strings:{value}";
    }

    /// <inheritdoc />
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}

I don't know why, but unfortunately Binding.StringFormat not working too. I think converter is the best solution which I can offer now.

Thanks its working.
I just want to clarify for those who are interested in that "HelloWorldWPF" is only the root namespace and not the whole namespace route of the resx file.

Having a nice day