how to add translation in foreach list into laravel blade

 To add translations to a foreach loop in Laravel Blade, you can use the @lang directive to translate each item in the loop. Here is an example:

@foreach($items as $item)
    <li>@lang('messages.' . $item->name)</li>
@endforeach

In this example, the items variable contains a collection of objects with a name attribute. The @lang directive is used to translate each item's name by passing the translation key to the trans function. The translation key is constructed using the dot notation and the name attribute value of each item.

Assuming that you have defined the translations in your language files under the messages namespace, the @lang directive will automatically translate the item's name based on the current locale. If a translation is not available for the current locale, the original string will be returned.

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...