Not proprietary, others are welcome to use - glad to be able to contribute something back. To see it in action, goto
http://www.ecoscentric.com/
To add this feature, all that is needed is this piece of code below - added before you declare any menus.
Code: Select all
// Extract the google translate backend address if present, local server name and local url part.
var ec_URL = location.href;
var ec_lang = 'en';
var ec_trans = ec_URL.match(/^(http:\/\/\d+\.\d+\.\d+\.\d+\/translate\w+\?)hl=([\w\-]+)&langpair=([^&]+)&u=http:\/\/([^\/]+)\/(.*)$/);
if (ec_trans) {
ec_URL = 'http://'+ec_trans[4]+'/'+ec_trans[5];
ec_lang = ec_trans[2];
}
// Provide the url link, via translation site if necessary
function add_url(item) {
if (ec_trans)
return 'pagematch=/'+item +
';url=`'+ec_trans[1]+
'hl='+ec_trans[2]+
'&langpair='+ec_trans[3]+
'&u=http://'+ec_trans[4]+'/'+item+'`;';
return "url=/"+item+";";
}
function goto_page(item) {
top.location.href = item;
}
As google translate does not modify the links for the Milonic Menu navigation to go via it's backend, you need to do this yourself when you are being translated. Otherwise when someone navigates the site through the MM system, you will return back to the original version of that page. Also, you will end up in a google translate frame which is misleading as it gives the impression the page is being translated.
To work around this, use the functions add_url() and goto_page() declared above.
- add_url() is used to provide the url for aI() - either direct or through translate.
goto_page() is used to remove the google frame and return to the original english (in our case) version.
So, instead of declaring your menus like this:
Code: Select all
with(milonic=new menuname("Company")){
style=menuStyle;
aI("text=About;url=/about.shtml;");
aI("text=Contact;url=/contact.shtml;");
aI("text=People;url=/people.shtml;");
aI("text=Careers;url=/careers.shtml;");
}
declare your menus like this:
Code: Select all
with(milonic=new menuname("Company")){
style=menuStyle;
aI("text=About;"+add_url("about.shtml"));
aI("text=Contact;"+add_url("contact.shtml"));
aI("text=People;"+add_url("people.shtml"));
aI("text=Careers;"+add_url("careers.shtml"));
}
As for providing the translation, we simply add a translation menu item to our main menu with sub-menu:
Code: Select all
with(milonic=new menuname("Translate")){
style=menuStyle;
imagealign='right';
menualign='right';
menuwidth=122;
aI("text=`About Translation`;"+add_url("abouttrans.shtml"));
if (ec_lang == "en") {
aI("imagepadding=2;overimage=/images/trans_arabic.gif;pageimage=/images/trans_arabic.gif;image=/images/trans_arabic.gif;url=`http://translate.google.com/translate?langpair=en%7Car&hl=ar&u="+ec_URL+"`;text=` `");
aI("imagepadding=2;overimage=/images/trans_chinese.gif;pageimage=/images/trans_chinese.gif;image=/images/trans_chinese.gif;url=`http://translate.google.com/translate?langpair=en%7Czh-CN&hl=zh-CN&u="+ec_URL+"`;text=` `");
aI("imagepadding=2;overimage=/images/flag_germany.gif;pageimage=/images/flag_germany.gif;image=/images/flag_germany.gif;url=`http://translate.google.com/translate?langpair=en%7Cde&hl=de&u="+ec_URL+"`;text=`Deutsch`");
aI("imagepadding=2;overimage=/images/flag_spain.gif;pageimage=/images/flag_spain.gif;image=/images/flag_spain.gif;url=`http://translate.google.com/translate?langpair=en%7Ces&hl=es&u="+ec_URL+"`;text=`Español`");
aI("imagepadding=2;overimage=/images/flag_france.gif;pageimage=/images/flag_france.gif;image=/images/flag_france.gif;url=`http://translate.google.com/translate?langpair=en%7Cfr&hl=fr&u="+ec_URL+"`;text=`Français`");
aI("imagepadding=2;overimage=/images/flag_italy.gif;pageimage=/images/flag_italy.gif;image=/images/flag_italy.gif;url=`http://translate.google.com/translate?langpair=en%7Cit&hl=it&u="+ec_URL+"`;text=`Italiano`");
aI("imagepadding=2;overimage=/images/trans_japanese.gif;pageimage=/images/trans_japanese.gif;image=/images/trans_japanese.gif;url=`http://translate.google.com/translate?langpair=en%7Cja&hl=ja&u="+ec_URL+"`;text=` `");
aI("imagepadding=2;overimage=/images/trans_korean.gif;pageimage=/images/trans_korean.gif;image=/images/trans_korean.gif;url=`http://translate.google.com/translate?langpair=en%7Cko&hl=ko&u="+ec_URL+"`;text=` `");
aI("imagepadding=2;overimage=/images/flag_portugal.gif;pageimage=/images/flag_portugal.gif;image=/images/flag_portugal.gif;url=`http://translate.google.com/translate?&langpair=en%7Cpt&hl=pt&u="+ec_URL+"`;text=`Portuguese`");
} else {
aI("imagepadding=2;overimage=/images/flag_us_uk.gif;pageimage=/images/flag_us_uk.gif;image=/images/flag_us_uk.gif;url=javascript:goto_page('"+ec_URL+"');text=`English`");
}
}
This provides options to translate to all languages supported by google translate, unless you are already within a translated page in which case you get the option to return to english using the call to goto_page();
You could replace the individual items with your own map, something like the Milonic Alta-Vista translate map translate example, if you wanted to get fancy. We do this for the non-javascript enabled versions of our pages, if you want to see another example.
Have fun
