Zend_Translate untranslated strings question

5 messages Options
Embed this post
Permalink
Silverstorm

Zend_Translate untranslated strings question

Reply Threaded More More options
Print post
Permalink
Hi I'm developing multilingual application where english language is default and all others are based on it. I'm wondering if its possible to handle missed messages in localizations.

It'd be more clear if I give an example:

1. (default) English source has msg. 'APPLICATION_START_CHAT' => 'Start Chat'
2. (localization) Polish source hasnt this message so If I call anywhere under pl_PL locale echo $this->view->translate('APPLICATION_START_CHAT'); it will output APPLICATION_START_CHAT, but I'd like to see 'Start Chat' instead.


I'm feeling like I'm missing something and this is already implemented functionality...

here is my language plugin (couple of lines) that I use at app initialization:
...
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {      
        // determine which language to use
        $session = new Zend_Session_Namespace('uiLanguage', true);        
    $language = $this->getRequest()->getParam('uilang', null);
   
    if(null === $language && !isset($session->language)){
       $session->language = $this->_default;
    } elseif (null !== $language && isset($this->_languages[$language])){
       $session->language = $language;
    }
   
        // set up locale object
        $localeString = $this->_languages[$session->language];
        $locale = new Zend_Locale($localeString);
                               
       
        Zend_Registry::set('language', $session->language);
        Zend_Registry::set('localeString', $localeString);
        Zend_Registry::set('Zend_Locale', $locale);
       
        // Mailing List Comment:
        // $this->_directory => /application/languages/en/*.xml
        //                                /application/languages/pl/*.xml
        $translate = new Zend_Translate('qt', $this->_directory, $locale, array('scan' => Zend_Translate::LOCALE_DIRECTORY));    
       
        Zend_Registry::set('Zend_Translate', $translate);
       
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $viewRenderer->translate = $translate;
    }
Thomas Weidner

Re: Zend_Translate untranslated strings question

Reply Threaded More More options
Print post
Permalink
I don't see what your problem is.
What do you want to do when a translation is missing ?

Because you should not change the language in the middle of the application.
And you can't evaluate if the translation exists before setting the
language, because you don't know what you want to translate before you are
doing so.

The only way to handle this is to eighter to react on missing translations
per case, see the isTranslated() method, or to write missing translations
into a file to know it's missing and translate it then, see the log option.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "Silverstorm" <[hidden email]>
To: <[hidden email]>
Sent: Saturday, February 28, 2009 2:57 AM
Subject: [fw-i18n] Zend_Translate untranslated strings question


>
> Hi I'm developing multilingual application where english language is
> default
> and all others are based on it. I'm wondering if its possible to handle
> missed messages in localizations.
>
> It'd be more clear if I give an example:
>
> 1. (default) English source has msg. 'APPLICATION_START_CHAT' => 'Start
> Chat'
> 2. (localization) Polish source hasnt this message so If I call anywhere
> under pl_PL locale echo $this->view->translate('APPLICATION_START_CHAT');
> it
> will output APPLICATION_START_CHAT, but I'd like to see 'Start Chat'
> instead.
>
>
> I'm feeling like I'm missing something and this is already implemented
> functionality...
>
> here is my language plugin (couple of lines) that I use at app
> initialization:
> ...
>    public function dispatchLoopStartup(Zend_Controller_Request_Abstract
> $request)
>    {
>        // determine which language to use
>        $session = new Zend_Session_Namespace('uiLanguage', true);
>    $language = $this->getRequest()->getParam('uilang', null);
>
>    if(null === $language && !isset($session->language)){
>        $session->language = $this->_default;
>    } elseif (null !== $language && isset($this->_languages[$language])){
>        $session->language = $language;
>    }
>
>        // set up locale object
>        $localeString = $this->_languages[$session->language];
>        $locale = new Zend_Locale($localeString);
>
>
>        Zend_Registry::set('language', $session->language);
>        Zend_Registry::set('localeString', $localeString);
>        Zend_Registry::set('Zend_Locale', $locale);
>
>        // Mailing List Comment:
>        // $this->_directory => /application/languages/en/*.xml
>        //                                /application/languages/pl/*.xml
>        $translate = new Zend_Translate('qt', $this->_directory, $locale,
> array('scan' => Zend_Translate::LOCALE_DIRECTORY));
>
>        Zend_Registry::set('Zend_Translate', $translate);
>
>        $viewRenderer =
> Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
>        $viewRenderer->translate = $translate;
>    }
>
> --
> View this message in context:
> http://www.nabble.com/Zend_Translate-untranslated-strings-question-tp22257801p22257801.html
> Sent from the Zend I18N/Locale mailing list archive at Nabble.com.

