Reputation: 1663
I am using Google Translate in French and some letters of result come back to me as some symbols. After some research, I learned it is because of encoding but I need some help because I could not find enough information.
Here is my code:
- (void)performTranslation:(NSString *) inputStr {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *outLang = [defaults objectForKey:@"OutLanguage"];
NSString *inLang=@"tr";
NSString *textEscaped = [inputStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"textEscaped=%@",textEscaped);
NSString *url = [NSString
stringWithFormat:@"https://www.googleapis.com/language/translate/v2? key=AIzaSyAx5dSiKm1J-qkc0qKZpYnWhgFjYpoC84g&q=%@&source=%@&target=%@",textEscaped, inLang, outLang];
NSLog(@"REQ : -%@-", url);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"didReceiveResponse");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"didReceiveData=%@",data);
NSString *result = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"OUTPUT : %@", result);
}
I receive transfert d'argent
but I expect transfert d'argent
. This d'
letter needs different kind of encoding I guess.
Upvotes: 0
Views: 201
Reputation: 45598
'
is an html or xml entity. The data you are receiving has probably been xml encoded. You need to parse the response using a proper XML parser if this is the case. I'm guessing you are manually parsing out the data you want.
Upvotes: 1