Localizing winforms in visual-studio-2012 express

梦想的初衷 提交于 2019-12-12 04:14:25

问题


I have a application previously developed in Visual Studio Express 2010. It uses localized winforms and resx resources used in code.

When the project is opened and compiled using Visual Studio Express 2012 on the same computer the localized strings are not applied, only the default code was found.

The application runs fine and in the winforms designer I can change language to see and edit the localized text of the controls. I also tried the following code to determine if the languages used were there at runtime, which did report the ones used.

        CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
        foreach (CultureInfo culture in cultures)
        {
            try
            {
                ResourceSet rs = resources.GetResourceSet(culture, true, false);
                // or ResourceSet rs = rm.GetResourceSet(new CultureInfo(culture.TwoLetterISOLanguageName), true, false);
                if (rs == null)
                    continue;
                string isSupported = (rs == null) ? " is not supported" : " is supported";
                Console.WriteLine(culture + isSupported);
            }
            catch (Exception)
            {
                Console.WriteLine(culture + " is not available on the machine or is an invalid culture identifier.");
            }
        }

Still when the application is running all I get is the resources for the default language.

I retrieve the resources using:

        ResourceManager resources = new ResourceManager(form.GetType());
        form.Text = resources.GetString("$this.Text", lang);

where I have verified that lang is correct, but also using

        System.Threading.Thread.CurrentThread.CurrentUICulture = lang;
        System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang.Name);

followed by usage of MyLangResxFile.MyStringResource. The strings returned are still only the default ones.

Might there be changes or limitations in resx localization support between Visual Studio Express 2010 - 2012?

Update: I noticed that the localisation works if compiled using msbuild.exe from 3.5 but when using 4.0... the localisations are missing as described above.


回答1:


sorry for "answering" that question but commenting is not working. I just want to ask if you could solve that issue in the meantime because I have exactly the same issue.

I even noticed that this issue only happens when target framework < 4.0 is selected. For target framework 4.0 and 4.5 localization is working as before in VS 2010...



来源:https://stackoverflow.com/questions/13153992/localizing-winforms-in-visual-studio-2012-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!