How to Configure Google Translate API v2 on localhost

Popular automatic website translation tool

How to Configure Google Translate API v2 on localhost

Postby E.Ogunkeye » Wed Apr 09, 2014 5:46 pm

Hi,

I am trying to translate text on my basic webpage that I created on localhost However, I always keep receiving the Access Not Configured. Please enable the Google API error. I have already enabled the Translate API in my Google Developer account, I created both a server and browser API key (any suggestions on what I should add in my referers would be great thanks, my screen dump link underneath may help you with the option).

I was wondering if there is any alternative way I can get this API v2 to work on my localhost machine? Please see screen dump link for error.

Here on the website, I am trying to translate the UK word on google, with the Translate API V2 enabled and the browser key running in the background of the application I am using for this process, the UK word should translate to a language of my choice, however, as shown below, an error pops up.

Here is the link that shows screen dump

http://www.efe-ogunkeye.com/u.jpg - I am running the script through WAMPDeveloper on my local machine.

In the referrer section within the APIs & auth --> Credentials on my Google Developer account I added the following localhost URL paths hoping that it would work:

*.ikeogunkeye.com
http://www.ikeogunkeye.com
http://www.ikeogunkeye.com/
http://www.ikeogunkeye.com/*
ikeogunkeye.com/*
http://www.ikeogunkeye.com/cgi-bin/dictafy20.cgi
http://www.ikeogunkeye.com/cgi-bin/*
ikeogunkeye.com/cgi-bin/dictafy20.cgi
ikeogunkeye.com/cgi-bin/dictafy20.cgi/*


However I received no luck.


Any one that can help me with this issue, or if you have any further questions please let let me know? Your assistance is much appreciated.

Thanks
E.Ogunkeye
 
Posts: 3
Joined: Wed Apr 09, 2014 5:38 pm

Re: How to Configure Google Translate API v2 on localhost

Postby Edvard » Wed Apr 09, 2014 5:50 pm

Hi,

Your topic seems to be not related to this forum. However I may try to help you.

Please describe what you want to do and may be share some of your code here, so I can understand and try to help you.

Thanks!
Regards,

Edvard Ananyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Edvard
Site Admin
 
Posts: 4183
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia

Re: How to Configure Google Translate API v2 on localhost

Postby E.Ogunkeye » Wed Apr 09, 2014 6:31 pm

Hi,

My apologies for the irrelevant topic as I thought I would be able to find some solutions to my issue here.

I will give it a shot in describing my objective. Basically I am trying to producing a system that translates any duplicated webpage through a one-word one-click/one-press mode. The idea is I grab the URL of a link, put it within the system and the output will show a duplicated version of the link, with a small pop-up box showing the translated version of a word as soon as I move my cursor to that specific word and press the SHIFT key.

The idea of this project is not originally mine, I am trying to implement it with reference from:

http://www.securecottage.com/cgi-bin/reference.cgi and https://code.google.com/p/googletrans/ (I have contacted the author that created the system, he has managed to help me through half of the process, but the difficulty lies in actually showing the translated words from localhost machine, the author did not use localhost, he paid for hosting which I currently cannot afford due to financial difficulties).

My apologies if my response does not make sense, if you need me to clarify even further I am happy to do so. Any help/assistance would be greatly appreciated.


Thanks
E.Ogunkeye
 
Posts: 3
Joined: Wed Apr 09, 2014 5:38 pm

Re: How to Configure Google Translate API v2 on localhost

Postby Edvard » Wed Apr 09, 2014 6:51 pm

OK I understand you, it doesn't matter if your script which translates words is located on your localhost, it should work without issues. Can you post the part of your script which communicates with Google Translate through the API, so I can help you?

Thanks!
Regards,

Edvard Ananyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Edvard
Site Admin
 
Posts: 4183
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia

Re: How to Configure Google Translate API v2 on localhost

Postby E.Ogunkeye » Wed Apr 09, 2014 7:27 pm

Here are some of the parts I think you are referring to from the dictionarylookup20a.js file, referenced. I avoided inserting it further list of coding that I thought was not relevant to your question so that you do not end up looking at a long list.

Code: Select all

var SCGoogleAPIKeyV2 = "API Key Here";  // put your own Google language API V2 key here.

var SCtextDetect="";
function SCGoogleDetectV2(text,wholetext)
{
     
      SCtextDetect = wholetext;
      var sourceText = encodeURIComponent(text);
       

      var source = 'https://www.googleapis.com/language/translate/v2?key=' +
       SCGoogleAPIKeyV2 /*+'&source='+SCtranslateFrom*/+'&target=' +
       SCtranslateTo +
       '&callback=SCDetectedText&q=' + sourceText
       ;

       SCimportScriptURI(source);

}

var SCgoogletranslate = "";
function SCgoogleLookup(text,label)
{
     
      SClabel = label;
      SCtext = text;
     
    if(typeof SCbaseurl != "undefined")
    {
   
    SCgoogletranslate =
      "http://translate.google.com/translate?hl=en" + "&tl=" + SCtranslateTo +"&u=" +
          encodeURIComponent(SCbaseurl + "?" + SCbaseparamlist);
   
    }
    else
    {
   
   SCgoogletranslate =
       "http://translate.google.com/translate?hl=en" + "&tl=" + SCtranslateTo +"&u=" +
          encodeURIComponent(document.location.href);
   
    }
     
      var sourceText = encodeURIComponent(text);
       

      var source1 = 'https://www.googleapis.com/language/translate/v2?key=' +
       SCGoogleAPIKeyV2 +'&target=' +
       SCtranslateTo  +
       '&callback=SCTranslatedText&q=' + sourceText
       ;
       
       SCimportScriptURI(source1); 
}

E.Ogunkeye
 
Posts: 3
Joined: Wed Apr 09, 2014 5:38 pm

Re: How to Configure Google Translate API v2 on localhost

Postby Edvard » Wed Apr 09, 2014 7:35 pm

OK, I see a couple of design problems here. I guess you got this script from somewhere. In the past Google Translate API has been free with some limits, so people were not aware using javascript to get translations. Currently using Google Translate API key is not free and you need to pay for translations, so using your API key in javascript file is not safe, since people can see your API key and use it without your knowledge.

You need to write a server side script for translations trough the Google Translate API and refer to it with javascript to get a translation, you need to think also to be able to protect yourself from unauthorized use of your service.

Let me know if this info was helpful.

Thanks!
Regards,

Edvard Ananyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Edvard
Site Admin
 
Posts: 4183
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia


  • Related Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests

2GLux