π 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
You dispatch a queue job right after saving a model. The job fires, tries to look up the recordβ¦ and…
2 min readYou're building a workflow. When an order is cancelled, you need to process a refund. The straightforward approach: call the…
3 min readI've seen this pattern in multiple Laravel codebases β a translation helper that manually fetches the locale before passing it…
2 min read
Leave a Reply