guidocella/laravel-multilingual
Laravel package for building multilingual apps: defines per-locale routes and URLs, integrates language switching and detection, and helps translate paths for localized navigation. Lightweight setup for Laravel projects needing clean locale-aware routing.
translations() relationships.hasMany for translations) rather than reinventing storage mechanisms, reducing complexity. The MIT license ensures compatibility with proprietary and open-source projects.translations table with locale, model_id, and field columns. Pre-existing schemas may need migration scripts or zero-downtime alterations.N+1 issues) could arise if not paired with Laravel’s with() or caching.en → es) be prioritized? Is a custom fallback chain needed?use GuidoCella\Multilingual\Models\MultilingualModel;
class Product extends MultilingualModel {
protected $translatable = ['name', 'description'];
}
laravel-localization for URL routing (e.g., /en/products).spatie/laravel-translatable (if hybrid approaches are needed) or vinkla/hashid for locale-aware slugs.translations table if missing:
Schema::create('translations', function (Blueprint $table) {
$table->id();
$table->foreignId('model_id')->constrained()->cascadeOnDelete();
$table->string('locale')->index();
$table->json('fields'); // or separate columns per field
$table->timestamps();
});
MultilingualModel and define $translatable.name_en, name_es) into the new table.Product::find(1)->name returns en if es is missing).Page in a CMS).Product, Article).composer.json until stability is confirmed.(model_id, locale) and locale for fallback queries.locale if translations are read-heavy for specific languages.Product::find(1)->name) with tags (e.g., product:1:en).cache()->remember for expensive translation lookups.| Scenario | Impact | Mitigation |
|---|---|---|
| Translation table corruption | Data loss for multilingual fields | Regular backups; transactional writes |
| Locale fallback misconfiguration | Inconsistent UI text | Validate fallback chain in tests |
| Query timeouts | Slow API responses | Optimize with(); add query caching |
| Concurrent write conflicts | Lost updates | Use database transactions |
| Unsupported PHP/Laravel version | Integration breaks | Pin versions; test upgrade paths |
$translatable fields.model->translate('es')->name).N+1 issues by eager-loading translations.fr requests fall back to en").translations table growth).How can I help you explore Laravel packages today?