Manage all your laravel translations easily:
- Sort tranlations array in natural order
- Find missing translations strings
- Translate automatically string to other languages (DeepL, OpenAI or any custom service)
- Fix Grammar and syntax in your translations (OpenAI, or any custome service)
- Format your translations files
You can install the package via composer:
composer require-dev elegantly/laravel-translator
You can publish the config file with:
php artisan vendor:publish --tag="translator-config"
This is the contents of the published config file:
return [
'lang_path' => lang_path(),
'translate' => [
'service' => 'deepl',
'services' => [
'deepl' => [
'key' => env('DEEPL_KEY'),
],
'openai' => [
'model' => 'gpt-4o',
'prompt' => "Translate the following json to the locale '{targetLocale}' while preserving the keys.",
],
],
],
'grammar' => [
'service' => 'openai',
'services' => [
'openai' => [
'model' => 'gpt-4o',
'prompt' => '
Fix the grammar and the syntax the following json string while preserving the keys.
Do not change the meaning or the tone of the sentences and never change the keys.
',
],
],
],
];
This package can be used:
- Like a CLI tool, using commands.
- In a programmatic way using
\Elegantly\Translator\Facades\Translator::class
facade class.
You can format and sort all your php translations files using:
php artisan translator:sort
use Elegantly\Translator\Facades\Translator;
Translator::sortAllTranslations();
You can display all the missing translations present in a given locale but not in the other ones using:
php artisan translator:missing fr
use Elegantly\Translator\Facades\Translator;
Translator::getAllMissingTranslations('fr');
This package can automatically translate your files for you. It includes 2 services right now:
- DeepL
- OpenAI
You can also define your own service.
First, you need to edit the config file to add your DeepL api key and select deepl as your service:
return [
'translate' => [
'service' => 'deepl', // select the default service here
'services' => [
'deepl' => [
'key' => env('DEEPL_KEY'), // add you api key here
],
],
],
]
To translate all the missing translations use:
php artisan translator:translate
To translate all translations use:
php artisan translator:translate --all
Ommitting the --to
option will translate to every available languages in your project.
use Elegantly\Translator\Facades\Translator;
Translator::translateTranslations(
referenceLocale: 'fr',
targetLocale: 'en',
namespace: 'namespace-file',
keys: ['title', ...]
);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.