locked
.NET assembly localization RRS feed

  • Question

  • Hi all,

    I have a .NET assembly containing localizable Windows forms. I want to set .NET assembly language localization by the calling application. I use the following code in the windows form class constructor to implement it:

    public MyAssemblyForm(string culture)
        {
            CultureInfo myCultureInfo = new CultureInfo(culture);
            Thread.CurrentThread.CurrentCulture = myCultureInfo;
            Thread.CurrentThread.CurrentUICulture = myCultureInfo;
            InitializeComponent();
        }

    But as a result the default language is used. I changed my project type from Assembly to Windows Application and provided some language directly (not default):

    public MyAssemblyForm()
        {
            CultureInfo myCultureInfo = new CultureInfo("fr-FR");
            Thread.CurrentThread.CurrentCulture = myCultureInfo;
            Thread.CurrentThread.CurrentUICulture = myCultureInfo;
            InitializeComponent();
        }

    I run it without additional application that calls it. That works fine and all resources having "fr-FR" suffix is used. Switching the project back to the class library type and calling MyAssemblyForm() constructor gives just default resources values. Does anybody know how to set assembly culture? Thanks in advance!

    Sunday, February 22, 2015 12:34 PM

Answers

  • Just setting the Thread.CurrentThread.CurrentUICulture property to another culture at runtime won't automatically change the language of all controls.

    You should call the ApplyResources method of the ComponentResourceManager class to "refresh" the resources for an object. Please refer to the ChangeLanguage method in step 5 of the following tutorial for more information: http://www.dotnetcurry.com/showarticle.aspx?ID=174

    Here is another link on the subject that might also be helpful: http://stackoverflow.com/questions/11711426/proper-way-to-change-language-at-runtime

    Hope that helps.

    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question.

    • Marked as answer by Fred Bao Wednesday, March 4, 2015 8:51 AM
    Sunday, February 22, 2015 2:09 PM