📖 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
Laravel's markdown mail renderer is picky about whitespace. If you've ever seen literal **bold** text in your emails instead of…
2 min readWhen using Laravel collections with strict return types, be careful with first() – it returns null when the collection is…
1 min readJSON_CONTAINS in MySQL for Schema-Free Array Searches MySQL's JSON_CONTAINS function lets you query JSON array columns without rigid schema changes….
2 min read
Leave a Reply