views:

57

answers:

1
+3  Q: 

Translation error

NSString *soundURL = [NSString stringWithFormat:@"http://translate.google.com/translate_tts?q=%@&tl=%@",strTextOfFilter,strCodeOfLanguage];
        NSLog(@"URL : %@",soundURL); 

this show:http://translate.google.com/translate_tts?q=%E4%BD%A0%E5%A5%BD&tl=zh-TW

copy url to Browser of firefox. it's right Translation of Chinese,but to Browser of safari ,it's error! why Translation Chinese is error. others language is right!! please help me !!!

    NSData *soundData = [NSData dataWithContentsOfURL:[NSURL URLWithString:soundURL]];
    NSLog(@"returnSoundData:%@",[NSURL URLWithString:soundURL]);
    NSError *err = nil;
    AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:soundData error: &err];
    [player play];
+3  A: 

Just put &ie=UTF-8 explicitly at the end of the URL, both in Safari and in your code.

http://translate.google.com/translate_tts?q=%E4%BD%A0%E5%A5%BD&tl=zh-TW&ie=UTF-8

does the job. I guess the Google server was confused by the encoding used.

Yuji
thanks very much! It's ok! I want to be your friends!
raien
You're welcome:) As another East Asian, I can feel your pain about encodings ...
Yuji