php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
688 stars 134 forks source link

Blade Extractor improvement for Laravel 8/Jetstream (Gettext 4.x branch) #261

Closed MichaelHoste closed 3 years ago

MichaelHoste commented 4 years ago

In a new Laravel 8 Jetstream project (created with laravel new [name] --jet), there is an exception when using Extractors\Blade::fromFile($file, $translations);

  Unable to locate a class or view for component [jet-input].

  at vendor/laravel/framework/src/Illuminate/View/Compilers/ComponentTagCompiler.php:273
    269▕         if ($viewFactory->exists($view = $this->guessViewName($component))) {
    270▕             return $view;
    271▕         }
    272▕ 
  ➜ 273▕         throw new InvalidArgumentException(
    274▕             "Unable to locate a class or view for component [{$component}]."
    275▕         );
    276▕     }
    277▕ 

      +2 vendor frames 
  3   [internal]:0
      Illuminate\View\Compilers\ComponentTagCompiler::Illuminate\View\Compilers\{closure}(["<x-jet-input type="password" class="mt-1 block w-3/4" placeholder="Password"
                                x-ref="password"
                                wire:model.defer="password"
                                wire:keydown.enter="logoutOtherBrowserSessions" />", "jet-input", " type="password" class="mt-1 block w-3/4" placeholder="Password"
                                x-ref="password"
                                wire:model.defer="password"
                                wire:keydown.enter="logoutOtherBrowserSessions" ", " type="password" class="mt-1 block w-3/4" placeholder="Password"
                                x-ref="password"
                                wire:model.defer="password"
                                wire:keydown.enter="logoutOtherBrowserSessions" ", "="logoutOtherBrowserSessions""])

It seems to be unable to locate the jet components, and therefore can't compile the Blade file to PHP.

i don't exactly know why it breaks, but a lot of things are recently updated regarding ComponentTag namespaces and it might be related to this error? (cf. https://github.com/laravel/framework/commit/7cc120ebfcccdecf02d5cdbec47f6eae63a8e5a9).

However, if I'm right, the Blade extractor doesn't need to compile ComponentTag to do its job correctly, so I created this pull request to always disable it, so that the 4.x branch could still work with Laravel 8/Jetstream.

i hope that makes sense!

MichaelHoste commented 3 years ago

@oscarotero Do you think you could consider merging this small pull request in a new GetText 4.x release?

It seems that Blade component tags trigger an error when parsed by GetText (Unable to locate a class or view for component). It's problematic for most Laravel 8 projects.

Or maybe it should work without this pull request and I'm doing something wrong?

(FYI The tests actually pass, but travis bugged on one of them)

oscarotero commented 3 years ago

Ok. (sorry I missed this pull request). Thanks!

MichaelHoste commented 3 years ago

Thank you very much for accepting this pull request, and also for this nice project! 😄