Question

I have a big project written in my native language (hun) in c# with Visual Studio 2012.

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

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

Was it helpful?

Solution

There is a build in way in .Net using resx files.

  • You can find the short introduction here.

  • More on Programmers stackexchange

  • MSDN is quite extensive with it's documentation about this topic and it is a good read. 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.

The .Net applications able to change translations on the fly usually use custom made internationalization e.g. loading text files and refreshing the 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.

  1. Add a resx file to your project like Localized.resx
  2. Add a string property "CountText" with value {0} text text.
  3. Add a second resx Localized.en.resx
  4. Add string property "CountText" with value text text {0}. to Localized.en.resx
  5. Where you write your progress to the GUI use 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.

To learn about all the possibilities especially translating with VS you really should go through the MSDN library articles. Translation can get cumbersome if you miss something.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top