What do people think of specifying parameter replacements outside the normal flow of picking a string?
I’m using translations for page titles and descriptions for a sports-related site. Pretty much every string has a :club parameter that’s replaced with the name of a sports club. A sports club can then have multiple teams, so a lot of titles/descriptions also have a :team parameter. It’s therefore getting pretty cumbersome to specify these parameters for every translation, i.e.
Especially when titles/descriptions include more and more parameters.
Therefore, my thinking is it would be good to be able to specify replacements elsewhere in an application, i.e. a controller or middleware:
class SomeMiddleware
{
public function handle($request, Closure $next)
{
Lang::parameter(':club', $request->route('club')->name);
Lang::parameter(':team', $request->route('team')->name);
return $next($request);
}
}
<!-- resources/views/club/team/show.blade.php -->
@section('title', trans(':team | Teams | :club'))
<!-- i.e. "First Team | Teams | Manchester United" -->
In the above, the :team and :club parameters will be replaced with whatever values are set using the Lang façade in the example middleware class.
What do people think of specifying parameter replacements outside the normal flow of picking a string?
I’m using translations for page titles and descriptions for a sports-related site. Pretty much every string has a
:club
parameter that’s replaced with the name of a sports club. A sports club can then have multiple teams, so a lot of titles/descriptions also have a:team
parameter. It’s therefore getting pretty cumbersome to specify these parameters for every translation, i.e.Especially when titles/descriptions include more and more parameters.
Therefore, my thinking is it would be good to be able to specify replacements elsewhere in an application, i.e. a controller or middleware:
In the above, the
:team
and:club
parameters will be replaced with whatever values are set using theLang
façade in the example middleware class.