| Install | |
|---|---|
composer require darvis/livewire-inline-translation |
|
| Latest Version: | v1.1.0 |
| PHP: | ^8.2 |
Inline translation editing for Livewire applications with database storage. This package allows authorized users (e.g., staff) to edit translations directly on the website without accessing the CMS.
composer require darvis/livewire-inline-translation
php artisan vendor:publish --tag=inline-translation-migrations
php artisan migrate
php artisan vendor:publish --tag=inline-translation-config
This will create config/inline-translation.php where you can configure:
staff)If you want to customize the view:
php artisan vendor:publish --tag=inline-translation-views
Add this container to your layout file (e.g., resources/views/components/layouts/website.blade.php):
<!DOCTYPE html>
<html>
<head>
<!-- Your head content -->
@livewireStyles
</head>
<body>
<!-- Your body content -->
{{ $slot }}
<!-- Add this container for inline translation modals -->
<div id="inline-translation-modals"></div>
@livewireScripts
</body>
</html>
Use the component in your Blade templates:
<livewire:inline-translation translationKey="website.welcome" />
The translation key should follow the format: {group}.{key}
group: The language file name (e.g., website, messages)key: The translation key within that fileExamples:
website.welcome → lang/en/website.php → ['welcome' => '...']messages.hello → lang/en/messages.php → ['hello' => '...']translations table (highest priority)lang/{locale}/{file}.php files (fallback)This means you can override any Laravel translation by editing it inline, and the original files remain untouched.
In config/inline-translation.php:
return [
'guard' => 'web', // Change from 'staff' to 'web' or any other guard
];
Or via environment variable:
INLINE_TRANSLATION_GUARD=web
In config/inline-translation.php:
return [
'modal_container_id' => 'my-custom-container',
];
Then update your layout:
<div id="my-custom-container"></div>
The package creates a translations table:
| Column | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| locale | string(10) | Language code (e.g., 'en', 'nl') |
| group | string(100) | File name (e.g., 'website', 'messages') |
| key | string(255) | Translation key |
| value | text | Translation value |
| created_at | timestamp | Created timestamp |
| updated_at | timestamp | Updated timestamp |
Unique constraint on: locale, group, key
Language file lang/en/website.php:
return [
'welcome' => 'Welcome to our website!',
];
Blade template:
<h1><livewire:inline-translation translationKey="website.welcome" /></h1>
<div>
<h1><livewire:inline-translation translationKey="website.title" /></h1>
<p><livewire:inline-translation translationKey="website.description" /></p>
<button><livewire:inline-translation translationKey="website.cta_button" /></button>
</div>
The component supports HTML in translations:
<div>
<livewire:inline-translation translationKey="website.rich_content" />
</div>
Language file:
return [
'rich_content' => 'This is <strong>bold</strong> and <em>italic</em> text.',
];
❌ Wrong:
<a href="/contact">
<livewire:inline-translation translationKey="website.contact" />
</a>
✅ Correct:
<a href="/contact">{{ __('website.contact') }}</a>
The component generates a clickable span for authorized users, which conflicts with parent clickable elements.
The modal uses Alpine.js x-teleport directive. Make sure Alpine.js is loaded in your layout:
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
#inline-translation-modals container exists in your layoutgroup.key)config/inline-translation.php guard settingphp artisan config:clearThe package includes a comprehensive test suite using Pest:
# Run all tests
composer test
# Run with coverage
composer test-coverage
# Run specific test file
vendor/bin/pest tests/Unit/TranslationModelTest.php
Contributions are welcome! Please see CONTRIBUTING.md for details.
# Clone the repository
git clone https://github.com/darvis/livewire-inline-translation.git
cd livewire-inline-translation
# Install dependencies
composer install
# Run tests
composer test
Please see CHANGELOG.md for recent changes.
If you discover any security-related issues, please email info@arvid.nl instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Arvid de Jong
If you find this package helpful, please consider giving it a star on GitHub!