i want to use a function (@lang) inside another function (@sortablelink).
@lang: changed localisation depending on previous user input @sortablelink: kysliks sortable columns ( https://github.com/Kyslik/column-sortable )
Like this:
@foreach($COLUMNS_TASK as $column => $val)
<div class="th">
<a href=""><p class="justify-content-center text-center">@sortablelink($val, @lang('lang.'.$val))</p></a>
</div>
@endforeach
When i run this code, i am getting this error: Error Call to undefined function lang()
But when i write it like this:
@foreach($COLUMNS_TASK as $column => $val)
<div class="th">
<a href=""><p class="justify-content-center text-center">@sortablelink($val)@lang('lang.'.$val)</p></a>
</div>
@endforeach
It's working, but it only displays the results of the functions side by side, and it looks like this:
Is it possible to use a function inside another function like this? Or is there another solution here i am not seeing?
Thanks in advance and have a great day.
You can call the translator to get the value you want and if you want to pass it as the second parameter to that @sortablelink
directive you can:
@sortablelink($val, __($val))
// some ways to call the translator to get a translation
__($val)
trans($val)
Lang::get($val)
app('translator')->get($val)
The @lang
directive would be calling the translator and echoing the result.
Laravel 7.x Docs - Localization - Retrieving Translation Strings __
@lang
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.