Translate your Laravel website into multiple languages

This section shows how to integrate Weglot to your Laravel website and translate your Laravel website. It's quick and easy to make your Laravel website multilingual.

1) Installation

You can install the library via Composer. Run the following command:

composer require weglot/translate-laravel

To use the library, use Composer's autoload:

require_once __DIR__. '/vendor/autoload.php';

2) Register package

This package use auto-discovery, when you require it from composer, you should have nothing to do and Provider gonna be added automatically to your config/app.php providers list.
If this doesn't work, you can add our provider to the config/app.php, as following:

return [
    // ...
    'providers' => [
        // ... Other packages ...
        Weglot\Translate\TranslateServiceProvider::class
    ],
    //...
];

3) Configuration

As usual for Laravel packages, you can publish configuration files by doing:

php artisan vendor:publish --provider="Weglot\Translate\TranslateServiceProvider" --tag="config"

You'll find the configuration file in config/weglot-translate.php with default values:

<?phpreturn [
    'api_key' => env('WG_API_KEY'),
    'original_language' => config('app.locale', 'en'),
    'destination_languages' => [
        'fr'
    ],
    'exclude_blocks' => ['.site-name'],
    'cache' => false,
​
    'laravel' => [
        'controller_namespace' => 'App\Http\Controllers',
        'routes_web' => 'routes/web.php'
    ]
];

This is an example of configuration, enter your own API key, your original language and destination languages that you want.

  • api_key : is your personal API key. You can get an API Key by signing up on Weglot.
  • original_language : original language is the language of your website before translation.
  • destination_languages : are the languages that you want your website to be translated into.
  • cache : if you wanna use cache or not. It's not a required field and set as false by default.

4) Check additional resources

You can find more resources about what you can do with the Laravel package in our developer space.