views:

48

answers:

1

Is it possible to translate XSL files using PHP and gettext?

I'm building a web application where most of the user interface code is in XSL files. I'm using PHP gettext to translate PHP pages and an app called Poedit to translate the texts. All this works very well! I would need a way to translate the XSL files too, preferably so that Poedit can find the texts from the XSL files.

Is this possible? Should I perhaps consider another approach for translating XSL files?

+3  A: 

You can use any PHP function within XSL template:

<xsl:value-of select="php:function( 'gettext' , 'Term to translate' )" />

You just need to register namespace:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl"&gt;

And allow to use php functions:

$style = DOMDocument::load( $template );
$processor = new XSLTProcessor();
$processor->registerPHPFunctions();
$processor->importStylesheet( $style );

See also: http://de3.php.net/manual/en/xsltprocessor.registerphpfunctions.php

Radek Suski