Quraşdırma
Paketi Composer ilə qur.
composer require stichoza/google-translate-php
Əsas istifadə
use Stichoza\GoogleTranslate\GoogleTranslate;
$tr = new GoogleTranslate('en'); // Translates into English
Və ya dili sonra dəyişə bilərsiniz.
$tr = new GoogleTranslate(); // Translates to 'en' from auto-detected language by default
$tr->setSource('en'); // Translate from English
$tr->setSource(); // Detect language automatically
$tr->setTarget('ka'); // Translate to Georgian
Cümlənin tərcümə edilməsi
echo $tr->translate('Hello World!');
Qabaqcıl istifadə
Dilin aşkarlanması
Dilin avtomatik aşkarlanması üçün,sadəcə olaraq,source(mənbə) dilini null qeyd edin:
$tr = new GoogleTranslate('es', null); // Or simply do not pass the second parameter
$tr->setSource(); // Another way
Use getLastDetectedSource() -aşkar olunmuş dili göstərir:
$tr = new GoogleTranslate('fr');
$text = $tr->translate('Hello World!');
echo $tr->getLastDetectedSource(); // Output: en
Digər dildə:
EN