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 the url to the firefox browser. this is correct Translation of Chinese, but in safari browser, this is a mistake! Why Chinese Translation is a mistake. other languages ​​are 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
source share
1 answer

Just put it &ie=UTF-8explicitly 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

performs this work. I assume the Google server was confused by the encoding used.

+4
source

Source: https://habr.com/ru/post/1763697/


All Articles