Search code examples
zend-frameworkinternationalizationzend-translate

Zend_Translate : Auto-extract string from views


i don't figure out a way to extract automaticaly string to be translated in files.

For instance, you've got in your layout and views some echo $this->translate('my_string'); and I want to created the files 'en_US.php', 'fr_FR.php', 'es_ES.php' with the comparative array :

<?php return array('my_string' => 'translation of my string'); ?>

Is it possible ?

Thanks.


Solution

  • Look at the Zend_Translate adapters and choose one. I warmly recommend the gettext adapter.

    Here is how to implement i18n in your Zend Framework application:

    1. Setup a translation adapter during Bootstrap
    2. Store the adapter object in the registry with Zend_Registry::set('Zend_Translate', $translate);
    3. Wrap all text in the equivalent of $translate->translate('This is translatable text');
    4. Install 'gettext' on your development machine.
    5. Install and setup poEdit. poEdit will scan your application and find all translatable strings. It will then store them in a .po file, which you can edit and multiply for other languages.
    6. When you're done, save it and poEdit stores creates the .mo files. The Zend_Translate gettext adapter needs those.