Custom filetype for PHP files with translatable text in echo commands

Hello!

I am trying to create a custom filetype for PHP files with translatable text in echo commands. Please advise how to best define filter for files like attached here.

What I did so far:

1) In Document structure, I defined opening pattern echo \" and closing pattern \". This works fine for files like example_php_2.php where echo only has one string of translatable text.

How to extract all translatable strings from echo commands that have many, like in example_php_1.php?

Alternatively, I tried using echo as opening and \; as closing, but then I did not figure out how to block PHP variables and only mark text in "" as translatable.

2) In Inline tags, I defined <br> as placeholder and <h2> </h2> as tag pair, this works fine for these examples.

However, there can be much more HTML inside PHP and I'd need to rewrite a lot of HTML filter to cover it properly. Is it possible to build a custom filetype for PHP and somehow include the HTML support that already exists in SDL Trados Studio?

(I tried to modify the HTML5 filter instead of building my own filetype, or build a custom filetype based on HTML rather than regular expressions, but there I did not figure out how to make echo content translatable.)

echo_PHP.ZIP

Thank you and best regards,

Marta Bartnicka

  • I'd go with the html filter and enable server side scripts:

    To make this work I did two things:

    1. added php as a parser rule:


    2. Created an Embedded Content Processor called "MB":

    You can see in the first screenshot that I referred to this MB embedded content processor for handling the server side script.

    I also added two structure rules for the MT filetype to pick up the structure you're after and then you can efine whatever inline rules you need to tackle the rest... for example:

    This is definitely not perfect... it's just a quick idea to get you started.  But this gives me this with your php2 file:

    Doing it as html means you can still handle any html in the file if it's not all php, but also allows you to handle the php as needed.  That's how I'd tackle it anyway... hope that helps.

    Paul Filkin | RWS Group

    ________________________
    Design your own training!

    You've done the courses and still need to go a little further, or still not clear? 
    Tell us what you need in our Community Solutions Hub

  • Yes, this helps a lot! I was curious how to make use of an existing HTML filter and just add something to it. Parser rule and custom Embedded Content Processor are the solution - thank you!!!

    Now I am struggling a bit with the "" (esp. in multi-string echo commands) and with getting the variables displayed correctly, but with your solution, I have moved forward a lot.

    Regards,

    Marta Bartnicka