简体   繁体   中英

Translating English to other language using zend framework

I am beginner with the Zend Framework.

I have one simple small web application which is in English Language. I want to translate it in Hindi. I referred to Zend_Translate but I wasn't able to understand how it works, would someone be able to help me? I m not getting idea for zend_translate... Please give me a controller, bootstrap and form code which translate a simple english string to hindi...

Zend_Translate is a component used for localization, this component enable you to store your different translated string in some various formats(XML, PHP, CSV, gettext). After loading your translated content, you can use the component to show your translated pieces in your view.

Here an example extracted from the manual

$translate = new Zend_Translate(
    array(
        'adapter' => 'gettext',
        'content' => '/my/path/source-de.mo',
        'locale'  => 'de'
    )
);
$translate->addTranslation(
    array(
        'content' => '/path/to/translation/fr-source.mo',
        'locale'  => 'fr'
    )
);

print $translate->_("Example") . "\n";
print "=======\n";
print $translate->_("Here is line one") . "\n";
printf($translate->_("Today is the %1\$s") . "\n", date('d.m.Y'));
print "\n";

$translate->setLocale('fr');
print $translate->_("Here is line two") . "\n";

The steps you have to make depend on which adapter you choose (for example gettext requires using editor for .po files (Poedit)).

Generally you have to:

    1) Choose and configure one of available adapters.
    2) Place all text you want to translate inside translate function, as shown in RageZ post (however some source are translate automatically, for example: if you have function setLabel() of Zend_Form class you do not have to call additionally translate function - Zend_Form is integrated with Zend_Translate out of the box)
    3) Provide translated data (format of data dependent on chosen adapter)

To my mind, documentation about Zend_Translate on zendframework.com is quite good add one should be able to start using translation based on information from reference guide.

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