backstage / laravel-translations
A Laravel translations package
Fund package maintenance!
vormkracht10
Requires
- php: ^8.2
- echolabsdev/prism: ^0.37.0
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
- stichoza/google-translate-php: ^5.2
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
This package is auto-updated.
Last update: 2025-03-10 08:18:05 UTC
README
Nice to meet you, we're Vormkracht10
Hi! We are a web development agency from Nijmegen in the Netherlands and we use Laravel for everything: advanced websites with a lot of bells and whitles and large web applications.
Installation
You can install the package via composer:
composer require backstage/laravel-translations
You can publish and run the migrations with:
php artisan vendor:publish --provider="Backstage\Translations\Laravel\TranslationServiceProvider"
php artisan migrate
This is the contents of the published config file:
use EchoLabs\Prism\Enums\Provider; [ 'scan' => [ 'paths' => [ base_path(), ], 'files' => [ '*.php', '*.blade.php', '*.json', ], 'functions' => [ 'trans', 'trans_choice', 'Lang::transChoice', 'Lang::trans', 'Lang::get', 'Lang::choice', '@lang', '@choice', '__', ], ], 'translators' => [ 'default' => env('TRANSLATION_DRIVER', 'google-translate'), 'drivers' => [ 'google-translate' => [ // no options ], 'ai' => [ 'provider' => Provider::OpenAI, // Example provider 'model' => 'text-davinci-003', // Example model 'system_prompt' => 'You are an expert mathematician who explains concepts simply. The only thing you do it output what i ask. No comments, no extra information. Just the answer.', // Example system prompt ], ], ], ];
If you have choosen the AI driver, please read the Prism documentation on how to configure providers.
Usage
Add lang types
If you want to add a language use the following command:
php artisan translations:languages:add {locale} {label}
For example:
php artisan translations:languages:add nl Nederlands
translations:languages:add en English
translations:languages:add fr-BE Français // French specifically for Belgians
The command can also be used without in-command-line parameters
Scan for translations
To scan for translations within your Laravel application, use the following command:
php artisan translations:scan
Translate scanned translations
To translate the scanned translations, use the following command:
php artisan translations:translate {--all : Translate language strings for all languages} {--code= : Translate language strings for a specific language} {--update : Update and overwrite existing translations}
For example:
php artisan translations:translate --code=nl php artisan translations:translate --code=en php artisan translations:translate --code=fr-BE --update // overwrite existing translations php artisan translations:translate // translate all languages
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.