Laravel - PHP

How to Use Google Translator in Laravel?

Laravel Google Translate

Google Translator in Laravel

Google Translator in Laravel?

In this post, we will learn about  Laravel Google Translate.  if your design a project for multilingual and you don’t want to manually translation every time you add a new language.

For doing auto translation we use a laravel package.

https://github.com/Stichoza/google-translate-php.

This is good package and its don’t need any key to access the API. This package is easy to implement.

The good side of this package is don’t need any keys to access the API and is easy to implement. kindly visit their documentation: https://github.com/Stichoza/google-translate-php.

Okay so let’s continue.

Step 1: Install the package

composer require stichoza/google-translate-php

Step 2: Usage

Now, let’s implement the translation using this package. In your controller you need to use the following class:

use Stichoza\GoogleTranslate\GoogleTranslate;

Then call it to your controller method.

$tr = new GoogleTranslate('fr');

echo $tr->translate('Google Translate');

Another example is using a static method which is you don’t need to instantiate the class and put in a variable.

echo GoogleTranslate::trans('Google Translate', 'fr');

Another way to use on direct in blade file

<li>{{ GoogleTranslate::trans('Google Translate', 'fr') }}</li>
Visited 9 times, 1 visit(s) today

Leave a Reply

Your email address will not be published. Required fields are marked *