0

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?

4

1 回答 1

3

您可以在 XSL 模板中使用任何 PHP 函数:

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

你只需要注册命名空间:

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

并允许使用 php 函数:

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

看到这个

于 2010-06-22T13:18:04.790 回答