boxblinkracer / phpunuhi

PHPUnuhi - The easy composable framework to validate and manage translations
MIT License
72 stars 5 forks source link

Support for MJML scanner #41

Closed wannevancamp closed 5 months ago

wannevancamp commented 5 months ago

When using MJLM templates with snippets, snippets are not detected because a MJML scanner is currently not supported. This can be very useful when using the Shopware plugin FroshPlatformTemplateMail

boxblinkracer commented 5 months ago

hi

thanks for this great idea

so i think frosh also uses twig. that means snippets have a different syntax? or do you need same snippet twig syntax with a different file extension?

thanks

wannevancamp commented 5 months ago

The FroshPlatformTemplateMail plugin supports MJML formats which makes styling emails much easier. In those templates, the MJML extension is used instead of twig.

Example folder structure with MJML files.

lensonline-shop6-webshop – contact_form:html mjml 2024-01-23 07-57-37

MJML content with snippets.

<mjml>
    <mj-body mj-class="body">
        <mj-wrapper mj-class="body__wrapper">
            <mj-section mj-class="content">
                <mj-column>
                    <mj-text>
                        <h1>{{ 'email.contact.subject'|trans|sw_sanitize }}</h1>
                        <p>{{ 'email.contact.intro'|trans|sw_sanitize }}</p>

                        ...
                    </mj-text>
                </mj-column>
            </mj-section>
        </mj-wrapper>
    </mj-body>
</mjml>

In this example the snippets in the MJML file are not detected by the twig-scanner.

boxblinkracer commented 5 months ago

Hi

a perfect

thats amazing so we have a a) a new extension b) new snippet pattern in that files

great

ill do it

thanks a lot :)

boxblinkracer commented 5 months ago

you can test dev-master with the new scanner should work now, QA not started yet but unit tests are all passing

wannevancamp commented 5 months ago

Thanks for the fast response!

I've tested the feature on the dev-main branch but it still does not recognize the .mjml files? Do I have to activate to MJML-scanner?

#1 [EMPTY_CONTENT] Found empty translation
   - Locale: en-GB
   - File: /.../.../.../.../src/xyz/Resources/snippet/storefront.en-GB.json
   - Line: 30
       [x]: email.contact.intro
boxblinkracer commented 5 months ago

you need to use the scanner:usage command the detection in files is integrating with an external system from the frameworks point of view (so twig files) and its not 100% correct...because snippets might not appear inside templates but could be used inside PHP scripts....

so the basic idea on scanners is to get some quick insight in what MIGHT not be used :)

php bin/console scanner:usage .... --scanner=mjml --dir=xyz

that should work

wannevancamp commented 5 months ago

I'm running php vendor/bin/phpunuhi scan:usage --dir=./src --scanner=mjml --set=General but still get the following errors:

+-------+----------------------------------------------------+----------------------------------------------------------------------------------+
| #     | Keys (2)                                          | Error                                                                            |
+-------+----------------------------------------------------+----------------------------------------------------------------------------------+
| 1     | email.contact.intro                             | Key not found in any file                                                        |
| 2     | email.contact.subject                                | Key not found in any file                                                        |

This is my simplified configuration image

boxblinkracer commented 5 months ago

Ok that's funny because of these unit tests with the exact same data haha https://github.com/boxblinkracer/phpunuhi/blob/main/tests/phpunit/Bundles/Scanner/MJML/MjmlScannerTest.php

could only think of the file not being found somehow

ill check it out...maybe ill add a debug output which files have been scanned would be good right? or a verbose mode for that maybe?

boxblinkracer commented 5 months ago

Hi

ok got it, stupid me. forgot to ask the scanner implementation what file extension to use accidentally always used TWIG

now its dynamic and should work in dev-master :)

wannevancamp commented 5 months ago

Great, I've tested the fix on the dev-main and it works 👍

The last step to make the CI validation work is the compatibility for mjml with the validate:all command. I suppose it's better to create another ticket for this?

boxblinkracer commented 5 months ago

Hi amazing thank you

yeah i didnt really want to add the scanners to the official validation command because the result is not 100% valid....please see the warnings in the text

if snippets are added thru PHP for instance...then its okay that they are not found in those files. so scanners are more some working helpers.....

do you have any better idea on that?

boxblinkracer commented 5 months ago

released in 1.17.0