问题描述
我们有一个资源文件,其中包含许多翻译后的字符串,在我们的应用程序中的不同位置使用.有没有更好的方法来将按钮的文本绑定到某个字符串?
We have a resource file with lots of translated strings used various places in our application. Is there a better way for binding for example the text of a button to a certain string?
目前我们通常只是在构造函数、Load 事件处理程序或由其中之一调用的方法中执行类似的操作:
Currently we are usually just doing something like this in the constructor, in a Load event handler or in a method called by one of those:
someButton.Text = CommonTexts.SomeString;
someMenuItem.Text = CommonTexts.SomeOtherString;
有没有更好的方法呢?也许在设计师?或者这是推荐的做法?
Is there a better way to do it? Maybe in the designer? Or is this the recommended way of doing it?
只是让您知道我们如何进行实际翻译:我们有一个仅包含 resx 文件的类库项目.主要的 resx 文件是用英文编写的(当然).然后,我们在我们(或其他人)名为 ResEx 的应用程序中打开这些基本 resx 文件翻译成其他语言.编译后,Visual Studio 会自动为每种语言创建程序集,这些程序集会根据当前的文化集自动使用.这工作得很好,所以我真的不需要关于如何进行翻译等的信息(尽管我总是对改进感到好奇).我要问的是,是否有更好的方法可以将这些翻译后的字符串从资源程序集中获取到所有各种 Text
属性中.
Just to let you know how we do the actual translation: We have one Class Library project which only contains resx files. The main resx files are written in english (of course). We then open up those base resx files in an application called ResEx where we (or someone else) does the translation to other languages. When compiled Visual Studio automatically creates assemblies for each language which are used automatically depending on the current culture set. This works pretty well, so I don't really need info on how to do the translation and such (although I am always curious to improvements of course). What I am asking is if there is a better way for getting those translated strings from the resource assembly and into all the various Text
properties.
推荐答案
我明白,这是一个老问题,但我仍然有同样的问题(VS 2010),谷歌的第一个链接之一就是这个主题.
I understand, it's an old question, but still, I had the same issue (VS 2010), and one of the first links in google is this topic.
为了将所有文本移动到表单资源文件 - 您需要将 winform Localizable 属性设置为 True.就是这样.:)(c) 上限.哦.
In order to move all the texts to forms resource file - you need to set the winform Localizable property to True. And that's it. :) (c) Cap. O.
这篇关于C#:如何将 winforms 按钮的文本绑定到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!