# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Translation -------------------------------------------------------------------------------------------
#
# Dependencies	: main.kmm ($macroPrefBranch, OpenURL)
# Resources	: -
# Preferences	: kmeleon.plugins.macros.translation.to
#
# ------------------------------------------------------------------------------------------------------------------

Translate_From{
$_from=$ARG; &_Translate;
}
Translate_To{
alert(_("Available target languages:")."\n\n".sub("%s",en,_("English\t\t = %s"))."\n\n".sub("%s",es,_("Spanish\t\t = %s"))."\n".sub("%s",pt,_("Portuguese\t = %s"))."\n".sub("%s",fr,_("French\t\t = %s"))."\n".sub("%s",de,_("German\t\t = %s"))."\n".sub("%s",nl,_("Dutch\t\t = %s"))."\n".sub("%s",it,_("Italian\t\t = %s"))."\n".sub("%s",el,_("Greek\t\t = %s"))."\n\n".sub("%s",ru,_("Russian\t\t = %s"))."\n".sub("%s",ko,_("Korean\t\t = %s"))."\n".sub("%s",ja,_("Japanese\t\t = %s"))."\n".sub("%s",zt,_("Chinese (Traditional) = %s"))."\n".sub("%s",zh,_("Chinese (Simplified)\t = %s"))."\n\n"._("Enter the desired language's two-letter code into the following prompt."),$_Translate_srvc,INFO);
&_Translate_pref;
$_to=prompt(_("Two-letter target language code:"),$_Translate_srvc,$_to);
$_to==""?0:setpref(STRING,$_Translate_pref,$_to);
}

# ----- PRIVATE

$_Translate_pref=$macroPrefBranch."translate.to";
$_Translate_srvc=_("Babel Fish Translation");
$_Translate_text="http://babelfish.altavista.com/babelfish/tr?lp=<from>_<to>&urltext=";
$_Translate_page="http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=<from>_<to>&url=";

_Translate{
&_Translate_pref; $OpenURL=$SelectedText; $OpenURL==""?&_Translate_page:&_Translate_text;
}
_Translate_pref{
$_to=getpref(STRING,$_Translate_pref); $_to==""?$_to=en:0;
}
_Translate_text{
$OpenURL=sub("<from>",$_from,sub("<to>",$_to,$_Translate_text)).urlencode($OpenURL); &OpenURL_Selected;
}
_Translate_page{
$OpenURL=sub("<from>",$_from,sub("<to>",$_to,$_Translate_page)).urlencode($URL);
index($URL,"http://")==0?&OpenURL_Typed:alert(_("Sorry, local and secure pages cannot be translated!"),$_Translate_srvc,INFO);
}

_Translate_BuildMenu{
# tools menu
$__t="&Translate From";
setmenu(WebServices,popup,$__t);
$__m="Translate_From(";
setmenu($__t,macro,"&English",$__m."en)");
setmenu($__t,separator,-1);
setmenu($__t,macro,"&Spanish",$__m."es)");
setmenu($__t,macro,"&Portuguese",$__m."pt)");
setmenu($__t,macro,"&French",$__m."fr)");
setmenu($__t,macro,"&German",$__m."de)");
setmenu($__t,macro,"&Dutch",$__m."nl)");
setmenu($__t,macro,"&Italian",$__m."it)");
setmenu($__t,macro,"Gr&eek",$__m."el)");
setmenu($__t,separator,-1);
setmenu($__t,macro,"&Russian",$__m."ru)");
setmenu($__t,macro,"&Korean",$__m."ko)");
setmenu($__t,macro,"&Japanese",$__m."ja)");
setmenu($__t,macro,"&Chinese (Traditional)",$__m."zt)");
setmenu($__t,macro,"Chi&nese (Simplified)",$__m."zh)");
setmenu($__t,separator,-1);
setmenu($__t,macro,"&To (Specify Language)...",Translate_To);
# context menus
setmenu(Selection,popup,$__t);
}
$OnInit=$OnInit."_Translate_BuildMenu;";

# ------------------------------------------------------------------------------------------------------------------
$macroModules=$macroModules."Translate;";