Installation
Run composer require laravel-lang/moonshine --dev in your project root.
Ensure your project uses MoonShine v4+ (verified via release notes).
Update Translations
Execute php artisan lang:update to sync all available locales (e.g., en, es, ru, ja).
This populates resources/lang/vendor/moonshine/ with translation files.
First Use Case
config/app.php):
'locale' => 'es', // Spanish translations will now apply to MoonShine components.
resources/lang/vendor/moonshine/ for locale-specific keys (e.g., moonshine::buttons.save).Adding New Locales
en.json to a new locale (e.g., resources/lang/vendor/moonshine/fr.json) and translate keys.php artisan lang:update to auto-generate translations for unsupported locales (e.g., sw, ur).
Note: Machine translations may require manual review (see Gotchas).Overriding Default Translations
resources/lang/{locale}/moonshine.php:
return [
'buttons' => [
'save' => 'Guardar cambios', // Overrides Spanish 'save' button
],
];
php artisan vendor:publish --provider="LaravelLang\MoonShine\MoonShineServiceProvider" --tag="moonshine-translations"
Then edit config/moonshine.php to customize default keys.Dynamic Locale Switching
app()->setLocale(request('locale')); // e.g., via a route parameter
moonshine-table, moonshine-form) are compatible with your MoonShine version. Test after lang:update.config/app.php to fall back to English:
'fallback_locale' => 'en',
trans() helper to verify translations in Blade:
{{ trans('moonshine::buttons.cancel') }}
MoonShine Version Mismatch
lang:update on MoonShine v3 with this package may break UI strings (keys differ between v3/v4).Machine Translation Quality
ak, ln) may contain errors or awkward phrasing.resources/lang/vendor/moonshine/{locale}.json and manually correct keys like:
"buttons": {
"save": "Simpan" // Auto-translated to "Save" → corrected to Indonesian
}
Missing Keys
Caching
lang:update:
php artisan view:clear
php artisan cache:clear
Log Missing Keys: Enable Laravel’s translation logging in config/app.php:
'debug' => env('APP_DEBUG', true),
Missing keys will appear in logs (e.g., translation missing: moonshine::tables.no_results).
Key Reference: Use MoonShine’s Blade components to find the correct translation key for a UI element (e.g., moonshine-table::no_results).
Custom Translation Sources
// app/Providers/MoonShineTranslationServiceProvider.php
use LaravelLang\MoonShine\MoonShineServiceProvider;
class MoonShineTranslationServiceProvider extends MoonShineServiceProvider {
public function register() {
$this->mergeConfigFrom(__DIR__.'/../config/moonshine.php', 'moonshine');
$this->loadTranslationsFrom(__DIR__.'/../lang', 'moonshine');
}
}
Locale-Specific Plugins
moonshine namespace in your locale files:
return [
'plugins' => [
'table' => [
'actions' => [
'edit' => 'Editar registro', // Overrides table edit button
],
],
],
];
Dynamic Translation Loading
// In a service provider
app()->loadLanguageFiles(app()->getLocale());
How can I help you explore Laravel packages today?