larastan icon indicating copy to clipboard operation
larastan copied to clipboard

Find missing translation strings in blade files

Open nerg4l opened this issue 1 year ago • 5 comments

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.

nerg4l avatar Jan 22 '24 17:01 nerg4l

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.

calebdw avatar Jan 22 '24 18:01 calebdw

Yes, my bad. The comment on Reddit misled me. I will close this PR and open one there. Thanks for the info.

nerg4l avatar Jan 22 '24 18:01 nerg4l

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

philbates35 avatar Jan 22 '24 19:01 philbates35

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.

canvural avatar Jan 22 '24 20:01 canvural

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.

nerg4l avatar Jan 22 '24 20:01 nerg4l