Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we pass a variable and use it inside a yml file

I need to perform string interpolation inside yml file, to create a custom error message based on a value which I will pass to locale yml file.

something like

users:
  error1: "custom error message based on variable #{passed_in_var}"

Is this possible?

like image 503
Ajay Avatar asked Oct 17 '25 16:10

Ajay


1 Answers

Use I18n interpolation!

users:
  error1: "custom error message based on variable %{passed_in_var}"

Then you call it like this:

t('users.error1', passed_in_var: 'foobar')
like image 93
Sergio Tulentsev Avatar answered Oct 19 '25 12:10

Sergio Tulentsev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!