private string TranslateLinks(srctargetpair arguments) { var validlinks = LoadOriginalPage(arguments.sourcesite); Dictionary<string, string> pagetoiwiki = MakeTranslationsList(validlinks, arguments); return ReplaceWords(pagetoiwiki); }
private Dictionary<string, string> MakeTranslationsList(IEnumerable<string> validlinks, srctargetpair arguments) { Dictionary<string, string> pagetoiwiki = new Dictionary<string, string>(); int i = 0; foreach (string link in validlinks) { // ERROR: do not access controls in background worker directly worker.ReportProgress(Convert.ToInt32(((decimal)i / (decimal)validlinks.Count()) * 100), "Processing interwiki"); XmlDocument interwikipage = new XmlDocument(); interwikipage.LoadXml(GetFromURL(@"http://" + arguments.sourcesite + @"/w/api.php?action=parse&redirects&prop=langlinks&format=xml&page=" + link)); XmlNodeList langlinks = interwikipage.GetElementsByTagName("ll"); var translatedlist = from XmlNode c in langlinks where c.Attributes["lang"].Value == arguments.targetlang select c.InnerText; string translatedlink = translatedlist.Count() != 0 ? translatedlist.First() : ""; pagetoiwiki.Add(link, translatedlink); ++i; Thread.Sleep(1000); } return pagetoiwiki; }