Quantcast

problem in translation in zend2 beta5

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

problem in translation in zend2 beta5

frederic ferri
Dear Sir,

I'm working with Zend2 beta5 and experience trouble with translations.

I first tested the translate() method at the view level and it works
perfectly with PoEdit.

I just set this in my module.config.php and everything goes fines :

     'translator' => array(
        'locale' => 'fr_FR',
        'translation_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),


Now i want to translate std error messages from validators but couldn't
find a way to activate the use of translation files for them. As far as i
can understand, translate helper method is only for views.

Same problem if i want to translate error messages generated by home made
check in the controller....

Same problem to translate the form fields labels. I would like to translate
them in the form file using something like the translate() method but i
couldn't find any acceptable way to do it.
I can only get rid of

echo $this->formLabel($form->get('xxxx'))

in the view and replace them by

$this->translate('xxx')

but in that case i somehow lose the definition done in the form...

Could you be kind enough to tell me where i could find some
information/examples on this topic? I'm a bit disappointed because the
beginning of the translation process was pretty easy to implement (the view
part)... maybe i missed something...

--
Frédéric FERRI
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

RE: problem in translation in zend2 beta5

Alexandre, Lydia
There is no  "defautlTranslator" like in ZF 1.11.11 ?

        $this->setDefaultTranslator($translate);

class abc_Form extends Zend_Form
{

    public function __construct($options = null) {
        :
        :
       
        $this->setDefaultTranslator($translate);
    }

Each of my form is a abc_Form instance

-----Message d'origine-----
De : Frédéric Ferri [mailto:[hidden email]]
Envoyé : jeudi 19 juillet 2012 10:19
À : [hidden email]
Cc : Cédric Duchatelle
Objet : [fw-general] problem in translation in zend2 beta5

Dear Sir,

I'm working with Zend2 beta5 and experience trouble with translations.

I first tested the translate() method at the view level and it works perfectly with PoEdit.

I just set this in my module.config.php and everything goes fines :

     'translator' => array(
        'locale' => 'fr_FR',
        'translation_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),


Now i want to translate std error messages from validators but couldn't find a way to activate the use of translation files for them. As far as i can understand, translate helper method is only for views.

Same problem if i want to translate error messages generated by home made check in the controller....

Same problem to translate the form fields labels. I would like to translate them in the form file using something like the translate() method but i couldn't find any acceptable way to do it.
I can only get rid of

echo $this->formLabel($form->get('xxxx'))

in the view and replace them by

$this->translate('xxx')

but in that case i somehow lose the definition done in the form...

Could you be kind enough to tell me where i could find some information/examples on this topic? I'm a bit disappointed because the beginning of the translation process was pretty easy to implement (the view part)... maybe i missed something...

--
Frédéric FERRI

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: problem in translation in zend2 beta5

weierophinney
Administrator
-- Alexandre, Lydia <[hidden email]> wrote
(on Friday, 20 July 2012, 05:04 PM +0200):

> There is no  "defautlTranslator" like in ZF 1.11.11 ?
>
>         $this->setDefaultTranslator($translate);
>
> class abc_Form extends Zend_Form
> {
>
>     public function __construct($options = null) {
> :
> :
>        
>         $this->setDefaultTranslator($translate);
>     }
>
> Each of my form is a abc_Form instance

There will be soon -- Chris Martin is just about done with a solution
for view helpers and validators that allow translation; it simply did
not make it in time for beta5.

> -----Message d'origine-----
> De : Frédéric Ferri [mailto:[hidden email]]
> Envoyé : jeudi 19 juillet 2012 10:19
> À : [hidden email]
> Cc : Cédric Duchatelle
> Objet : [fw-general] problem in translation in zend2 beta5
>
> Dear Sir,
>
> I'm working with Zend2 beta5 and experience trouble with translations.
>
> I first tested the translate() method at the view level and it works perfectly with PoEdit.
>
> I just set this in my module.config.php and everything goes fines :
>
>      'translator' => array(
>         'locale' => 'fr_FR',
>         'translation_patterns' => array(
>             array(
>                 'type'     => 'gettext',
>                 'base_dir' => __DIR__ . '/../language',
>                 'pattern'  => '%s.mo',
>             ),
>         ),
>     ),
>
>
> Now i want to translate std error messages from validators but couldn't find a way to activate the use of translation files for them. As far as i can understand, translate helper method is only for views.
>
> Same problem if i want to translate error messages generated by home made check in the controller....
>
> Same problem to translate the form fields labels. I would like to translate them in the form file using something like the translate() method but i couldn't find any acceptable way to do it.
> I can only get rid of
>
> echo $this->formLabel($form->get('xxxx'))
>
> in the view and replace them by
>
> $this->translate('xxx')
>
> but in that case i somehow lose the definition done in the form...
>
> Could you be kind enough to tell me where i could find some information/examples on this topic? I'm a bit disappointed because the beginning of the translation process was pretty easy to implement (the view part)... maybe i missed something...
>
> --
> Frédéric FERRI
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: problem in translation in zend2 beta5

frederic ferri
Thanks a lot Matthew for the information.

This means i will stop my desperate efforts to get this working  and will postpone this part of the zend2 project i'm working on.

Any idea when this is planned to be done ?... Not that i want to speed up the process, it's more in order to update my project planning and have an idea of when i will need to reserve time ressource to spend on this ( you know the good old scrum planification...)

In any case, thanks a lot to you and Lydia for the help you provided.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: problem in translation in zend2 beta5

weierophinney
Administrator
-- frederic ferri <[hidden email]> wrote
(on Monday, 23 July 2012, 02:25 AM -0700):
> Thanks a lot Matthew for the information.
>
> This means i will stop my desperate efforts to get this working  and
> will postpone this part of the zend2 project i'm working on.
>
> Any idea when this is planned to be done ?... Not that i want to speed
> up the process, it's more in order to update my project planning and
> have an idea of when i will need to reserve time ressource to spend on
> this ( you know the good old scrum planification...)

Should be merged into master sometime today.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: problem in translation, similar to that in zend2 beta5, still present in latest dev master

clara
Hi,

I am someone else than the original reporter still hitting the same wall with the latest checkout 0abbba9f1171e5c7cd7997f4d185d5ffe0cd7c5f from zendframework-dev-master.

The goal is to have PoEdit (or xgettext) detect strings for translation from forms.


i.e.
class LoginForm extends Form {
    public function __construct() {
    $this->add(array(
                        'name' => "username",
                        'attributes' => array(
                                'type' => "email",
                                'class' => "input-medium span5",
                                'placeholder' => "Email address..." // THIS NEEDS TO BE EXTRACTED BY XGETTEXT!! // XXX
                        ),
                        'options' => array(
                                'label' => "!THIS NEEDS TO BE EXTRACTED BY XGETTEXT!", // XXX
                        )
                ));
    }
}

I too couldn't find any acceptable way to do it.


I can only get rid of

echo $this->formLabel($form->get('username'))

in the view and replace them by

$this->translate('xxx')

but in that case I somehow lose the definition done in the form...

Can anyone please suggest a way of doing it?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: problem in translation, similar to that in zend2 beta5, still present in latest dev master

Griesi
Hi,

you can set the translator for the translation of validator messages in your Module.php onBootstrap method. Pre translated validator files can be found for numerous languages in app\vendor\zendframework\zendframework\resources. Just be careful because not all of them (eg. for es) have been updated to the current Zend Framework Version. de just works fine. If you copy them over to your module using /language/de_De_Zend_Validate.php you can use the following code within you onBootstrap method. The logic will automatically use the locale which is set for the translator in your module.config. This translator must be present to work:


Module.php in your module
    public function onBootstrap(MvcEvent $e)
    {
                $app = $e->getApplication();
                $sm  = $app->getServiceManager();


                $resDir =  __DIR__ . '/language/'.$sm->get('translator')->getLocale().'_Zend_Validate.php';
                $translator = new \Zend\I18n\Translator\Translator(array('locale'=>$sm->get('translator')->getLocale()));
                $translator->addTranslationFile('phpArray',$resDir,'default',$sm->get('translator')->getLocale());
                \Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
    }


module.config in the Application module:
    'translator' => array(
        'locale' => 'de_DE',
        'translation_file_patterns' => array(
            array(
                'type'     => 'PhpArray',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.php',
            ),
        ),
    ),
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: problem in translation, similar to that in zend2 beta5, still present in latest dev master

Griesi
This post has NOT been accepted by the mailing list yet.
In regards to performance probably a much better way would be to use DI to inject the translator into the AbstractValidator when first used through a concrete implementation. There is also a injectTranslator method.  But currently I have no idea how and where I could centrally configure this injection in module.config or getServiceConfig(). Hopefully somebody can shed some light on this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: problem in translation, similar to that in zend2 beta5, still present in latest dev master

clara
This post has NOT been accepted by the mailing list yet.
In reply to this post by Griesi
Building the strings manually using PhpArray is precisely what I want to avoid.

As said earlier:
The goal is to have PoEdit (or xgettext) [*AUTOMATICALLY*] detect strings for translation from forms.
Loading...