/google-translate-php

Google Translate API free PHP class. Translates totally free of charge.

Primary LanguagePHPMIT LicenseMIT

Google-Translate-PHP

Latest Stable Version Total Downloads Latest Unstable Version License

Google Translate API free PHP class. Translates totally free of charge.

Installation

New! Now available via Composer 😎

Install this package through Composer. Edit your project's composer.json file to require stichoza/google-translate-php.

"require": {
    "stichoza/google-translate-php": "~2.0"
}

Or run a command in your command line:

composer require stichoza/google-translate-php

Usage

Instantiate GoogleTranslate object

use Stichoza\Google\GoogleTranslate;

$tr = new GoogleTranslate("en", "ka");

Or set/change languages later

$tr = new GoogleTranslate();
$tr->setLangFrom("en");
$tr->setLangTo("ka");

Translate sentences

echo $tr->translate("Hello World!");

Also, you can use shorter syntax:

echo $tr->setLangFrom("en")->setLangTo("ru")->translate("Goodbye");

Or call a static method

echo GoogleTranslate::staticTranslate("Hello again", "en", "ka");