1

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.

weiszam
  • 187
  • 4
  • 14

1 Answers1

3

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.

Community
  • 1
  • 1
  • Okay, this really works and is amazing. But is there a way to solve that problem, that a variable goes in the middle of the text in one language, and it goes to the end of the text in another language? – weiszam Jun 18 '13 at 14:06
  • This one has an issue. So far I had exact texts everywhere, and now I started replacing them with the Localized.resx things. It worked fine, but when I replaced the whole project in the _Form1.Designer.cs_, one tiny modification in the _Form1.cs [Design]_ replaced all the Localized.resx links with real texts, so all my work is gone. How should I solve this? When modifying the Design area, the links disappear. – weiszam Jun 19 '13 at 12:00
  • Did you set Form.Localizable = true? –  Jun 19 '13 at 12:36
  • Not yet, I'll try and then I comment again. – weiszam Jun 19 '13 at 12:38
  • This is crucial for it to work. :) This is why i meant that reading the articles in MSDN is helpful. –  Jun 19 '13 at 12:49
  • Okay it seems to be working now. I'll get back to you when something's going wrong again. Thanks! – weiszam Jun 19 '13 at 13:09
  • One tiny bit of problem still remains: I have a Form1.resx, where there are some strings, but Localized.resx is not identified there because of it is some xml file. What to do? – weiszam Jun 20 '13 at 18:43
  • If you have added the Localizes.resx with Add New Item there should also be a Localized.Designer.cs whrer the Properties to access the strings are generated into. The strings in Localized.resx should be accessible in code like Localized.MyStringKey. Localized.resx is meant to be accessed from code not from Designer. Strings for the Designer will be stored in Form1.resx (and language specific resx if you have set Form1.Localizable = true. –  Jun 21 '13 at 08:21
  • Okay thanks to your links and description , I have now a language specific Form1.resx. I'll go translate that one, too :) – weiszam Jun 21 '13 at 09:09