0

So attempting to use the wpf localization extension.

Our buttons / controls all have their IDs stored in the code behind, and as such I wound up creating a translations service to translate in the code behind also. So it just binds the completed translation.

We also have our translations stored in a separate project as an external group handles the translations. As such my translation method is set up as follows.

private string Translate(string id)
{
    string uiString;

    var locExtension = new LocTextExtension
    {
        Key = "XXX.UI.Resources",
        ResourceIdentifierKey = id
    };

    locExtension.ResolveLocalizedValue( out uiString );
    return uiString ?? id;
}

When my page is loaded however, it seems as though it isn't translating the first button on the page. First button comes back as Buttun_BtnTxt rather than the translated value. I've tried swapping which button is the first in the list, and it's always the first one which fails.

If I put in some retry functionality it still fails. (put the above code in a while loop, checking for uistring == null, and retrying 50000 times)

If I navigate away from the first page, all other pages load fine, and if I navigate back to it, the translations happen fine too. just cannot for the life of me figure out why it isn't translating the first time around.

Has anyone had to do something like this in the past and had the same problem?


Had a further look. Added code to check loaded assemblies. On the first run through (where it's failing) this is the only instance of resources present.

XXX.UI.Resources, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

After the first attempt has failed I then checked the assemblies again, and now have the following entries also appearing.

XXX.UI.Resources.resources, Version=0.0.0.0, Culture=de-DE, PublicKeyToken=null
XXX.UI.Resources.resources, Version=0.0.0.0, Culture=ja-JP, PublicKeyToken=null
XXX.UI.Resources.resources, Version=0.0.0.0, Culture=zh-Hans, PublicKeyToken=null

No idea why these are delayed in loading, or whether that could be what's causing the problem. But it's the only thing I can think of right now.

user3265613
  • 355
  • 2
  • 14

1 Answers1

0

Eventually figured it out. I still needed to have the following stuff in my xaml.

xmlns:lex="http://wpflocalizeextension.codeplex.com"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="XXX.UI.Resources"
lex:ResxLocalizationProvider.DefaultDictionary="Resources"

At least once, without it the localization stuff doesn't work at all, even if you're doing the localization in code behind.

The reason it wasn't translating the first control was because it goes through the VM first, and then hit the xaml where this code was called. After which the codebehind translations worked fine.

Moved that xaml to my shellview and all is good.

user3265613
  • 355
  • 2
  • 14