Changing Localization on the fly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Z3JlZw==?=

    Changing Localization on the fly

    I've got a windows forms application that uses french and english. We're
    localizing it right now. It does appear to work if I set the language

    Thread.CurrentT hread.CurrentCu lture = new CultureInfo("fr-CA");
    Thread.CurrentT hread.CurrentUI Culture = new CultureInfo("fr-CA");

    Just before we run it.

    How can I setup a button that will toggle the language while the program is
    running? It seems once it's running, changing the language has no effect.

    Thanks,
    Greg
  • Alberto Poblacion

    #2
    Re: Changing Localization on the fly

    "greg" <thefish@nospam .nospamwrote in message
    news:53116570-AB79-4288-A3CE-0B9DB5403F97@mi crosoft.com...
    I've got a windows forms application that uses french and english. We're
    localizing it right now. It does appear to work if I set the language
    >
    Thread.CurrentT hread.CurrentCu lture = new CultureInfo("fr-CA");
    Thread.CurrentT hread.CurrentUI Culture = new CultureInfo("fr-CA");
    >
    Just before we run it.
    >
    How can I setup a button that will toggle the language while the program
    is
    running? It seems once it's running, changing the language has no effect.
    The language is processed in the Constructor of the Form. So once a form
    is already constructed, it won't change language. After you change the
    Thread.CurrentT hread.CurrentUI Culture, new forms that you open will show in
    the new language, but the form itself from which you executed that change,
    as well as any previously opened forms, will not change. You can close and
    reopen the current form if you want it to show in the new language.

    Comment

    • Ashutosh Bhawasinka

      #3
      Re: Changing Localization on the fly

      Localization data(strings and other data if any) are stored in satellite
      dlls. So, once a dll is loaded, you can't unload that dll and load
      another dll. The only way to change that (as far as I know) is to
      restart your application. It applies to both .Net applications and MFC
      applications.

      Thanks & Regards,
      Ashutosh

      greg wrote:
      I've got a windows forms application that uses french and english. We're
      localizing it right now. It does appear to work if I set the language
      >
      Thread.CurrentT hread.CurrentCu lture = new CultureInfo("fr-CA");
      Thread.CurrentT hread.CurrentUI Culture = new CultureInfo("fr-CA");
      >
      Just before we run it.
      >
      How can I setup a button that will toggle the language while the program is
      running? It seems once it's running, changing the language has no effect.
      >
      Thanks,
      Greg
      >

      Comment

      • =?Utf-8?B?V2FsdGVyIEZyYW5r?=

        #4
        RE: Changing Localization on the fly

        Hi Greg,

        you can change it, look how it's done in
        Windows Form Designer generated code.

        Basically it's working like this:


        private void localize(Cultur eInfo culture)
        {
        Thread.CurrentT hread.CurrentUI Culture = culture;

        foreach (Form form in Application.Ope nForms)
        ApplyControlRes ources(new
        ComponentResour ceManager(form. GetType()), form);
        }

        private void ApplyControlRes ources
        (ComponentResou rceManager resourceManager , Control control)
        {
        if (control is Form)
        resourceManager .ApplyResources (control, "$this");
        else
        resourceManager .ApplyResources (control, control.Name);

        if (control is IContainerContr ol)
        {
        foreach (Control childControl in control.Control s)
        {
        ApplyControlRes ources(resource Manager, childControl);
        }
        }
        }

        Additional, you have to iterate through each forms menus and do the same.

        Walter

        Comment

        • Hongye Sun [MSFT]

          #5
          RE: Changing Localization on the fly

          Hi Greg,

          Walter has provided a great solution to this question.

          This solution works because the ComponentResour ceManager.Apply Resources
          will load the resource dll at runtime. It will not impact the performance
          because the loading will only happen in the first time to apply the
          resource and later the resource dll will stay in memory.

          Please try Walter's solution and let us know if you have any problem when
          implementing it. Thanks.

          Regards,
          Hongye Sun (hongyes@online .microsoft.com, remove 'online.')
          Microsoft Online Community Support

          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          =============== =============== =============== =====
          Get notification to my posts through email? Please refer to
          http://msdn.microsoft.com/en-us/subs...#notifications.

          Note: MSDN Managed Newsgroup support offering is for non-urgent issues
          where an initial response from the community or a Microsoft Support
          Engineer within 2 business day is acceptable. Please note that each follow
          up response may take approximately 2 business days as the support
          professional working with you may need further investigation to reach the
          most efficient resolution. The offering is not appropriate for situations
          that require urgent, real-time or phone-based interactions. Issues of this
          nature are best handled working with a dedicated Microsoft Support Engineer
          by contacting Microsoft Customer Support Services (CSS) at

          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          • Grant Frisken

            #6
            Re: Changing Localization on the fly

            On Nov 4, 2:43 am, greg <thef...@nospam .nospamwrote:
            I've got a windows forms application that uses french and english. We're
            localizing it right now. It does appear to work if I set the language
            >
              Thread.CurrentT hread.CurrentCu lture = new CultureInfo("fr-CA");
              Thread.CurrentT hread.CurrentUI Culture = new CultureInfo("fr-CA");
            >
            Just before we run it.
            >
            How can I setup a button that will toggle the language while the program is
            running? It seems once it's running, changing the language has no effect.
            >
            Have a look at the following article on code project:



            It provides a component that allows you to change the active culture
            of all forms/controls in your application.

            Regards
            Grant Frisken
            Infralution

            Infralution Globalizer.NET - localization made easy

            Comment

            • Hongye Sun [MSFT]

              #7
              RE: Changing Localization on the fly

              Hi Greg,

              I have not heard from you for several days. I am writing to check the staus
              of this issue. Would you mind letting us know any progress from your side?
              If you have any problem regarding this issue, please feel free to let us
              know. It is our pleasure to help you. Thanks.

              Have a nice day.

              Regards,
              Hongye Sun (hongyes@online .microsoft.com, remove 'online.')
              Microsoft Online Community Support

              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.
               
              This posting is provided "AS IS" with no warranties, and confers no rights.

              Comment

              Working...