(* Translations *) (* correcting misprints in translations *) transmisprints = { "<" ~~ ___ ~~ ">" -> "", "Agaricus silvicola" -> "Agaricus sylvicola", "hare'sfoot" -> "hare's foot" }; translatename[_, "en"] := {}; translatename[_, "ru"] := {}; misreps = {"0" -> "o"}; misrepsru = {"0" -> "", "O" -> "\:041e", "o" -> "\:043e", "E" -> "\:0415", "e" -> "\:0435"}; normalname[s_String] := Sort[StringSplit[ StringReplace[tolowercase[stringtrim[s]], misreps]]]; normalnameru[s_String] := Sort[StringSplit[ StringReplace[ StringReplace[tolowercase[stringtrim[s]], misrepsru], {"\:0451" -> "\:0435", "\:044f" -> "\:0430"}]]]; updatetranslation[lang_String, tabnames_List, function_] := Module[{table, names, name, trans, transold, transoldn, transnew}, table = tabnames; {names, trans} = Transpose[table]; trans = function /@ trans; If [!MatchQ[trans, List[List[___String] ...]], Print["Error: updatetranslation: ", {lang, tabnames[[1]], function}]]; trans = StringReplace[#, transmisprints]&/@trans; table = Transpose[{names, trans}]; Do[ {name, trans} = tab; If[(*MemberQ[namespic, name]*) True, (* Including translations of possible synonims *) transold = translatename[name, lang]; transoldn = If[lang === "ru", normalnameru /@ transold, normalname /@ transold]; transnew = trans; badchars = {"?"}; transnew = Select[transnew, (Intersection[Characters[#], badchars] === {})&]; If[lang == "en", transnew = Select[transnew, (!ifrussianlett[#] && ifenglishlett[#])&]]; If[lang == "ru", transnew = StringReplace[#, misrepsru]&/@transnew; transnew = Select[transnew, (ifrussianlett[#] && !ifenglishlett[#])&]]; transnew = Select[transnew, !MemberQ[Join[transoldn, badnamesn], If[lang === "ru", normalnameru[#], normalname[#]]] &]; translatename[name, lang] = Join[transold, transnew]], {tab, table}]; ]; maintainTranslations := ( Print["Running maintainTranslations ..."]; (* Sorting by first occurence *) listsortocc = Table[ pics = data[[3]]; picfirst = First[pics]; yrp = ToExpression /@ Take[picfirst, 3]; {yrp, data}, {data, datalist}]; listsortocc = Sort[listsortocc(*,OrderedQ[{#1[[1]],#2[[1]]}]&*)]; listsortocc = #[[2]] & /@ listsortocc; namespicocc = Reverse[#[[1]] & /@ listsortocc]; (* Reverse replacement list *) replnamesreverse = Reverse /@ replnames; (* my own translations *) file = ToFileName[dirwork, "transru.txt"]; checkfile[file]; lines = Import[file, "Lines"]; lines = Select[lines, !StringMatchQ[#, WhitespaceCharacter...]&]; lines = Select[lines, StringFreeQ[#, "XXX"]&]; linesru = Sort[lines]; mynamesru = Table[ tline = StringSplit[line, " - "]; If[Length[tline] =!= 2, {name, trans} = {"", {""}}; If[Length[tline] =!= 0, Print["Error: file ", file, ", line ", line, ": Length[tline] =!= 2"]; ], {name, trans} = tline; trans = StringSplit[trans, " "... ~~ "/" ~~ " "...]; If[trans[[1]] =!= "", translatename[name, "ru"] = Take[trans, 1]]; ]; trans = Drop[trans, 1]; {name, trans}, {line, lines}]; mynamesru = Select[mynamesru, (#[[2]] =!= {})&]; file = ToFileName[dirwork, "transen.txt"]; checkfile[file]; lines = Import[file, "Lines"]; lines = Select[lines, !StringMatchQ[#, WhitespaceCharacter...]&]; lines = Select[lines, StringFreeQ[#, "XXX"]&]; linesen = Sort[lines]; mynamesen = Table[ tline = StringSplit[line, " - "]; If[Length[tline] =!= 2, {name, trans} = {"", {""}}; If[Length[tline] =!= 0, Print["Error: file ", file, ", line ", line, ": Length[tline] =!= 2"]; ], {name, trans} = tline; trans = StringSplit[trans, " "... ~~ "/" ~~ " "...]; If[trans[[1]] =!= "", translatename[name, "en"] = Take[trans, 1]]; ]; trans = Drop[trans, 1]; {name, trans}, {line, lines}]; mynamesen = Select[mynamesen, (#[[2]] =!= {})&]; rusnameswiki = Table[ nameru = redirectru[name]; tr = ""; If[Head[nameru] === String, If[ifrussianlett[nameru], tr = {name, nameru}] ]; tr, {name, namespic}]; (* bad names *) file = ToFileName[dirwork, "badnames.txt"]; checkfile[file]; badnames = Import[file, "Lines"]; badnamesn = normalname/@badnames; rusnameswiki = Select[rusnameswiki, (# =!= "")&]; updatetranslation["en", engnames, Identity]; updatetranslation["ru", rusnamesWikigrib, Identity]; updatetranslation["ru", rusnames4, {#} &]; (* mycoweb *) updatetranslation["ru", rusnames5a, Identity]; (* Svetlova *) updatetranslation["ru", rusnameswiki, {#} &]; updatetranslation["ru", rusnames1, {#} &]; updatetranslation["ru", rusnames2, {#} &]; updatetranslation["ru", rusnames3, {#} &]; updatetranslation["ru", rusnames6, {#} &]; If[mynamesen =!= {}, updatetranslation["en", mynamesen, Identity]]; If[mynamesru =!= {}, updatetranslation["ru", mynamesru, Identity]]; (* Checking completeness of translation *) addlinesru = Table[ If[translatename[name, "ru"] === {}, url = "http://127.0.0.1:81/pictures/mushrooms/ru/" <> StringReplace[ToLowerCase[name], " " -> "_"] <> ".htm"; urlg = "http://www.google.com/search?q=%22" <> StringReplace[ToLowerCase[name], " " -> "+"] <> "%22+\:0433\:0440\:0438\:0431\:044b"; Print["Warning: no ", Hyperlink["ru-translation", urlg], ": ", Hyperlink[name, url]]; (* Expanding names *) names0 = {name}; names = Table[names0 /. repl, {repl, replnames}] // Flatten // Union; names = Table[names /. repl, {repl, replnamesreverse}] // Flatten // Union; names = Complement[names, names0]; If[names =!= {}, namestr = translatename[#, "ru"] & /@ names; If[Flatten[namestr] =!= {}, Print[name, " -> ", {names, namestr} // Transpose // TableForm]]; ]; {name, "XXXXXXXXXX"}, {}], {name, namespicocc}]; addlinesru = Select[addlinesru, (# =!= {})&]; file = ToFileName[dirwork, "transru-draft.txt"]; If[addlinesru =!= {}, Print["Warning: there are some names without Russian translations. Will be written to the file ", file]]; text = Join[linesru, StringJoin[Riffle[#, " - "]]&/@addlinesru]; text = StringJoin[Riffle[text, " "]]; Export[file, text, "Text"]; addlinesen = Table[ If[translatename[name, "en"] === {}, url = "http://127.0.0.1:81/pictures/mushrooms/en/" <> StringReplace[ToLowerCase[name], " " -> "_"] <> ".htm"; urlg = "http://www.google.com/search?q=%22" <> StringReplace[ToLowerCase[name], " " -> "+"] <> "%22+common+names"; Print["Warning: no ", Hyperlink["en-translation", urlg], ": ", Hyperlink[name, url]]; (* Expanding names *) names0 = {name}; names = Table[names0 /. repl, {repl, replnames}] // Flatten // Union; names = Table[names /. repl, {repl, replnamesreverse}] // Flatten // Union; names = Complement[names, names0]; If[names =!= {}, namestr = translatename[#, "en"] & /@ names; If[Flatten[namestr] =!= {}, Print[name, " -> ", {names, namestr} // Transpose // TableForm]]; ]; {name, "XXXXXXXXXX"}, {}], {name, namespicocc}]; addlinesen = Select[addlinesen, (# =!= {})&]; file = ToFileName[dirwork, "transen-draft.txt"]; If[addlinesen =!= {}, Print["Warning: there are some names without English translations. Will be written to the file ", file]]; text = Join[linesen, StringJoin[Riffle[#, " - "]]&/@addlinesen]; text = StringJoin[Riffle[text, " "]]; Export[file, text, "Text"]; (* Translations of families *) Do[ {f, rusf} = rusfname; rusfamily[f] = rusf, {rusfname, rusfnames}]; );