coderscantina / laravel-translations
Database driven translation for your Laravel application.
Installs: 5 130
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- illuminate/database: ^7.0||^8.0||^9.0||^10.0||^11.0||^12.0
- illuminate/support: ^7.0||^8.0||^9.0||^10.0||^11.0||^12.0
Requires (Dev)
- doctrine/dbal: ^3.6
- graham-campbell/testbench: ^6.1
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.6
README
A powerful, database-driven translation system for Laravel applications. Store, manage, and retrieve translations directly from your database, with full integration with Laravel's built-in translation system.
Features
- Database Storage: Store all translations in your database for easy management
- Laravel Integration: Seamlessly integrates with Laravel's built-in translation system
- Placeholder Support: Full support for placeholders in translations
- Fallback Support: Cascading language fallbacks
- Import/Export: Import and export translations from/to JSON files
- Command Line Tools: Comprehensive set of Artisan commands to manage translations
Getting started
- Install this package
Installation
Requirements
- PHP 8.0 or higher
- Laravel 8.0 or higher
Via Composer
composer require coderscantina/translations
The package will automatically register its service provider.
Publish Configuration
Optionally publish the configuration file:
php artisan vendor:publish --provider="CodersCantina\Translations\ServiceProvider" --tag="config"
Run Migrations
Create the translations table:
php artisan migrate
Usage
Adding Translations
Via Artisan Command
# Basic usage php artisan translations:add welcome.message 'Welcome to our application' # With language option php artisan translations:add welcome.message 'Willkommen in unserer Anwendung' --lang=de # With namespace php artisan translations:add welcome.message 'Welcome to our application' --namespace=frontend
Via Code
use CodersCantina\Translations\Translation; Translation::create([ 'key' => 'welcome.message', 'value' => 'Welcome to our application', 'language_iso' => 'en' ]);
Retrieving Translations
Use Laravel's built-in methods for retrieving translations, such as Lang::get()
, __
and trans
helpers.
// Using the __ helper echo __('welcome.message'); // 'Welcome to our application' // With replacements echo __('welcome.user', ['name' => 'John']); // 'Welcome, John' // Specifying language echo __('welcome.message', [], 'de'); // 'Willkommen in unserer Anwendung' // Using the trans helper echo trans('welcome.message'); // Using the facade use Illuminate\Support\Facades\Lang; echo Lang::get('welcome.message');
Organizing Translations
We strongly recommend using dot notation to logically group translations:
auth.login.title
auth.login.email
auth.login.password
auth.register.title
errors.validation.required
errors.server.unavailable
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test