• Resolved webspilka

    (@webspilka)


    Hi I use

    • loco translate v 2.6.11
    • theme based on sage theme

    Еverything was working fine but today i found a problem.
    If I add php code in my *.blade.php files:

    <?php
    // Loco translate see this php scope
    $loco_works_for_it = __('Loco Works for this', 'vgstudio');

    ?>
    <span class="share__text">{{ __('Loco dont see this', 'vgstudio') }}</span>

    If I delete <?php ?> block from my file:

    <span class="share__text">{{ __('Loco Works for this', 'vgstudio') }}</span>

    Can I use php and blade at the same time in one file ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tim W

    (@timwhitlock)

    Currently, no. The Blade extractor in Loco Translate is a bit of a workaround, and assumes the file is all non-PHP code.

    It starts by adding its own <?php tag to the beginning of the stream, and then uses the PHP tokenizer to parse out the function calls. It doesn’t try to switch between PHP and non-PHP as it works through the file. I guess it should, but it doesn’t. I don’t use Blade, so I wasn’t aware this was a problem.

    Thread Starter webspilka

    (@webspilka)

    Thank you for your prompt response. I understand what the problem is now, it can be easily bypassed by changing the code to the following

    @php
    $loco_works = __('Loco Works for this', 'vgstudio');
    @endphp
    <span class="share__text">
    {{ __('and now Loco Works for this to', 'vgstudio') }}</span>

    Plugin Author Tim W

    (@timwhitlock)

    Great. Saves me some work.

    Thanks for posting your solution

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PHP code and blade files’ is closed to new replies.