terminal: Define term_event_key_T as int32_t, not int.
[elinks.git] / contrib / lua / babelfish.lua
blob69a0670694ad3dbf03e1ab82c0a29e94d3857ca4
1 function babelfish (url)
2 local from, to, rest
3 local lang_pair
4 local param
5 local lang2code = {
6 ["chinese-simp"] = 'zh',
7 ["chinese-simple"] = 'zh',
8 ["chinese-simplified"] = 'zh',
9 ["chinese-trad"] = 'zt',
10 ["chinese-traditional"] = 'zt',
11 ["dutch"] = 'nl',
12 ["nederlands"] = 'nl',
13 ["Nederlands"] = 'nl',
14 ["german"] = 'de',
15 ["deutsch"] = 'de',
16 ["Deutsch"] = 'de',
17 ["english"] = 'en',
18 ["french"] = 'fr',
19 ["fran\231ais"] = 'fr',
20 ["greek"] = 'el',
21 ["italian"] = 'it',
22 ["italiano"] = 'it',
23 ["japanese"] = 'ja',
24 ["korean"] = 'ko',
25 ["portuguese"] = 'pt',
26 ["portugu\234s"] = 'pt',
27 ["russian"] = 'ru',
28 ["spanish"] = 'es',
29 ["espanol"] = 'es',
30 ["espa\241ol"] = 'es',
33 _,_,from,to,rest = string.find(url, '^bb%s*([^%s]+)[%s]+([^%s]+)[%s]*(.*)')
35 if not rest then return url,nil end
37 from = lang2code[from] or from
38 to = lang2code[to] or to
40 lang_pair = from..'_'..to
42 if string.find(rest, ':[^%s]') then
43 url = "http://babelfish.altavista.com/babelfish/urltrurl"
44 .."?url="..escape(rest)
45 .."&lp="..lang_pair
46 else
47 url = "http://babelfish.altavista.com/babelfish/tr"
48 .."?trtext="..escape(rest)
49 .."&lp="..lang_pair
50 end
52 return url,true
53 end
55 table.insert(goto_url_hooks, babelfish)