Silverstorm

Re: Zend_Translate untranslated strings question

Reply Threaded More More options
Print post
Permalink
Thx for reply.
Well I think its better to output some default translation to user instead of messageId string wchich is completely non-userfriendly (and in fact shouldnt be). In my case - I'm sure of base language (english) that all messages presents here, but I cant be sure about other localizations that are prepared by different people.
As I remember there will be some nice tool in 1.8 for automatic logging missed messagesId's, but it still a bit far away :)

So to accomplish my idea I'd propably extend my translation adapter and overload 'translate method', is it good idea?
Thx for help.


On Sat, Feb 28, 2009 at 10:02 AM, Thomas Weidner <[hidden email]> wrote:
I don't see what your problem is.
What do you want to do when a translation is missing ?

Because you should not change the language in the middle of the application.
And you can't evaluate if the translation exists before setting the language, because you don't know what you want to translate before you are doing so.

The only way to handle this is to eighter to react on missing translations per case, see the isTranslated() method, or to write missing translations into a file to know it's missing and translate it then, see the log option.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Silverstorm" <[hidden email]>
To: <[hidden email]>
Sent: Saturday, February 28, 2009 2:57 AM
Subject: [fw-i18n] Zend_Translate untranslated strings question



Hi I'm developing multilingual application where english language is default
and all others are based on it. I'm wondering if its possible to handle
missed messages in localizations.

It'd be more clear if I give an example:

1. (default) English source has msg. 'APPLICATION_START_CHAT' => 'Start
Chat'
2. (localization) Polish source hasnt this message so If I call anywhere
under pl_PL locale echo $this->view->translate('APPLICATION_START_CHAT'); it
will output APPLICATION_START_CHAT, but I'd like to see 'Start Chat'
instead.


I'm feeling like I'm missing something and this is already implemented
functionality...

here is my language plugin (couple of lines) that I use at app
initialization:
...
  public function dispatchLoopStartup(Zend_Controller_Request_Abstract
$request)
  {
      // determine which language to use
      $session = new Zend_Session_Namespace('uiLanguage', true);
  $language = $this->getRequest()->getParam('uilang', null);

  if(null === $language && !isset($session->language)){
      $session->language = $this->_default;
  } elseif (null !== $language && isset($this->_languages[$language])){
      $session->language = $language;
  }

      // set up locale object
      $localeString = $this->_languages[$session->language];
      $locale = new Zend_Locale($localeString);


      Zend_Registry::set('language', $session->language);
      Zend_Registry::set('localeString', $localeString);
      Zend_Registry::set('Zend_Locale', $locale);

      // Mailing List Comment:
      // $this->_directory => /application/languages/en/*.xml
      //                                /application/languages/pl/*.xml
      $translate = new Zend_Translate('qt', $this->_directory, $locale,
array('scan' => Zend_Translate::LOCALE_DIRECTORY));

      Zend_Registry::set('Zend_Translate', $translate);

      $viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
      $viewRenderer->translate = $translate;
  }

--
View this message in context: http://www.nabble.com/Zend_Translate-untranslated-strings-question-tp22257801p22257801.html
Sent from the Zend I18N/Locale mailing list archive at Nabble.com.




--
Anton Martyniuk
Thomas Weidner

Re: Zend_Translate untranslated strings question

Reply Threaded More More options
Print post
Permalink
I don't think so.

The reason why you can read in the manual that messageIDs should be complete
sentences is that your code will be better understandable for other authors,
think of a team of developers. And of course you will then not have the
problem of rerouting as non existant translation will automatically be
returned in the default (english) language.

Still, feel free to extend and add whatever you need.
Just because it's not recommeneded does not mean that you should not do it.
;-)

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "Anton Martyniuk" <[hidden email]>
To: "Thomas Weidner" <[hidden email]>
Cc: <[hidden email]>
Sent: Saturday, February 28, 2009 10:22 AM
Subject: Re: [fw-i18n] Zend_Translate untranslated strings question


