Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. howto: multi-languaged gui

howto: multi-languaged gui

Scheduled Pinned Locked Moved C#
c++csharpxmlquestionlearning
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rupel
    wrote on last edited by
    #1

    hi there, i want my app to appear in different languages. the user may choose his prefered language in an options-dialog. which way would YOU do that? * define a seperate class, containung a string-member for each string-constant? * some resource-thing (as it was with the string-tables in C++/MFC-times) * is there something built-in in C# for that purpose? * ... what about the language-files (containing all the strings)? is xml overkill? i'm currently in the phase of thinking about it, implementing comes later. my current favorite is as described - a class containing a string-member for each message initialized by an xml-file for each language. so when the user changes the language, the class just reads a different xml-file, rewrites all of its string-members and everything is redrawn/reassigned. but i'm not sure, if this is the best way... so if anyone has some hints, i would be glad to read them... :rose: :wq

    Z M 2 Replies Last reply
    0
    • R Rupel

      hi there, i want my app to appear in different languages. the user may choose his prefered language in an options-dialog. which way would YOU do that? * define a seperate class, containung a string-member for each string-constant? * some resource-thing (as it was with the string-tables in C++/MFC-times) * is there something built-in in C# for that purpose? * ... what about the language-files (containing all the strings)? is xml overkill? i'm currently in the phase of thinking about it, implementing comes later. my current favorite is as described - a class containing a string-member for each message initialized by an xml-file for each language. so when the user changes the language, the class just reads a different xml-file, rewrites all of its string-members and everything is redrawn/reassigned. but i'm not sure, if this is the best way... so if anyone has some hints, i would be glad to read them... :rose: :wq

      Z Offline
      Z Offline
      Zombies with Coffee LLC
      wrote on last edited by
      #2

      Have you seen the 'Language' property? Go to your dialog, change the 'Language' to the desired locale, and then .NET handles it for you. Was one of the neatest features I've seen in the IDE yet.

      R 1 Reply Last reply
      0
      • Z Zombies with Coffee LLC

        Have you seen the 'Language' property? Go to your dialog, change the 'Language' to the desired locale, and then .NET handles it for you. Was one of the neatest features I've seen in the IDE yet.

        R Offline
        R Offline
        Rupel
        wrote on last edited by
        #3

        what's the use? it didn't changed anything (i thought at least the system-menu-entries (minimize, maximize, move, etc.) should have changed) btw: this doesn't help with the menu and labels etc. because I assign the text-properties myself (or is there some hidden dictionary somewhere) :eek: ;) - and when i want my application to appear in a completely different language, all texts have to be changed. or am i getting something wrong...:~ :wq

        Z 1 Reply Last reply
        0
        • R Rupel

          what's the use? it didn't changed anything (i thought at least the system-menu-entries (minimize, maximize, move, etc.) should have changed) btw: this doesn't help with the menu and labels etc. because I assign the text-properties myself (or is there some hidden dictionary somewhere) :eek: ;) - and when i want my application to appear in a completely different language, all texts have to be changed. or am i getting something wrong...:~ :wq

          Z Offline
          Z Offline
          Zombies with Coffee LLC
          wrote on last edited by
          #4

          No, it doesn't change anything. You need to change it. Make a new dialog and put the text field 'Name:' Now change the language to French and rename the field 'Nom:' Now change the language back to English. Cool, eh?

          1 Reply Last reply
          0
          • R Rupel

            hi there, i want my app to appear in different languages. the user may choose his prefered language in an options-dialog. which way would YOU do that? * define a seperate class, containung a string-member for each string-constant? * some resource-thing (as it was with the string-tables in C++/MFC-times) * is there something built-in in C# for that purpose? * ... what about the language-files (containing all the strings)? is xml overkill? i'm currently in the phase of thinking about it, implementing comes later. my current favorite is as described - a class containing a string-member for each message initialized by an xml-file for each language. so when the user changes the language, the class just reads a different xml-file, rewrites all of its string-members and everything is redrawn/reassigned. but i'm not sure, if this is the best way... so if anyone has some hints, i would be glad to read them... :rose: :wq

            M Offline
            M Offline
            Michael Mac
            wrote on last edited by
            #5

            I would choose build-in function called globalization. In the property window there is a property called Language. First of all, enter text for your controls in the default language. Then change the language to another and change text. For one language the editor creates one .resx file the WinForms directory. For example: default language - MainForm.resx second language (in this case Polish) - MainForm.pl.resx For details see the documentation :)


            43 68 65 65 72 73 2c 4d 69 63 68 61 65 6c

            M 1 Reply Last reply
            0
            • M Michael Mac

              I would choose build-in function called globalization. In the property window there is a property called Language. First of all, enter text for your controls in the default language. Then change the language to another and change text. For one language the editor creates one .resx file the WinForms directory. For example: default language - MainForm.resx second language (in this case Polish) - MainForm.pl.resx For details see the documentation :)


              43 68 65 65 72 73 2c 4d 69 63 68 61 65 6c

              M Offline
              M Offline
              Michael Mac
              wrote on last edited by
              #6

              I almost forget. :) The following code shows how to change the language programmatically

              System.Globalization.CultureInfo culture =
              new System.Globalization.CultureInfo( "fr" );

              System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

              where fr is a language code ( see MSDN ).


              43 68 65 65 72 73 2c 4d 69 63 68 61 65 6c

              R 1 Reply Last reply
              0
              • M Michael Mac

                I almost forget. :) The following code shows how to change the language programmatically

                System.Globalization.CultureInfo culture =
                new System.Globalization.CultureInfo( "fr" );

                System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

                where fr is a language code ( see MSDN ).


                43 68 65 65 72 73 2c 4d 69 63 68 61 65 6c

                R Offline
                R Offline
                Rupel
                wrote on last edited by
                #7

                i just want to mention, that using the form-editor was a BAD idea. my menuitems are objects of my own menuitem-class - after just changing the language in the properties-window, the menu completely vanished. setting the language back to 'default' didn't bring it back! the variables are still there, but the AddRange-functions of the main menu items were absent. ok, i added them by hand. fault! the form-designer showed me an error-message instead of the form-preview. i corrected these things by changing the order of the variable-definitions (!!!) - but the designer now doesn't work, as he did before. the additional properties of my menuitems are set back each time i compile after using the form-designer... X| i tell you: you better stick to the standards when using the form-designer. i will do that all by hand from now on... :~ :wq

                M 1 Reply Last reply
                0
                • R Rupel

                  i just want to mention, that using the form-editor was a BAD idea. my menuitems are objects of my own menuitem-class - after just changing the language in the properties-window, the menu completely vanished. setting the language back to 'default' didn't bring it back! the variables are still there, but the AddRange-functions of the main menu items were absent. ok, i added them by hand. fault! the form-designer showed me an error-message instead of the form-preview. i corrected these things by changing the order of the variable-definitions (!!!) - but the designer now doesn't work, as he did before. the additional properties of my menuitems are set back each time i compile after using the form-designer... X| i tell you: you better stick to the standards when using the form-designer. i will do that all by hand from now on... :~ :wq

                  M Offline
                  M Offline
                  Michael Mac
                  wrote on last edited by
                  #8

                  The globalization function is cool. The C# designer seems not to work correctly with custom classes, for example Menu. :( I use globalization but I don't use designer. I write my own code. This code use Carlos H. Perez's library - designer is not supported. There is only one minus of it. You must create the resources yourself using resgen.exe and al.exe

                  private System.Resources.ResourceManager m_mResources = new System.Resources.ResourceManager(typeof(MainForm));
                  // MainMenu
                  ToolBarEx menuToolBar = new ToolBarEx( BarType.MenuBar );

                  // Menu File and its submenu
                  ToolBarItem menuFile = new ToolBarItem( (string)(m_mResources.GetObject("Menu.File")) );
                  MenuItem[] submenuFile = new MenuItem[3];
                  submenuFile[0] = new MenuItemEx( (string)(m_mResources.GetObject(
                  "Menu.File.Options")), new EventHandler( OptionsHandler ), Shortcut.CtrlO );
                  submenuFile[1] = new MenuItemEx( "-", null );
                  submenuFile[2] = new MenuItemEx( (string)(m_mResources.GetObject(
                  "Menu.File.Close")), new EventHandler( CloseHandler ) );

                  menuFile.MenuItems = submenuFile;


                  43 68 65 65 72 73 2c 4d 69 63 68 61 65 6c

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups