在Visual Studio 2012 Express中本地化Winforms [英] Localizing winforms in visual-studio-2012 express

查看:100
本文介绍了在Visual Studio 2012 Express中本地化Winforms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以前在Visual Studio Express 2010中开发的应用程序.它使用代码中使用的本地化winforms和resx资源.

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

在同一计算机上使用Visual Studio Express 2012打开和编译项目时,未应用本地化的字符串,仅找到默认代码.

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.

应用程序运行正常,在Winforms设计器中,我可以更改语言以查看和编辑控件的本地化文本. 我还尝试了以下代码来确定运行时是否使用了所使用的语言,这些语言确实报告了所使用的语言.

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);

我已验证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);

其次是使用MyLangResxFile.MyStringResource. 返回的字符串仍然只是默认字符串.

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

Visual Studio Express 2010-2012之间的resx本地化支持是否可能有更改或限制?

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

更新: 我注意到,如果使用3.5版中的msbuild.exe进行编译,则可以进行本地化,但是如果使用4.0版,则本地化会如上所述丢失.

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.

推荐答案

很抱歉回答"该问题,但评论不起作用. 我只想问一下您是否可以同时解决该问题,因为我有完全相同的问题.

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.

我什至注意到,仅当目标框架<选择了4.0.对于目标框架4.0和4.5,本地化工作与VS 2010中的以前一样……

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...

这篇关于在Visual Studio 2012 Express中本地化Winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