DEV Community

Cover image for Laravel Translation With Variables Example
Code And Deploy
Code And Deploy

Posted on

5 2

Laravel Translation With Variables Example

Originally posted @ https://codeanddeploy.com visit and download the sample code:
https://codeanddeploy.com/blog/laravel/laravel-translation-with-variables-example

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"
}
Enter fullscreen mode Exit fullscreen mode

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]);
Enter fullscreen mode Exit fullscreen mode

I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/laravel/laravel-translation-with-variables-example if you want to download this code.

Happy coding :)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more