Translator
Installation
To install, run the console command:
You can also change the default settings by making changes to the config/localization.php
file.
Usage
Cyclic translation
Not all API services cover the required number of localizations for translation, and therefore it is possible to find one that can translate the text with one call.
For example, we have settings:
In the settings, we specified Google Translate and DeepL Translate as active translators, and also deactivated Yandex.Translate. The enabled
parameter applies only to cyclic translation.
Let's say Google Translate can only translate into French, and DeepL Translate can only translate into German. Thus, we get three translation cases:
We check whether Google Translate can translate into this language. Yes, he can translate.
We return text translation from Google Translate.
We check whether Google Translate can translate into this language. No, he cannot. Let's move on to the next translator.
We check whether DeepL Translate can translate into this language. Yes, he can translate.
We return the text translation from DeepL Translate.
We check whether Google Translate can translate into this language. No, he cannot. Let's move on to the next translator.
We check whether DeepL Translate can translate into this language. No, he cannot. Let's move on to the next translator.
We return the original text without translation.
Via Facade
Via Dependency Injection
Direct translate
Via Google Translate
To call direct translation, you can use either the LaravelLang\Translator\Facades\Translate
facade or the LaravelLang\Translator\Services\Translate
service class, connecting it via DI.
Via DeepL Translate
To call direct translation, you can use either the LaravelLang\Translator\Facades\Translate
facade or the LaravelLang\Translator\Services\Translate
service class, connecting it via DI.
Via Yandex Translate
To call direct translation, you can use either the LaravelLang\Translator\Facades\Translate
facade or the LaravelLang\Translator\Services\Translate
service class, connecting it via DI.
Compatibility
Laravel | PHP | Translators API | Package | Status |
---|---|---|---|---|
10, 11 | 8.2, 8.3 | Google Translate, DeepL Translate, Yandex.Translate |
|