📖 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
When you're debugging a complex Eloquent query, toSql() gives you the query with ? placeholders. Not super helpful when you…
1 min readOne of the easiest ways to create accidental “data migrations” is to put user-facing strings in places you later treat…
2 min readWhen you have complex boolean conditions, don't cram them into one giant expression. Break them into named variables that explain…
2 min read
Leave a Reply