简体   繁体   中英

Want to use Zend_translate outside the Zend framework?

im creating a website with multilingual features. and i have search and found the zend_translate is the best way to translating the text. but i have started my website with simple php(no framework) and completed many modules. but now i want to use translator in my site which translate the php texts and the text come from the database(mysql)

i can use gettext() but i have no rights to install the gettext() on my live server so i have choose zend_translate. so can anybody help me to use zend_translate with using the zend framework and without copying the whole zend library files. or give me some another way.

Thanks.

You can't pull just Zend_Translate unless you decide to modify its code, by using Zend_Translate you will have to get Zend_Exception, Zend_Registry (not sure about this), Zend_Cache (if you want caching) and thats it I think.

Copy the needed code to you project, with the appropriate adapter you want to use, and then just create instance of Zend_Translate as following

$translator = new Zend_Translate(array(
    'adapter' => 'gettext',
    'content' => '/my/path/source-de.mo',
    'locale'  => 'de'
));

Then somewhere in your code do

echo $translator->_('Welcome back'), ' ', $username;

To add more languages do something like:

$translator->addTranslation(
array(
    'content' => '/path/to/translation/fr-source.mo',
    'locale'  => 'fr'
));

And to output with french locale write:

$translator->setLocale('fr');
echo $translator->_('Welcome back'), ' ', $username;

For more information please see http://framework.zend.com/manual/en/zend.translate.html Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM