In general this is correct, but there are a few simple mistakes.
On line 6,
var currentTab.url
is not valid syntax. Just call the variable something likecurrentUrl
.On line 6, it is
safari.application.activeBrowserWindow.activeTab
notsafari.application.activeBrowserWindow.currentTab
.On line 8,
url
is not a function, it is a property. Just assign it with an equals.
This should work:
<script>
safari.application.addEventListener("command", performCommand, false);
function performCommand(event) {
if (event.command == "translate") {
var currentUrl = safari.application.activeBrowserWindow.activeTab.url;
var rUrl = "http://translate.google.it/translate?u=" + encodeURIComponent(currentUrl) + "&sl=auto&tl=it&hl=&ie=UTF-8";
safari.application.activeBrowserWindow.activeTab.url = rUrl;
}
}
</script>