3

I want to translate the words using asp.net mvc3 , for example Good is a word. i want to translate the word into my specified language? how to do? advance in thank you...

2 Answers2

4

MVC Can't do traslation. you should be using some kind of service to do that for you

like google traslation APIs for DotNet as

https://code.google.com/p/google-language-api-for-dotnet/

You can creat a custom function as below to acheive that

public string TranslateText(string input, string languagePair)
{
    string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);
    WebClient webClient = new WebClient();
    webClient.Encoding = System.Text.Encoding.UTF8;
    string result = webClient.DownloadString(url);
    result = result.Substring(result.IndexOf("<span title=\"") + "<span title=\"".Length);
    result = result.Substring(result.IndexOf(">") + 1);
    result = result.Substring(0, result.IndexOf("</span>"));
    return result.Trim();
}

OR see this Question here on SO

Community
  • 1
  • 1
Raab
  • 34,778
  • 4
  • 50
  • 65
2

You could use an online language translation service such as the Google Translate API or Bing Translate. On the other hand if the words you want to translate are known beforehand you could localize your application using resource files. Checkout the following blog post from Scott Hanselman for more details.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • .NET doesn't have any translation services built-in. If the API provided by third party APIs is not good enough for you then I am afraid that you will have to write your own translation service. – Darin Dimitrov May 16 '13 at 06:12
  • ya okey sir, i will try to write own translation service or try to localize the words in my application using resource files.. –  May 16 '13 at 06:15
  • Sir, can you give more explain about on our own translation service? –  May 16 '13 at 06:21
  • What exactly do you need to know? You need to keep a list of all possible words for all languages you want to handle. And if you want to handle entire sentences and not just words things are going to be extremely complicated. This is an entire science behind it and books have been written on the subject. – Darin Dimitrov May 16 '13 at 06:23
  • sir, i give a example, i want to take a print in report, that time i will type in english, it should convert to my specified languages.. like that google translation... –  May 16 '13 at 06:26
  • As I already said this is too big subject to be discussed here. – Darin Dimitrov May 16 '13 at 06:35
  • 1
    You may take a look at the following page on Microsoft Research: http://research.microsoft.com/en-us/projects/mt/ It contains links to publications from scientist that worked on developing language translation algorithms. Please do not expect to get a couple of lines of code here on StackOverflow that will achieve this task. I repeat it once again and for the last time: this is an entire science and the reason why online translation services such as Google Translate exist. – Darin Dimitrov May 16 '13 at 06:46
  • Thank you so much for your guidance sir.. thank you sir.. i will refer that sir.. –  May 16 '13 at 06:49