Stichoza / google-translate-php

🔤 Free Google Translate API PHP Package. Translates totally free of charge.
MIT License
1.79k stars 380 forks source link

It doesn't work with me! #11

Closed lucinda34 closed 9 years ago

lucinda34 commented 9 years ago

It doesn't work with me!

Stichoza commented 9 years ago

Can you explain what exactly does not work? What errors do you get and what have you tried? Opening an unconstructive issue shouting "It doesn't work!!!!11!" is not a good idea.

lucinda34 commented 9 years ago

Thank you for responding! It's not a shout, it's a whisper... Sorry!

Just does nothing... It stays a blank page:

http://dlc.pt/equipa_dlc/lucinda/tradutor/

This is my code... The file included is on the right path....

<?php
include ("Stichoza/Google/GoogleTranslate.php");
$tr = new GoogleTranslate("en", "ka");
//echo GoogleTranslate::staticTranslate("Hello again", "en", "ka");
echo $tr->translate("Hello World!");
?>
Stichoza commented 9 years ago

As of v2.0.0 this library is namespaced as PSR-4 standards require (See the readme.md for more information). In your code the object isn't actually instantiating. You should get an error about it if you haven't turned off error_reporting in your PHP configuration.

So you are using namespaces incorrectly. You should either add use Stichoza\Google\GoogleTranslate; before instantiating an object, or just use full namespace in classname.

With use keyword

use Stichoza\Google\GoogleTranslate;
$tr = new GoogleTranslate('en', 'pt');

Or with full namespace

$tr = Stichoza\Google\GoogleTranslate('en', 'pt');
lucinda34 commented 9 years ago

I put the class in the same dir...

And the code is this:

<?php
include ("GoogleTranslate.php");//in same dir
use Stichoza\Google\GoogleTranslate;//namespace in class
$tr = new GoogleTranslate("en", "ka");
echo $tr->translate("Hello World!");
?>

Nothing again: http://www.dlc.pt/equipa_dlc/lucinda/tradutor/ Could you please help me ? What I'm doing wrong?

Stichoza commented 9 years ago

I think it's not a problem of this library. I copied the exact code you wrote and it works for me. You can see output in the attached image below.

Consider enabling error_reporting on your server to see what's wrong.

screen shot 2014-10-31 at 18 55 39

lucinda34 commented 9 years ago

You are great!!! Realy works!!! It was an issue in the server...

Thank you so much!

Stichoza commented 9 years ago

You're welcome! :smile: