Cachet 3.x is under development. Learn more.

Laravel Localization Case Tips

Here is a little tip for Laravel's Localization that I discovered today whilst looking through the open Laravel Nova issues. Although it's documented it's not well known - at least, I didn't know about it before today!

Say you have an en.json translation file like this:

{
    "The :resource was created!": "The :resource was created!"
}

You can now use this like so:

__("The :resource was created!", ['resource' => 'category']) // "The category was created!"

But let's say you need to translate this to a language where the resource name must be in capitals. In our locale file, we say:

{
    "The :resource was created!": "Die :Resource wurde erstellt!"
}

And when we use this, we'd now get:

__("The :resource was created!", ['resource' => 'kategorie']) // "Die Kategorie wurde erstellt!"