📖 1 minute read
When defining translation strings in Laravel, always use named placeholders (like :count or :percent) instead of positional ones or manual string concatenation.
// Bad
__('You have ' . $count . ' notifications');
// Good
__('You have :count notifications', ['count' => $count]);
Different languages have varying word orders; named placeholders allow translators to move variables within the sentence without breaking the logic or requiring code changes for each locale.
Daryle De Silva
VP of Technology
11+ years building and scaling web applications. Writing about what I learn in the trenches.
Related Articles
Verify Before Removing Defensive Fallback Code Here's a cautionary tale about premature optimization: removing defensive fallback code before verifying the…
2 min readYou just defined a new Eloquent relationship. Now you need to write the migration. What columns should you create? What…
4 min readWhen you're debugging data inconsistencies in Laravel and suspect caching might be the culprit, here's a pattern that can save…
2 min read
Leave a Reply