Question

i'm using a UIWebView and i've got a UITextField getting a string that i'm converting in URL in this way

NSString *composedUrlString = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",urlString];
NSURL *url = [NSURL URLWithString:composedUrlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];   
[self.webView loadRequest:urlRequest];

What i want is to create dynamic URLs based on the set language of the device (or any other way round, not using some sort of GPS to get position), so that in composedUrlString i will have

http://www.google.com/search?q=
http://www.google.it/search?q=
http://www.google.fr/search?q=
http://www.google.de/search?q=

depending on the country. Actually i'm asking if there's a way to get the different com, it, fr to implement this code

NSString *composedUrlString = [NSString stringWithFormat:@"http://www.google.%@/search?q=%@",localLanguage, urlString];

thanks in advance

Was it helpful?

Solution

Google can use the hl parameter to specify a language, however it will still use the .com site.

If this works for you, change the search URL, and use the device's locale to set the search language, like this:

[NSString stringWithFormat:@"http://www.google.com/search?q=%@&hl=%@", urlString, [[NSLocale preferredLanguages] objectAtIndex:0]]

If this is not good enough, you will have to create a mapping between locales and their corresponding TLDs and make sure Google is available on these TLDs. See here a list of countries and their TLD domains.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top