outhebox/laravel-translations
## Getting Started
### Minimal Steps
1. **Installation**:
```bash
composer require outhebox/laravel-translations
php artisan vendor:publish --provider="Outhebox\LaravelTranslations\LaravelTranslationsServiceProvider" --tag="migrations"
php artisan migrate
Publish the config file:
php artisan vendor:publish --provider="Outhebox\LaravelTranslations\LaravelTranslationsServiceProvider" --tag="config"
First Use Case:
Access the UI at /translations (default route). The package provides a built-in admin panel for managing translations without writing a single line of code.
Key Files:
config/laravel-translations.php: Configuration for locales, default locale, and UI settings.database/migrations/: Migration for the translations table (auto-created).resources/views/vendor/laravel-translations/: Default UI templates (customizable).Translation Management:
auth.login).php artisan translations:export --locale=en --file=translations_en
auth, validation) for better UI navigation.Integration with Laravel:
trans helper or @lang Blade directive as usual. The package auto-loads translations from the database.
__('auth.login'); // Fetches from DB
config/laravel-translations.php:
'fallback_locales' => ['en'],
Customization:
resources/views/vendor/laravel-translations/./translations route with middleware (e.g., auth):
Route::middleware(['auth'])->group(function () {
Route::get('/translations', [TranslationController::class, 'index']);
});
php artisan vendor:publish --provider="Outhebox\LaravelTranslations\LaravelTranslationsServiceProvider" --tag="validation"
CLI Usage:
php artisan translations:update --locale=es --file=path/to/translations.json
php artisan translations:add-locale --locale=ar
Migration Conflicts:
translations table, run php artisan translations:table to regenerate the migration. Avoid altering the table structure directly.Caching Issues:
php artisan translations:clear-cache
config/laravel-translations.php for development:
'cache' => env('APP_ENV') !== 'local',
Nested Key Limitations:
user.profile.settings.notifications) intuitively. Flatten keys where possible or use dot notation consistently.Permission Handling:
laravel-permission to restrict access to /translations.Check Logs:
config/laravel-translations.php:
'debug' => env('APP_DEBUG'),
storage/logs/laravel.log.Verify Locale Files:
resources/lang/en/auth.php) are not conflicting with DB translations. The package prioritizes DB over files.UI Glitches:
npm run build
browser-logs tool in Boost).Custom Storage:
TranslationRepository in a service provider:
$this->app->bind(
\Outhebox\LaravelTranslations\Contracts\TranslationRepository::class,
\App\Services\CustomTranslationRepository::class
);
Event Listeners:
TranslationCreated) for auditing or notifications:
use Outhebox\LaravelTranslations\Events\TranslationCreated;
TranslationCreated::listen(function ($event) {
// Log or notify
});
API Endpoints:
Route::get('/api/translations/{locale}', [TranslationController::class, 'getTranslations']);
Testing:
$this->app->instance(
\Outhebox\LaravelTranslations\Contracts\TranslationRepository::class,
Mockery::mock(\Outhebox\LaravelTranslations\Contracts\TranslationRepository::class)
);
it('updates a translation', function () {
$this->actingAs(user())
->put('/translations/update', [
'locale' => 'en',
'key' => 'auth.login',
'value' => 'Sign In',
])
->assertRedirect('/translations');
});
---
How can I help you explore Laravel packages today?