how to include an svg image that contains gettext in php page

427 views Asked by At

I need a PHP page to display an Inkscape-maintained svg image that contains text which upon serving is translated using gettext without using JavaScript and avoiding libraries. Ideally I want a combination of:

<?php
    <img src="image.svg" alt="translated" />
?>

where the image.svg contains

...
<text>
   <tspan>text to be translated</tspan>
</text>
...

to which end I would normally use

<?php echo gettext("text to be translated"); ?>

with an accompanying .mo file that contains the translation, resulting in a php file ready for serving containing:

<body
    <svg>
       ....
       <text>
          <tspan><?php echo gettext("text to be translated"); ?></tspan>
      </text>
      ...
   </svg>
</body>

I've tried combinging many options using include, file_get_contents and eval, but none work smoothly, especially in cases where I have to post-edit my svg image using Inkscape or re-scan the gettext entries using PoEdit.

Entering php code in svg is not allowed, including svg code in php disallows Inkscape editing and eval'ing svg text throws out the svg, leaves just the result of the php expressions (ie. the translated text). includeing the svg file doesn't evaluate any php code within the svg, etc. etc.

When entering <?php echo gettext("text to be translated"); ?> using the text tool in Inkscape, Inkscape will escape the whole string and generate &lt;?php echo... and the resulting svg file is not interpreted, even when using eval.

Is there an elegant way to put the above requirements together or am I using the proverbial hammer to put in a screw?

0

There are 0 answers