larastan
larastan copied to clipboard
Find missing translation strings in blade files
Hello,
I recently developed a package (coding-socks/lost-in-translation) which is able to scan Blade files to identify translation strings and report if the translation for that string is missing from a locale.
u/boreasaurus on Reddit said the following:
It would be amazing if somehow this functionality existed in larastan, as that is already reporting errors for e.g. view('some.unknown.view')
My package provides a lost-in-translation:find {locale}
artisan command which reads all blade files, compiles them to PHP, converts them to tokens, and then finds the relevant nodes in the AST (Abstract syntax tree). As far as I know, this is similar to how static analysis tools work.
I'm not sure if I will have enough time in the upcoming days but I would happily work on adding this feature if you think it's a good addition. However, I might require some guidance on where to start because I'm not familiar enough with Larastan/PHPStan.
Awesome!
However, this seems better suited for the Bladestan project which is already analyzing blade files. To the best of my knowledge (and I could be wrong), but Larastan does not report missing views.
Yes, my bad. The comment on Reddit misled me. I will close this PR and open one there. Thanks for the info.
To the best of my knowledge (and I could be wrong), but Larastan does not report missing views.
It does actually:
https://github.com/larastan/larastan/blob/2.x/src/Types/ViewStringType.php
However it doesn't currently seem to be working properly, see https://github.com/larastan/larastan/issues/1607
Hi,
Yes this is possible with Larastan. I even had a working PR about this: https://github.com/larastan/larastan/pull/1456
Actually I would say this suits to Larastan more than Bladestan 😄 Because Bladestan compiles the blade files to PHP and then does static analysis. To do this task you do not need to compile the blade files. You can check the linked PR on how it works.
If you want, you can try to revive my linked PR and we can add this to Larastan. But it needs to be an optional rule disabled by default.
I will keep this issue open because it looks like a possible enhancement. Also, I will try to find some time to check the linked PRs and code. If I'm enthusiast enough, I can add it to both library.