Last active
December 19, 2015 17:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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