本地化Windows窗体

编程入门 行业动态 更新时间:2024-10-27 06:33:06
本文介绍了本地化Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从事一个涉及本地化大量Windows窗体的项目.

I'm working on a project that involves localizing a large number of Windows Forms.

我们正在使用TableLayoutPanel控件处理布局,效果很好.

We're dealing with layout using the TableLayoutPanel control, which works nicely.

我们遇到的一个问题是,当我们将Form.Localizable属性设置为True时,我们最终不得不为每种语言的每种表单管理一个.resx文件.如果.resx文件仅包含本地化文本,但它还包含该表单的大量布局数据,那会很好.

One area we're striking problems with is when we set the Form.Localizable property to True, we then end up having to manage one .resx file per form per language. That'd be fine if the .resx files only contained the Localized text, but it also contains a vast amount of layout data for the form.

是否有一种方法可以将可本地化的文本元素从控件布局信息中分离出来,并在Visual Studio IDE中继续起作用?

Is there a way to separate the localizable text elements from the control layout information, that continues to work in the visual studio IDE?

我注意到我可以修改表单的设计器文件以查看另一个资源文件,但是当我使用表单设计器时,这些更改将被删除:

I've noticed that I can modify my the form's designer file to look at another resource file, but when I use the form designer, these changes are deleted:

' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Dock = System.Windows.Forms.DockStyle.Top Me.Label1.Location = New System.Drawing.Point(3, 0) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(61, 13) Me.Label1.TabIndex = 1 Me.Label1.Text = My.Resources.ResourceManager.GetString("Form1_Label1_Text")

推荐答案

我从未找到对此完全满意的答案.但这是我最终实现的解决方案:

I never found an answer to this I was completely happy with. But this is the solution I ended up implementing:

  • 我最终设置为Form.Localizable = false,因为我不想维护所有这些相同的.resx文件

  • I ended up setting Form.Localizable = false because I didn't want to maintain all those identical .resx files

    所有UI元素都获得一个实际未本地化的值(例如"O_K _").

    All the UI elements get a de-facto value (like "O_K_") that is visibly not localized.

    我将表单/控件与其他所有可本地化的内容(错误消息,日志消息等)完全相同,只是给了它们唯一的键(例如"cmdOkTextOK"),以便它们可以在多个表单之间共享

    I treated the form / controls exactly the same as all my other localizable content (error messages, log messages etc.) and just gave them unique keys like "cmdOkTextOK" so they could be shared across multiple forms

    我在每种表单上创建了LocalizeComponent()函数,并在InitializeComponent()函数之后立即从构造函数中调用它,如下所示:

    I created LocalizeComponent() functions on every form and called it from the constructor immediately after the InitializeComponent() function, as follows:

    Public Class Form1 Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. LocalizeComponent() End Sub Private Sub LocalizeComponent() ' Localizes all the ui elements from a common Resource Me.SuspendLayout() Me.cmdOK.Text = My.Resources.ResourceManager.GetString("cmdOKTextOK") Me.cmdCancel.Text = My.Resources.ResourceManager.GetString("cmdCancelTextCancel") Me.cmdApply.Text = My.Resources.ResourceManager.GetString("cmdApplyTextApply") Me.ResumeLayout(False) End Sub End Class

    这会将可见控件的本地化移出设计器文件(每次我进行表单编辑时,销毁该文件),然后将其放回我的控制之下.

    This moves the localization of visible control elements out of the designer file (where it was destroyed each time I did a form edit) and puts it back under my control.

    我仍然不是100%满意,因为控件是在运行时使用非本地化的字符串创建的,后来又更新了这些字符串.但这将使我免于真正不需要的维护噩梦!

    I'm still not 100% happy, because the controls are being created with non-localized strings at run time that are latter being updated. But it will save me from a maintenance nightmare I really don't want!

    感谢所有麻烦回答的人.我很感激!我不确定您在回答自己的问题以将其标记为已回答"时打算做什么,因此,如果有人可以指出我的意思而又不会使我感到非常糟糕,那将不胜感激.

  • 更多推荐

    本地化Windows窗体

    本文发布于:2023-11-03 07:50:53,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1554614.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:窗体   Windows

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!