Skip to content

Instantly share code, notes, and snippets.

@katopz
Last active December 19, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katopz/5994612 to your computer and use it in GitHub Desktop.
Save katopz/5994612 to your computer and use it in GitHub Desktop.
Will open google translate website for mobile and translate sent word to English
const NSString *_GOOGLE_URI = @"http://translate.google.com/m/translate?hl=en&sl=auto&tl=en&ie=UTF-8&prev=_m&q=";
-(void) openWebViewForGGranslate : (UIWebView*) webView translate: (NSString *) targetString
{
// clean up new line at end of string
targetString = [targetString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// escape URL encode
targetString = [targetString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// merge cmd+args
NSString *fullURL = [NSString stringWithFormat:@"%@%@", _GOOGLE_URI, targetString];
// NSString -> NSURL
NSURL *url = [NSURL URLWithString:fullURL];
// load request
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment