开发者

Google Translate Api and Special Characters

I've rec开发者_C百科ently started using the google translate API inside a c# project. I am trying to translate some text from english to french. I am having issues with some special characters though.

For example the word Company comes thru as Société instead of Société as it should. Is there some way in code I can convert these to the correct special characters? ie (é to é)

Thanks

If you need anymore info let me know.


I ran into this same exact issue. If you're using the WebClient class to download the json response from google, try setting the Encoding property to UTF8.

using(var webClient = new WebClient { Encoding = Encoding.UTF8 })
{
    string json = webClient.DownloadString(someUri);
    ...
}


I have reproduced your problem, and it looks like you are using the UTF7 encoding. UTF8 is the way you need to go.

I use Google's API by creating a WebRequest to get an HTTP response from the server, then I read the response stream with a StreamReader. StreamReader defaults to UTF8, but to reproduce your problem, I passed Encoding.UTF7 into the StreamReader's constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