Zend Framework google translate usage - zend-framework

I'm trying to translate automatic a string using the google translator! Using Zend_Http_CLient is not able to log in in the application and retrieve the translated words. It returns to me an authentication error.
I google and searched here something about it but had no success. Can someone give a hand on it and tell me where can I find some idea on how to use Zend_Gdata with Google Translate and authenticate at the service?
Thanks a lot, best regard's.

As far as i know Zend GData classes doesn't support google translate yet
source : http://framework.zend.com/manual/en/zend.gdata.html
in the same page you would find a link to this : http://code.google.com/p/gtranslate-api-php/
i had give it a simple try and it seems to be working BUT note the comment in the class declaration
Google requires attribution for their
Language API, please see:
http://code.google.com/apis/ajaxlanguage/documentation/#Branding
hopefully that would help
please provide the error message to make your question more clear
thanks

$client = new Zend_Http_Client('http://ajax.googleapis.com/ajax/services/language/translate', array(
'maxredirects' => 0,
'timeout' => 30));
$client->setParameterGet(array(
'v' => '1.0',
'q' => 'Привет',
'langpair' => 'ru|en'
));
$response = $client->request();
$data = $response->getBody();
$server_result = json_decode($data);
$status = $server_result->responseStatus; // should be 200
$details = $server_result->responseDetails;
$result = $server_result->responseData->translatedText;
echo $result;
die;

There's no official Google Translate, yet. But this translation adapter might help:
http://www.zfsnippets.com/snippets/view/id/35
Also, if you do use this, be sure to CACHE your results! You don't want to hammer the service over and over again for the same translations.

Related

How to get response from a SOAP request using zend-soap?

I've been spending sometime with problem. I have a endpoint I want to send some data and receive a response.
I've look online and I've seen that Zend\Soap\Server is used to build methods, and Zend\Soap\Client can than use those methods. I would like for someone to explain what to write in those methods, and how that helps with getting a response.
$client = new Client($this->wsdl, array('soap_version' => SOAP_1_1));
Now we can $client->SOMEMETHOD();
My questions are: 'Where do I get this method from?', 'what will method do?', and 'how do I use it?'
SOAP short base
SOAP allows to request an online service. (use as a client code) for example you can query AMAZON on a product, know its price, etc.
SOAP works in 2 different ways:
way 1: wdsl mode
when you create a connection to a SOAP client, you must provide a link that will provide an XML file: the wdsl
example: type in your browser:
http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl
congratulation : you see (discover) the way to query AMAZON !
this XML file tells you what you can ask for: a price, a product info, a search, etc ..: these are the routes.
for each route (each possible query) the parameters you must provide, the validity check of these parameters: example: route = search article, param1 = article name, type of parameter = string, etc...
$client = new Client($this->wsdl, array( 'soap_version' => SOAP_1_1 ) )
create a client object :
$this->wsdl a link to xml file (the discovery part)
it's a URI string : example : "http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl"
array( 'soap_version' => SOAP_1_1 ) = i use SOAP version xx, you can add more options in this array.
way 2: non wdsl mode
you do not provide a wsdl link or file...
but you must know how to handle request and responses
deep learning
search on google a tutorial for SOAP,
there are online requester for test purpose, etc...
then use it in zend
I solved my problem, so I'll post it here for anyone to understand.
$client = new Client($wsdl, ['soap_version' => SOAP_1_1]);
$params = [
'args0' => [
'_PRCODASSOC' => null,
'_PRCODDELEG' => null,
'_PRCODFISCALE' => 'BRSLSN312213TY',
'_PRCODFSDDIRI' => null,
'_PRTIPOOPERAWS' => 'REPFAM'
]
];
$client->ws_fam_sgf($params);
$result = $client->getLastResponse();
die($result);
All I did was add 'args' => [] and added all my parameters inside that key.

Upload video as unlisted using API v2

