5

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.

Nilay Patel
  • 151
  • 2
  • 6
  • 1
    This may help: http://stackoverflow.com/questions/3836792/can-i-use-zend-translate-date-and-cache-as-standalone-class-in-my-project – Jeremy Harris Jan 23 '12 at 11:57
  • hi thanks for reply i have checked and integrate the zend_translate in my site. but can you tell me how zend_translate will translate the text comes from database. i need this. – Nilay Patel Jan 23 '12 at 12:45

1 Answers1

1

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!

Dmitry Kudryavtsev
  • 16,354
  • 4
  • 25
  • 32