简体   繁体   English

翻译Visual Studio项目

[英]Translating a Visual Studio project

I have a big project written in my native language (hun) in c# with Visual Studio 2012. 我用Visual Studio 2012在c#中用我的母语(hun)编写了一个大项目。

I'd like to translate it to english. 我想把它翻译成英文。

Of course if I get a text in hungarian, I can translate it, so the point is not about how to translate a text, but how to make the whole translation easier. 当然,如果我收到匈牙利语的文本,我可以翻译它,所以重点不是如何翻译文本,而是如何使整个翻译更容易。 I don't need the software to change the language while runtime, it is also ok if I get a different project with a different language. 我不需要软件在运行时更改语言,如果我使用不同的语言获得不同的项目也可以。 One way is go go through the whole project and change all the labels, but that's a lot of work, and because I modify the whole project, I would have to do it all over again. 一种方法是通过整个项目并更改所有标签,但这是很多工作,因为我修改整个项目,我将不得不重新做一遍。

I've written another program which finds labels marked with "..." in the project files (like 'Form1.cs', etc.), and I could translate those. 我写了另一个程序,在项目文件中找到标有“...”的标签(比如'Form1.cs'等),我可以翻译它们。 This had a lot of mistakes. 这有很多错误。 For example Visual Studio splits long text, so I got those strings seperated, so it was still a lot of work after the whole translation. 例如,Visual Studio会分割长文本,因此我将这些字符串分开,因此在整个翻译之后仍然需要做很多工作。

Another idea was replacing all the strings with array things, like instead of writing "Cancel" , writing t[201] or something like that, and then I could translate the t variable only. 另一个想法是用数组的东西替换所有的字符串,比如写“取消” ,写t [201]或类似的东西,然后我只能翻译t变量。 But that's also a lot of work and there's a problem if I include a variable in a text. 但这也是很多工作,如果我在文本中包含变量就会出现问题。

For excample, in hungarian I might write '2 masodperc maradt' , but I should translate that to 'Remaining seconds: 2' , or something like that. 例如,在匈牙利语中,我可能会写'2 masodperc maradt' ,但我应该将其翻译为'Remaining seconds:2' ,或类似的东西。 Then I have to mind the included variables. 然后我必须考虑包含的变量。

So what do you think the easiest way is to do the translation, and how do other programmers do this? 那么您认为最简单的方法是进行翻译,其他程序员如何做到这一点呢?

For excample TotalCommander changes the language in a second, without restarting or anything. 对于例子,TotalCommander会在一秒钟内更改语言,而无需重新启动或进行任何操作。

There is a build in way in .Net using resx files. 在.Net中使用resx文件进行构建。

  • You can find the short introduction here . 你可以在这里找到简短的介绍。

  • More on Programmers stackexchange 更多关于程序员stackexchange

  • MSDN is quite extensive with it's documentation about this topic and it is a good read. MSDN相当广泛,有关于这个主题的文档,这是一个很好的阅读。 MSDN MSDN

There are a lot of Tools out there helping with the translation based on .Net localization but you can also do it in VS directly. 有很多工具可以帮助进行基于.Net本地化的翻译,但你也可以直接在VS中进行。

The .Net applications able to change translations on the fly usually use custom made internationalization eg loading text files and refreshing the GUI. 能够在运行中更改翻译的.Net应用程序通常使用自定义国际化,例如加载文本文件和刷新GUI。

If you want to do something like that on your own be aware that you also have to resize controls so that the text fits. 如果您想自己做类似的事情,请注意您还需要调整控件大小以使文本适合。

For your problem wiht #count text text and text text #count you can use string.Format like. 对于你的问题#count文本文本和文本文本#count你可以使用string.Format之类的。

  1. Add a resx file to your project like Localized.resx 将resx文件添加到项目中,如Localized.resx
  2. Add a string property "CountText" with value {0} text text. 添加值为{0}文本文本的字符串属性“CountText”。
  3. Add a second resx Localized.en.resx 添加第二个resx Localized.en.resx
  4. Add string property "CountText" with value text text {0}. 添加带有值文本文本{0}的字符串属性“CountText”。 to Localized.en.resx 到Localized.en.resx
  5. Where you write your progress to the GUI use string.Format(Localized.CountText, myCount); 在将您的进度写入GUI的地方使用string.Format(Localized.CountText,myCount);
  6. Switch the program language as shown in the first link. 切换程序语言,如第一个链接所示。
  7. .Net automatically loads the corresponding resource for a language. .Net自动加载语言的相应资源。

To learn about all the possibilities especially translating with VS you really should go through the MSDN library articles. 要了解所有可能的内容,特别是使用VS进行翻译,您应该阅读MSDN库文章。 Translation can get cumbersome if you miss something. 如果你错过了什么,翻译会变得很麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM