I'm trying to use the google translate api's to... well translate some text, but its behaving strangely. When my query (the text to be translated) contains no spaces, it works fine, however as soon as I introduce a space into the query, i get no results back. This is my code:
-(void)translateText:(NSString *)originalText {
//Construct request url
NSString *urlString = [NSString stringWithFormat:@"http://ajax.googleapis.com/ajax/services/language/translate?q=%@&v=1.0&langpair=en%%7cde", originalText];
NSURL *url = [NSURL URLWithString:urlString];
// Get the contents of the URL as a string, and parse the JSON into Foundation objects
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
//Get out the translated text
NSDictionary *results = [jsonString JSONValue];
NSString *answer = [[results objectForKey:@"responseData"] objectForKey:@"translatedText"];
self.translatedText = answer;
}
I can't figure out what the hell is happening. Any ideas?