Posted By

Winkyboy on 11/06/12


Tagged

forms translate language international translation multi-language


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

thastyle


setLanguage in WinForms


 / Published in: C#
 

Just a snippet I like; this can be called on GotFocus or LostFocus of a field, and it attempts to set the input language to the desired language.

  1. private void fixLanguage(string whichLanguage)
  2. {
  3. string useLanguage;
  4. switch (whichLanguage.ToLower() )
  5. {
  6. case "chinese":
  7. useLanguage = "zh-CN";
  8. break;
  9. default:
  10. useLanguage = "en-US";
  11. break;
  12. }
  13. InputLanguage language = InputLanguage.CurrentInputLanguage;
  14. if (language.Culture.Name != useLanguage)
  15. {
  16. foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
  17. {
  18. if (lang.Culture.Name == useLanguage)
  19. {
  20. InputLanguage.CurrentInputLanguage = lang;
  21. }
  22. System.Console.WriteLine(lang.Culture.Name);
  23. }
  24. }
  25. if (language.Culture.Name == useLanguage)
  26. this.ImeMode = System.Windows.Forms.ImeMode.On;
  27. }

Report this snippet  

You need to login to post a comment.