0

I'm developing an App on IOS which will get some information from Wikipedia. I should request the information from Wikipedia based on user language.

For example in english the URL is: https://en.wikipedia.org/w/api.php?...

but in french it's: https://fr.wikipedia.org/w/api.php?...

Is there a service on Wikipedia to find the appropriate base URL?

At this time I have written the following code but I'm not sure it's the best way to proceed and if it will work with all languages.

    let locaLanguageCode = NSLocale.currentLocale().objectForKey(NSLocaleLanguageCode) as? String
    var languageCode = "en"
    if let newLanguage = locaLanguageCode {
        languageCode = newLanguage
    }

    Alamofire.request(.GET, "https://" + languageCode + ".wikipedia.org/w/api.php", parameters: ["action": "query", "list" : "geosearch", "gscoord" : "48.804318|2.122081", "gsradius" : "10000", "gslimit" : "10", "format" : "json"])
        .responseJSON { response in
            debugPrint(response)
            print("Request \(response.request)")  // original URL request
            print("Response \(response.response)") // URL response
            print("Data \(response.data)")     // server data

            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
    }
sebastien
  • 2,489
  • 5
  • 26
  • 47
  • Possible duplicate of [Retrieve another language of a Wikipedia page](http://stackoverflow.com/questions/4143713/retrieve-another-language-of-a-wikipedia-page) – leo Jan 30 '16 at 15:19
  • It's not a duplicate. I don't want to translate a page from one language to another. I'm using Wikipedia api to look for pages around a lat/long but when the user is French, I want to look for pages in French but when the user is from US, I want to look for pages in English. I need to build the URL to query pages using the appropriate language, like https://en.wikipedia.org for English or https://fr/wikipedia.org for French... – sebastien Feb 01 '16 at 21:40
  • There is no difference in the API between different Wikipedia editions, so just changing the language prefix should work. – leo Feb 02 '16 at 06:07
  • I agree but how to find the right prefix using the user local? I'm doing it in the right way? Will it work for all languages? Thanks ;-) – sebastien Feb 02 '16 at 06:11
  • The prefixes are _almost always_ the ISO 639 codes for the corresponding languages. The are currently only [13 exceptions](https://meta.wikimedia.org/wiki/List_of_Wikipedias) (e.g. `simple` and `ksh`). If you are asking how to retrieve all available Wikipedia editions, some different methods are outlined here: http://stackoverflow.com/questions/33608751/retrieve-a-list-of-all-wikipedia-languages-programmatically – leo Feb 02 '16 at 06:33

0 Answers0