GitzJoey
GitzJoey

Reputation: 65

laravel language key from variable

Let's say I have this in resource/lang/en/test.php with this input

'testing.language.test' => 'testing'

then in the index.blade.php I would like to consume it with this method but not directly, instead I like to put it inside variable first then generate

<p>
$var = 'testing.language.test';
@lang('test' + $var);
</p>

but it's not working, it always returns the testing.language.test without parsing it from the language file.

Upvotes: 2

Views: 8489

Answers (1)

Nour
Nour

Reputation: 1497

If you want to call it as a $var then do like so :

$var = 'testing.language.test';
{{Lang::get('test',[], $var )}}

And that means you are choosing a Locale from an array which is should be found in \Config\App.php file

'locale' => ['en' => 'English' ,'de'=>'Deutsch'],

And you can of course use Blade templating engine like so :

@lang('test.'.$var)

Upvotes: 3

Related Questions