> Thx for reply.
> Well I think its better to output some default translation to user instead
> of messageId string wchich is completely non-userfriendly (and in fact
> shouldnt be). In my case - I'm sure of base language (english) that all
> messages presents here, but I cant be sure about other localizations that
> are prepared by different people.
> As I remember there will be some nice tool in 1.8 for automatic logging
> missed messagesId's, but it still a bit far away :)
>
> So to accomplish my idea I'd propably extend my translation adapter and
> overload 'translate method', is it good idea?
> Thx for help.
>
>
> On Sat, Feb 28, 2009 at 10:02 AM, Thomas Weidner
> <[hidden email]>wrote:
>
>> I don't see what your problem is.
>> What do you want to do when a translation is missing ?
>>
>> Because you should not change the language in the middle of the
>> application.
>> And you can't evaluate if the translation exists before setting the
>> language, because you don't know what you want to translate before you
>> are
>> doing so.
>>
>> The only way to handle this is to eighter to react on missing
>> translations
>> per case, see the isTranslated() method, or to write missing translations
>> into a file to know it's missing and translate it then, see the log
>> option.
>>
>> Greetings
>> Thomas Weidner, I18N Team Leader, Zend Framework
>> http://www.thomasweidner.com
>>
>> ----- Original Message ----- From: "Silverstorm" <[hidden email]>
>> To: <[hidden email]>
>> Sent: Saturday, February 28, 2009 2:57 AM
>> Subject: [fw-i18n] Zend_Translate untranslated strings question
>>
>>
>>
>>> Hi I'm developing multilingual application where english language is
>>> default
>>> and all others are based on it. I'm wondering if its possible to handle
>>> missed messages in localizations.
>>>
>>> It'd be more clear if I give an example:
>>>
>>> 1. (default) English source has msg. 'APPLICATION_START_CHAT' => 'Start
>>> Chat'
>>> 2. (localization) Polish source hasnt this message so If I call anywhere
>>> under pl_PL locale echo
>>> $this->view->translate('APPLICATION_START_CHAT');
>>> it
>>> will output APPLICATION_START_CHAT, but I'd like to see 'Start Chat'
>>> instead.
>>>
>>>
>>> I'm feeling like I'm missing something and this is already implemented
>>> functionality...
>>>
>>> here is my language plugin (couple of lines) that I use at app
>>> initialization:
>>> ...
>>>   public function dispatchLoopStartup(Zend_Controller_Request_Abstract
>>> $request)
>>>   {
>>>       // determine which language to use
>>>       $session = new Zend_Session_Namespace('uiLanguage', true);
>>>   $language = $this->getRequest()->getParam('uilang', null);
>>>
>>>   if(null === $language && !isset($session->language)){
>>>       $session->language = $this->_default;
>>>   } elseif (null !== $language && isset($this->_languages[$language])){
>>>       $session->language = $language;
>>>   }
>>>
>>>       // set up locale object
>>>       $localeString = $this->_languages[$session->language];
>>>       $locale = new Zend_Locale($localeString);
>>>
>>>
>>>       Zend_Registry::set('language', $session->language);
>>>       Zend_Registry::set('localeString', $localeString);
>>>       Zend_Registry::set('Zend_Locale', $locale);
>>>
>>>       // Mailing List Comment:
>>>       // $this->_directory => /application/languages/en/*.xml
>>>       //                                /application/languages/pl/*.xml
>>>       $translate = new Zend_Translate('qt', $this->_directory, $locale,
>>> array('scan' => Zend_Translate::LOCALE_DIRECTORY));
>>>
>>>       Zend_Registry::set('Zend_Translate', $translate);
>>>
>>>       $viewRenderer =
>>> Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
>>>       $viewRenderer->translate = $translate;
>>>   }
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Zend_Translate-untranslated-strings-question-tp22257801p22257801.html
>>> Sent from the Zend I18N/Locale mailing list archive at Nabble.com.
>>>
>>
>>
>
>
> --
> Anton Martyniuk
>

Silverstorm

Re: Zend_Translate untranslated strings question

