coderscantina/laravel-translations
最新稳定版本:v1.1.0
Composer 安装命令:
composer require coderscantina/laravel-translations
包简介
Database driven translation for your Laravel application.
关键字:
README 文档
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
统计信息
- 总下载量: 6.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-22