How to translate Strings from a . resx file?

Asked

Viewed 913 times

1

I am creating a small application in C# and would like to translate it into English, because I intend to publish it and most of the target audience speaks English.

Searching, I discovered that I can use Visual Studio’s own tools to translate the interface of the program under development, but at no time did I find how I could translate strings used internally in the code, which will be represented in the course of using the program in the form of messages.

What is the best way to get these strings to be translated without the need to modify the code?

A practical example would be, rather than:

MessageBox.Show("Olá mundo!");

Something like:

MessageBox.Show(String.HelloWord);

Being in charge of the application choose the language automatically.

  • 1

    I believe it will help you answer this question: http://answall.com/questions/13232/comorinternationalizar-valores-do-enum

  • Thanks for the tip, @Caputo, but reading the question, I found the answer too complex, for two factors: I don’t even know what it is Enum or Resolver. There’s no such thing as simpler?

  • There is. I answered another question almost like yours here: http://answall.com/questions/17594/internacionaliza%C3%A7%C3%A3o-com-c-mvc/17600#17600

1 answer

2


You can create multiple resource files(Resource files).

Resource files can be used to store strings which will be translated into other languages.

Let’s say you have a resource file Resource.resx, will serve as default English words.

If you want to add English language support, you need to add a resource file Resource.en.resx (this file contains exactly the keys as the file in Portuguese, but the values will be the words translated in English) in the same directory.

Whenever the system language changes to English, for example, the . NET will automatically use the correct resource file. Similarly you can add support for other languages you want just by adding resource file with the correct extension.

Here have an example.

  • Thank you! If you are not abusing your goodwill, but there is some way to embed the files .dll of languages directly on .exe of the app?

  • 1

    @Renanlazarotto have a look at this link http://stackoverflow.com/questions/1793256/how-to-embed-multilanguage-resx-or-resources-files-in-single-exe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.