Reply Threaded More More options
Print post
Permalink
Well imho using complete sentences as messageId's has its postivie and negative sides.
Imagine you have couple of components  in your app (could be forms) and all of them follows some presentation rules (lets say all of password fields has the same description) and one day requirements for password format changes, so you have not only just update some single element validator but also check every form and update this field description. Thats could be painfull and thats why I think using some internal format for messageId's is a good idea. Personally I choosed some format that points me to exact place where it used eg: MODULE_CONTROLLER_MESSAGE_ID and global things like buttons and labels are presented without MODULE_CONTROLLER prefix.

 And imho something like $this->translate('SETTINGS_GUIDES_DOWNLOAD_LINK'); is more developer friendly than $this->translate('<a href="/whatever.zip" title="Whatever">Download</a> developer guide here bla bla bla <strong>bla blabla</strong>'); // Yep its quite often situation when you have to store HTML formatting in translation sources.


On Sat, Feb 28, 2009 at 10:28 AM, Thomas Weidner <[hidden email]> wrote:
I don't think so.

The reason why you can read in the manual that messageIDs should be complete sentences is that your code will be better understandable for other authors, think of a team of developers. And of course you will then not have the problem of rerouting as non existant translation will automatically be returned in the default (english) language.

Still, feel free to extend and add whatever you need.
Just because it's not recommeneded does not mean that you should not do it. ;-)


Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Anton Martyniuk" <[hidden email]>
To: "Thomas Weidner" <[hidden email]>
Cc: <[hidden email]>
Sent: Saturday, February 28, 2009 10:22 AM
Subject: Re: [fw-i18n] Zend_Translate untranslated strings question



Thx for reply.
Well I think its better to output some default translation to user instead
of messageId string wchich is completely non-userfriendly (and in fact
shouldnt be). In my case - I'm sure of base language (english) that all
messages presents here, but I cant be sure about other localizations that
are prepared by different people.
As I remember there will be some nice tool in 1.8 for automatic logging
missed messagesId's, but it still a bit far away :)

So to accomplish my idea I'd propably extend my translation adapter and
overload 'translate method', is it good idea?
Thx for help.


On Sat, Feb 28, 2009 at 10:02 AM, Thomas Weidner <[hidden email]>wrote:

I don't see what your problem is.
What do you want to do when a translation is missing ?

Because you should not change the language in the middle of the
application.
And you can't evaluate if the translation exists before setting the
language, because you don't know what you want to translate before you are
doing so.

The only way to handle this is to eighter to react on missing translations
per case, see the isTranslated() method, or to write missing translations
into a file to know it's missing and translate it then, see the log option.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Silverstorm" <[hidden email]>
To: <[hidden email]>
Sent: Saturday, February 28, 2009 2:57 AM
Subject: [fw-i18n] Zend_Translate untranslated strings question



Hi I'm developing multilingual application where english language is
default
and all others are based on it. I'm wondering if its possible to handle
missed messages in localizations.

It'd be more clear if I give an example:

1. (default) English source has msg. 'APPLICATION_START_CHAT' => 'Start
Chat'
2. (localization) Polish source hasnt this message so If I call anywhere
under pl_PL locale echo $this->view->translate('APPLICATION_START_CHAT');
it
will output APPLICATION_START_CHAT, but I'd like to see 'Start Chat'
instead.


I'm feeling like I'm missing something and this is already implemented
functionality...

here is my language plugin (couple of lines) that I use at app
initialization:
...
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract
$request)
 {
     // determine which language to use
     $session = new Zend_Session_Namespace('uiLanguage', true);
 $language = $this->getRequest()->getParam('uilang', null);

 if(null === $language && !isset($session->language)){
     $session->language = $this->_default;
 } elseif (null !== $language && isset($this->_languages[$language])){
     $session->language = $language;
 }

     // set up locale object
     $localeString = $this->_languages[$session->language];
     $locale = new Zend_Locale($localeString);


     Zend_Registry::set('language', $session->language);
     Zend_Registry::set('localeString', $localeString);
     Zend_Registry::set('Zend_Locale', $locale);

     // Mailing List Comment:
     // $this->_directory => /application/languages/en/*.xml
     //                                /application/languages/pl/*.xml
     $translate = new Zend_Translate('qt', $this->_directory, $locale,
array('scan' => Zend_Translate::LOCALE_DIRECTORY));

     Zend_Registry::set('Zend_Translate', $translate);

     $viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $viewRenderer->translate = $translate;
 }

--
View this message in context:
http://www.nabble.com/Zend_Translate-untranslated-strings-question-tp22257801p22257801.html
Sent from the Zend I18N/Locale mailing list archive at Nabble.com.





--
Anton Martyniuk





--
Anton Martyniuk