Table of contents
![Laravel Translation With Variables](https://ecn-storage.s3.us-west-2.amazonaws.com/articles/laravel-translation-with-variables-examplex980.webp)
Â
In this post, I will show you how to implement Laravel translation with variables. Building a Laravel Application with multi-language is amazing and it is easy to do it with the Laravel framework. How about you want to pass a dynamic value to your language with a variable/placeholder?
Â
So let's say this is your English language.
Â
{
"This is a sample message for :name with another :variable2": "This is a sample message for :name with another :variable2"
}
Â
So, how to input a dynamic value to your language variable/placeholder?
Â
See the example below:
$name = "your dynamic value here";
$variable2 = "dynamic value for variable 2";
// you can do it inside your PHP code like controller
trans('This is a sample message for :name with another :variable2', [ 'name' => $name, 'variable2' => $variable2]);
// or this helper function
__('This is a sample message for :name with another :variable2', [ 'name' => $name, 'variable2' => $variable2]);
// for blade template
@lang('This is a sample message for :name with another :variable2', [ 'name' => $name, 'variable2' => $variable2]);​
Read next