laravel-lang/actions
Developer-focused Laravel Lang package providing reusable actions for managing and automating localization tasks in Laravel apps. Integrates with the Laravel Lang ecosystem and offers documented installation, contribution guidelines, and MIT licensing.
Installation
composer require laravel-lang/actions
The package auto-registers with Laravel’s translation system—no manual configuration is needed.
First Use Case
Access translations via Laravel’s __() helper or trans() function:
// Basic action (e.g., "Save")
echo __('actions.save');
// Dynamic with placeholder (e.g., "Delete User")
echo __('actions.delete', ['name' => 'User']);
Where to Look First
resources/lang/ for locale-specific files).php artisan lang:list actions (if using Laravel Lang’s CLI tools) to list all available keys.Blade Integration Use in buttons, links, or tooltips:
<button type="submit">
{{ __('actions.submit') }}
</button>
Dynamic Context:
<a href="{{ route('users.destroy', $user) }}">
{{ __('actions.delete', ['name' => $user->name]) }}
</a>
Form Actions Leverage for CRUD operations:
// In a Form Request or Controller
return redirect()->route('posts.index')->with('success', __('actions.created'));
API Responses Return localized messages:
return response()->json(['message' => __('actions.updated')]);
JavaScript Localization Publish translations to JS:
php artisan vendor:publish --tag=laravel-lang-actions
Then use in Vue/React:
const messages = @json(__('actions'));
Custom Placeholders Extend with your own variables:
__('actions.custom_action', [
'count' => $items->count(),
'resource' => 'Posts',
]);
Conditional Translations
Use Laravel’s trans_choice for pluralization:
__('actions.items', ['count' => $count]); // "1 item" or "X items"
Fallback Handling
Override defaults in resources/lang/{locale}/actions.php:
return [
'save' => 'Guardar cambios', // Spanish override
];
Testing Mock translations in tests:
$this->app->setLocale('es');
$this->assertEquals('Guardar cambios', __('actions.save'));
Missing Keys
__('actions.unknown')).php artisan lang:list actions to verify available keys.config/app.php:
'fallback_locale' => 'en',
Placeholder Syntax
__('actions.delete') without ['name']).resources/lang/en/actions.php for required variables.Locale-Specific Quirks
nl) translations may use ZWSP (Zero-Width Space) characters, which can cause rendering issues in some UI frameworks.trim(__('actions.some_key'));
Caching
php artisan view:clear
php artisan config:clear
Inspect Translations Dump a translation to debug:
dd(__('actions.save')); // Check for unexpected characters/placeholders
Check Loaded Locales Verify the active locale:
dd(app()->getLocale()); // Should match your expected language
Override Machine Translations
Machine-translated locales (e.g., sa, ug) may be less accurate. Override them in your project’s resources/lang/:
// resources/lang/sa/actions.php
return ['save' => 'حفظ']; // Manual Arabic override
Add New Locales
Copy an existing locale file (e.g., en/actions.php) and translate it for your language. Place it in resources/lang/{locale}/actions.php.
Custom Action Keys Extend the package by publishing and modifying the translations:
php artisan vendor:publish --tag=laravel-lang-actions --force
Then edit config/laravel-lang/actions.php or override in your project.
Integration with Laravel Lang
If using other Laravel Lang packages (e.g., laravel-lang/core), ensure consistent locale handling across packages.
CI/CD Considerations
$this->app->setLocale('fr');
How can I help you explore Laravel packages today?