John Davidson

php - In laravel 8, where is defined the @lang directive?

0 comments
Message:


In Laravel, I'm looking for the code that creates the @lang directive, to copy the code and create my own version, but I can't find the code. I have found something similar in the trait:


Illuminate\View\Compilers\Concerns\CompilesTranslations

But I guess it's not the same thing. Where can i found it?



My Answer:
The `@lang` directive in Laravel is defined in the `Illuminate\View\Compilers\Concerns\CompilesTranslations` trait, as you mentioned. This trait contains the logic for compiling the `@lang` directive in Blade templates.

If you want to create your own version of the `@lang` directive, you can do so by extending the Blade compiler and adding your custom logic. You can create a custom Blade directive by using the `Blade::directive` method in a service provider or a custom Blade compiler class.

Here is an example of how you can create a custom Blade directive for translations:

php
use Illuminate\Support\Facades\Blade;

Blade::directive('customLang', function ($expression) {
return "get($expression); ?>";
});


You can add this code to a service provider or a custom Blade compiler class to define your custom `@customLang` directive.

Rate this post

3 of 5 based on 3783 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us