views:

79

answers:

1

Hi,

My application has to support multiple languages and should be able to switch the language on run time. For that purpose I am using LocalizationExtension from codeplex (http://wpflocalizeextension.codeplex.com/) I am using Ribbon Contorl in my application. I am creating ribbonCommands as window resource and Binding the LableTitle and other properties withLocalizationExtension class.

    <MvvmCore:RibbonCommandExtended x:Key="SwitchLanguageCommand" 
                            CanExecute="RibbonCommandExtended_CanExecute"
                            Executed="RibbonCommandExtended_Executed"
                            LabelTitle="{lex:LocText Key=SwitchLanguage,Dict=LanRes}"
                            ToolTipTitle="{lex:LocText Key=SwitchLanguage,Dict=LanRes}"
                            LargeImageSource="{lex:LocImage Key=ChangeLanguage,Dict=LanRes}"/>

Then assigning it to button Command property as static resource.

<rb:RibbonButton x:Name="EnglishButton" Command="{StaticResource SwitchToEnglishCommand}" Click="EnglishButton_Click">

Here is my RibbonCommandExtended class.

 public class RibbonCommandExtended : RibbonCommand
    {
        private ICommand m_command;
        public ICommand Command
        {
            get { return m_command; }
            set
            {
                m_command = value;
                if (m_command != null)
                {
                    this.CanExecute += UsCanExecute;
                    this.Executed += UsExecuted;
                }
                else
                {
                    this.CanExecute -= UsCanExecute;
                    this.Executed -= UsExecuted;
                }
            }
        }

        private void UsExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            Command.Execute(e.Parameter);
        }

        private void UsCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = Command.CanExecute(e.Parameter);
        }
    }

When my program starts, then the ribbon control picks the right language strings and images. But when I change the language on runtime then I could't see any change in ribbon control localized text and image. Because the RibbonCommand's LabelTitle, LargeImageSource and all other properties are not Dependency properties.

Have someone solved the issue already? Or is there any other way rather then LocalizationExtension to make my application localized so that it fulfills my requirements?

A: 

It is easy to use the LocalizationExtension to localize the application. But perhaps, we should back to the basic method to do the localization, separated culture resource and the change it on the run-time. Please refer to the http://msdn.microsoft.com/en-us/library/ms788718.aspx. You may need the Locbaml tool to generate the CVS that we can edit it for several culture, and then load the CSV to the resource dll file for different culture, and change it by the code:

Thread.CurrentThread.CurrentCulture = new CultureInfo(...); The following project provides a guidance about WPF localization - WPF Localization Guidance Whitepaper may help you: http://wpflocalization.codeplex.com/

Saghar