What is the preferred method of localization in Zend 2? -


i looking tutorial on preferred method of handling localization in zend 2, far haven't been able find any. best find this page, doesn't explain practical process of implementing localization (specifically, application messages) in detail, or this question, asked before release of zend 2 , outdated.

if given choice presented on page, pick gnu gettext translation format. there tutorial on localizing zf2 application in case?

or, store text of pages on site in database table, example

create table `page` (   `id` int(11) not null auto_increment,   `title` varchar(255) default null,   `body` blob,   `locale` int(11) not null,   `creator` int(11) not null,   `created` datetime not null,   `modified` datetime not null, primary key (`id`), key `pagecreatorfk_idx` (`creator`), constraint `pagecreatorfk` foreign key (`creator`) references `user` (`id`) on delete no action on update no action ) engine=innodb auto_increment=5 default charset=utf8 

how go providing localized messages then?

alright, starters you'll need translation program such http://www.poedit.net/

here how have setup:

in module folder create folder called "language".

open module.config.php , add following:

'translator' => array(     'translation_file_patterns' => array(         array(             'type'        => 'gettext',             'base_dir'    => __dir__ . '/../language',             'pattern'     => '%s.mo',             'text_domain' => 'account'         )     ) ) 

what makes things easy me create language.php file , add lines this:

echo _('text_to_translate_here'); 

when configure poedit you'll scan file add translation id's poedit. can add real text want displayed , upon save output 2 files account.mo , account.po. file need upload language folder account.mo

since use translations on application i've added factory global.php file:

return array(     'service_manager' => array(         'factories' => array(             'translator' => 'zend\i18n\translator\translatorservicefactory',         )     ) ); 

in view.phtml file i'll able translate:

<?php echo $this->translate('text_to_translate_here', 'account'); ?> 

now if don't want use textdomains have shown in example of module.config.php translations default use "default" textdomain. instead:

<?php echo $this->translate('text_to_translate_here'); ?> 

this work formlabels: (this output priroity label name)

<?php echo $this->formlabel($this->form->get('prio')); ?> 

if want translate form objects using textdomain other "default" add view.phtml

$this->formsubmit()->settranslatortextdomain('account'); 

now submit formlabels use textdomain instead of default textdomain. same goes other type of form object. replace formsubmit element type.

let me know if helps out or if i'm missing anything.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -