0

this is my first time posting on here so please be indulgent.

I am currently trying to localize a WPF application to Chinese. I am using .resx Resource Files and want to access those files from my .xaml code to display the right Strings. Unfortunately there seems to be a problem when changing the culture to chinese : although the right Strings are displayed, my XamMenu becomes disabled (displayed in grey and unclickable) and I have no idea why, there is no error message, just an unusable item. Here is my code.

On application startup :

 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh");

In MainWindow.xaml file :

 <ig:XamMenu x:Name="_mainMenuCtrl" Grid.Row="0" Height="25" VerticalAlignment="Top" Background="AliceBlue" >
                <ig:XamMenuItem Header="{x:Static res:Resources.File}" Height="25" VerticalAlignment="Bottom">
                    <ig:XamMenuItem x:Name="_newProjectMenuItem" Header="{x:Static res:Resources.NewProject}" InputGestureText="{StaticResource menuNewProjectInputGesture}" Command="{Binding NewProjectCommand}">
                      .......
                    </ig:XamMenuItem>
                </ig:XamMenuItem>
            </ig:XamMenu>

I have two resource files in the project, Resources.resx and Resources.zh.resx.

For some reason the menu works perfectly fine when I try to use any other culture (for instance using "fr" instead of "zh" in both code and resource file name). It also works when replacing XamMenu and XamMenuItem tags with Menu and MenuItem.

If anyone has any idea why this could happen that'll be very helpful. I couldn't find any relevant information on culture restrictions when using XamMenu, this is why I'm asking on here.

FrankM
  • 1,007
  • 6
  • 15
Celia
  • 1
  • Look at the following post: https://stackoverflow.com/questions/28987368/net-chinese-cultureinfo-zh-does-not-exist. Try to use zh-CN language culture name, for example. – Jackdaw Jul 09 '18 at 13:51
  • zh-CN, zh-Hans, cz-Hant, zh-CHS all have the same effect – Celia Jul 09 '18 at 14:28

1 Answers1

0

The main reason for your unexpected behavior is the command binding, not the localization.


You can try to remove the command binding Command="{Binding NewProjectCommand}" and view your new localization behavior. You'll find that the menu becomes clickable and the localization works correctly.

Maybe you should post your NewProjectCommand implementation here, and I guess that the CanExecute of this command may have used an unlocalized string comparison to determine whether the command is enabled.

So, you should do this: Check your NewProjectCommand implementation to view the CanExecute localization.

walterlv
  • 2,366
  • 13
  • 73
  • Thanks for your answer. It wasn't about the command but you were right about the string comparison. I had localized a string in an app launching method which prevented the menus from being enabled. – Celia Jul 10 '18 at 08:19
  • Glad you find out the key problem. – walterlv Jul 10 '18 at 08:22