Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to use Zend_translate outside the Zend framework?

i m 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.

like image 982
Nilay Patel Avatar asked Nov 13 '22 11:11

Nilay Patel


1 Answers

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!

like image 199
Dmitry Kudryavtsev Avatar answered Nov 16 '22 03:11

Dmitry Kudryavtsev