设置我所有表单的可本地化属性

发布于 2024-12-29 04:28:25 字数 123 浏览 0 评论 0原文

有没有办法自动设置此属性?我们有数百种表单需要本地化,将所有这些表单设置为 true 将是一场噩梦。

有没有办法让 Visual Studio 将解决方案/项目中的所有表单设置为 Localized = true ?

Is there a way to automate the set of this property ? we have hundreds of forms that needs to be localized and it will be a nightmare going through all of them setting this property to true.

is there a way to make visual studio set all forms in the solution / project to Localizable = true some how ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼窥荷 2025-01-05 04:28:25

当您创建一个新的Windows窗体时,它没有*.resx文件以及designer.cs文件中的相关代码。当您将Form的Localized属性设置为True时,VS会将以下代码添加到designer.cs中,但它也会生成并添加*.resx文件。

        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
        this.SuspendLayout();
        // 
        // Form2
        // 
        resources.ApplyResources(this, "$this");
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Name = "Form2";
        this.ResumeLayout(false);

由于 VS 添加了 *.resx 文件,因此无法仅查找和替换或剪切和粘贴代码。

我尝试记录一个 VS 宏来自动执行它,但是,它不会记录将可本地化属性更改为 True(不知道为什么)

这个临时宏可能是您的开始。您可以编写获取表单文件名列表并使用下面的宏代码循环遍历它们。

    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    DTE.ActiveWindow.Object.GetItem("WindowsFormsApplication1\WindowsFormsApplication1\Form3.cs").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ActiveWindow.Object.DoDefaultAction()
    DTE.Windows.Item(Constants.vsWindowKindProperties).Activate()

When you create a new Windows Form, it does not have have *.resx file and the related code in the designer.cs file. When you set the Form's Localizable property to True, VS adds the following code to the designer.cs but it also then generates and adds the *.resx file.

        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
        this.SuspendLayout();
        // 
        // Form2
        // 
        resources.ApplyResources(this, "$this");
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Name = "Form2";
        this.ResumeLayout(false);

Since VS adds the *.resx file, there is no way to find and replace or cut and paste only code.

I tried to record a VS Macro to automate it however, it would not record changing the Localizable property to True (not sure why)

This temp macro maybe a start for you. You could write get the list of your form filenames and loop through them with the macro code below.

    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    DTE.ActiveWindow.Object.GetItem("WindowsFormsApplication1\WindowsFormsApplication1\Form3.cs").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ActiveWindow.Object.DoDefaultAction()
    DTE.Windows.Item(Constants.vsWindowKindProperties).Activate()
虚拟世界 2025-01-05 04:28:25

它由表单的 .resx 文件中的如下条目表示(针对 .NET Framework 版本进行调整):

<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <value>True</value>
</metadata>

自动将所有值切换为 true 的最简单方法可能是运行表单子类文件,加载其 .resx 文件作为 XML 来测试该元素是否存在,如果不存在则添加它。或者,您可以使用 ResXResourceReader 和 ResXResourceWriter 来读取和写入文件内容。

It's represented by an entry like the following (adjusted for .NET Framework version) in the form's .resx file:

<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <value>True</value>
</metadata>

The easiest way to automate toggling all the values to true would probably be to run through the Form subclass files, loading their .resx files as XML to test for the presence of the element, and add it if it isn't. Alternately, you could use a ResXResourceReader and ResXResourceWriter to read and write the file contents.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文