Search code examples
zend-frameworkzend-translate

Use Zend translate in dynamic CSS


I need the Zend translator in a dynamic CSS file that I write with php.

So far, I always used the Zend translator outside of a view or a controller like this:

Zend_Registry::get('Zend_Translate')->translate('hello');

When using this in my dynamic CSS (which is located in the public folder) the Zend_Registry class cannot be founc

Class 'Zend_Registry' not found

How can I get the Zend translator to work in the public folder?


Solution

  • You need to setup the autoloader (or at least the include path) at the top of your PHP script:

    set_include_path('/path/to/library');
    require_once 'Zend/Loader/Autoloader.php';
    $autoloader = Zend_Loader_Autoloader::getInstance();
    

    then the script should be able to load the ZF classes.

    If you are serving CSS files with PHP, make sure you are serving (and handling) the appropriate cache headers so the browser doesn't have to download the file with every request.