I tried to upload video using API v2. It works but i'd like to set the privacy status of the video as Unlisted. I have the following code to do so:
$unlisted = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
$unlisted->setExtensionAttributes(array(
array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'),
array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied')));
$video->setExtensionElements(array($unlisted));
This only sets the video as private, not unlisted like i want.
I also tried this but it doesn't work either:
$status = new Google_VideoStatus();
$status->setPrivacyStatus('unlisted');
Any help would be welcome.
PS: The reason I use API v2 is because, correct me if i'm wrong, API v3 doesn't allow browser-based upload. Would be good if someone could clarify that. Cheers.
I believe that "unlisted" is not available with the API V2. According to the API V2 documentation, a private attribute can be added to the video properties to make a video private otherwise it is public. See the paragraph on https://developers.google.com/youtube/2.0/reference#Response_codes_uploading_videos for yt:private.

Zend Routes translate URL's

1) I have a controller "calendar" and have action "showDate" which gets date via url. So, url is something like "calendar/show-date/date/2012-07-22"
2) I have a link to display all entries, "calendar/"
So, I want to create routes so my links look like "kalendar/2012-07-22" and "kalendar/".
Can anyone help me?
According to this post:
http://www.z-f.fr/forum/viewtopic.php?id=5138
The solution is to add '#locale' => $lang to the params.
$this->url(array('lang'=>'it','#locale'=>'it'))
It works very well for me.
I've been looking into translating the URL with Zend_Translate and I came across this sites' plugin that attempts to auto-translate URL segments (module/controller/action).
http://blog.helmich.cz/305-howto-simple-multilingual-routes-in-zend-framework/
The nice thing is that it's a modified custom router class that can function similar to Zend_Router so it's relatively familiar off the bat.
$pages = new MyApp_Controller_Router_Route(
':locale/:#controller/:#action/*',
array(
'controller' =>; 'index',
'action' => 'index',
'locale' => 'cs'
)
);
$router->addRoute('pages',$pages);
The thing you'll need is to have a language ID in your URL (called :locale in the above example) so your Zend_Translate can set the proper language.
www.example.com/en/calendar/2012-06-22/
www.example.com/fr/calendrier/2012-06-22/
www.example.com/de/kalender/2012-06-22/
www.example.com/it/calendario/2012-06-22/
I've only slightly played around with this concept but I recall that it had promise. You'll have to get more familiar with Zend_Translate: http://framework.zend.com/manual/en/zend.translate.html
I hope that helps!
Cheers!
You could re-route all calls of calendar to kalendar. There are two possibilites, either you do it with Zend (preferable) or you change your webserver configuration to rewrite calls to calendar with a HTTP 302 (ugly).
You should however consult the official Zend Documentation, which is pretty good
You have to setup custom routes, this is my way:
in folder application/configs/ create file named "routes.ini"
Put in file your route:
;index-homepage, parameter date isn't required
;"index" is key of your route
routes.index.route = "kalendar/:date"
routes.index.defaults.controller = calendar
routes.index.defaults.action = show
routes.index.defaults.date =
So in your bootstrap.php define that config file:
protected function _initRoute() {
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addDefaultRoutes();
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
$router->addConfig($config, 'routes');
}
And that's it, you can call URL
www.website.com/kalendar
and
www.website.com/kalendar/2012-1-1
See answers in this question for details:
Simple rewrites in Zend Framework

receiving this msg from zend: 'Zend_Soap_Client_Exception' with message 'Invalid URN'

does anyone know what this means
im doing a pretty simple call here in my indexAction -
private $wsdl = "https://mywsdlserver.com/open?wsdl";
$options = array(
"location"=>$this->wsdl,
"uri"=>$this->wsdl
);
$client = new Zend_Soap_Client($this->wsdl, $options);
print_r($client);
fyi i have tried this with and without the options
when i set the options i get the error
when i dont set the options i get an empty client
what id like to get back
is the xml i get when i just put https://mywsdlserver.com/open?wsdl in the addressbar
thanks for your help
The error indicates that the URL you are passing in the options is not valid. The one in your example is fine, so presumably this is not what you are really using.
However, the location and URI options don't apply in WSDL mode, so you're best off omitting them completely. See the docs for the Zend_Soap_Client constructor at: http://framework.zend.com/manual/en/zend.soap.client.html

An example of how to call admin.setRestrictionInfo from PHP SDK

This is what I got so far and the returned result is empty
$params = array(
"method"=>"admin.setRestrictionInfo",
"restriction_str"=>"{'age':'21+'}"
);
$this->fb->api($params)
According to this page
http://wiki.developers.facebook.com/index.php/Session_Secret_and_API_Methods
I need to pass the Application Secret along with this type of API call, but I can't figure it out how to do it with PHP SDK.
Any inputs, directions would be appreciate as well
Cheers
simple
$this->fb->setSession(); //set user session to null
$params = array(
"method"=>"admin.setRestrictionInfo",
"restriction_str"=>array("age"=>18+)
);
$this->fb->api($params);