Installation
composer require moox/localization
php artisan localization:install
This creates the localizations table and publishes config files.
Configure Locales
Define locales in config/localization.php:
'locales' => [
'en' => 'English',
'de' => 'Deutsch',
// ...
],
First Use Case Use the Language Switcher in your Filament panel:
->renderHook(
\Filament\View\PanelsRenderHook::USER_MENU_BEFORE,
fn () => \Illuminate\Support\Facades\Blade::render('@livewire(\'language-switch\',[\'context\'=>\'backend\'])')
)
Enable Admin Panel
Set 'enable-panel' => true in config/localization.php to access /localization.
Model Localization
Extend moox/localization with astrotomic/laravel-translatable for multi-language models:
use Astrotomic\Translatable\Contracts\Translatable;
use Astrotomic\Translatable\Traits\Translatable;
class Post extends Model implements Translatable
{
use Translatable;
public $translatable = ['title', 'content'];
}
Route Localization
Use the routing_path column in the localizations table to manage URL slugs per locale:
// In a controller
$localization = Localization::where('routing_path', request()->path())->first();
Livewire Integration
@livewire('language-switch', ['context' => 'frontend'])
/localization (Filament-based).SEO Meta Tags
Dynamically fetch title, description, and keywords from the localizations table:
$meta = Localization::where('language_id', app()->getLocale())->first();
LocalizationPanelProvider for a dedicated UI.moox/localization's middleware to enforce locale-based routing:
Route::middleware(['localization'])->group(function () {
// Routes here will respect locale
});
app()->setLocale() or middleware.Missing Dependencies
astrotomic/laravel-translatable and moox/core are installed. The package will not work without them.composer require astrotomic/laravel-translatable moox/core if missing.Locale Mismatch
language_id in the localizations table must match your config/app.php locales. Use app()->getLocales() to verify.dd(app()->getLocale(), Localization::pluck('language_id')->toArray());
Route Conflicts
routing_path column is used for locale-specific URLs. Avoid duplicate paths across locales.php artisan route:list | grep localization
Livewire Context Issues
language-switch Livewire component requires a context parameter ('frontend' or 'backend'). Omitting it may cause errors.Panel Not Loading:
'enable-panel' => true in config/localization.php.AppServiceProvider:
Filament::registerPanelProviders([
\Moox\Localization\Providers\LocalizationPanelProvider::class,
]);
Translations Not Updating:
php artisan view:clear
php artisan cache:clear
Custom Fields
Extend the localizations table by publishing migrations:
php artisan vendor:publish --provider="Moox\Localization\LocalizationServiceProvider" --tag="migrations"
Then modify the published migration.
Override Livewire Components Publish the Livewire views:
php artisan vendor:publish --provider="Moox\Localization\LocalizationServiceProvider" --tag="views"
Customize resources/views/vendor/moox/localization/language-switch.blade.php.
Add Custom Logic
Bind events in EventServiceProvider:
protected $listen = [
\Moox\Localization\Events\LocaleSwitched::class => [
\App\Listeners\HandleLocaleSwitch::class,
],
];
$localizations = Localization::with(['translations'])->get();
Cache::remember("meta_{$locale}", now()->addHours(1), function () use ($locale) {
return Localization::where('language_id', $locale)->first();
});
How can I help you explore Laravel packages today?