Harshit
Harshit

Reputation: 11

Devexpress Localization

I have a WindowsForm application having all text(On form labels/buttons/other controls) written in the Norwegian language. I want to convert all text in English using localization. Is there any way in Devexpress where we can convert all text into English without writing the meaning of every text in a resource file manually? For example:- In the attachment, "Brukernavn" is hardcoded on a label. I want to auto-convert it into English without assigning its value in English-ResourceFile. What should be the approach in Devexpress localization?

enter image description here

Upvotes: 0

Views: 848

Answers (1)

demoncrate
demoncrate

Reputation: 390

I'm not aware of any Devexpress method to do this. A good solution would be to actually do the work of building a localisation file for English which would work like following.

  • Add a InternationlisationLayer to your application.
  • This layer scours the application to locate all Controls you would possible want to translate.
  • After finding all Controls you have to match their Text values to the translated text.
  • After finding a matching English text you will have to replace the Text Property on these Controls.

If you want to avoid building a proper Localisation system a far easier solution is explained below.

  • Make a List of type and fill it with all control texts you want translated.
  • Translate the strings and add format them as such that you have a Dictionary of type (where Key would be the original text and Value being the translated text).
  • At application Start get a list of all Controls you want to translate and do something like the following:

        public static IEnumerable<System.Windows.Forms.Control> GetAllControlsOfType(this      System.Windows.Forms.Control control, Type type)
        {
            var controls = control.Controls.Cast<System.Windows.Forms.Control>();
    
            return controls.SelectMany(ctrl => GetAllControlsOfType(ctrl, type))
             .Concat(controls)
             .Where(c => c.GetType() == type);
        }
    
        public void DoTranslation()
        {
            var ctrls = this.GetAllControlsOfTypes(new List<Type>() { typeof(Label), typeof(Button) });
            foreach (var ctr in ctrls)
            {
                var element = dict.FirstOrDefault(i => i.Key == ctr.Text);
                ctr.Text = element.Value;
            }
        }
    

Upvotes: 0

Related Questions