Results 1 to 2 of 2

Thread: Embedded parameter in Zend_Translate

  1. #1
    thinknirmal is offline Junior Member
    Join Date
    Apr 2010
    Posts
    1

    Unhappy Embedded parameter in Zend_Translate

    I am just unable to translate strings containing embedded parameter.

    Here is an example TMX source entry:

    Code:
    <tu tuid='You are requesting price for %1\$s models.'>
        <tuv xml:lang="ms"><seg>Anda meminta harga untuk %1\$s model.</seg></tuv>
    </tu>
    and I request the translation with this line of code:

    Code:
    printf($translate->_("You are requesting price for %1\$s models."), 2);
    It is supposed to produce this result:

    Anda meminta harga untuk 2 model.

    But what I am getting is the same English input:

    You are requesting price for 2 models.


    What am I doing wrong? is my TMX source entry correct? Any help would be appreciated.

  2. #2
    rsn1576 is offline Member
    Join Date
    Dec 2009
    Posts
    31

    Default

    I have been using an easier way that seems to work for me and avoids having to use printf everywhere. I made my own TMX translate adapter that extends Zend_Translate_Adapter_Tmx and I overrode the _() function. Here is the class:

    Code:
    class My_Translate_Adapter_Tmx extends Zend_Translate_Adapter_Tmx
    {
    	public function _($messageId) {
    		$translation = $this->translate($messageId, $this->getLocale());
    		if(func_num_args() > 1) {
    			$args = func_get_args();
    			$args[0] = $translation;
    			$translation = call_user_func_array('sprintf', $args);
    		}
    		return $translation;
    	}
    }
    Set it in my bootstrap like this:

    Code:
    $translator = new Zend_Translate('My_Translate_Adapter_Tmx',
    							APPLICATION_PATH . '/views/languages/' . $languageStr . '.tmx',
    							$languageStr, $options);
    This allows you to use _() with OR without parameters. For instance, in my TMX file I have these two entries:

    Code:
    <tu tuid="message_permission_denied">
    	<tuv xml:lang="en_US"><seg>You do not have permission to access this resource.</seg></tuv>
    </tu>
    
    <tu tuid="details_permission_denied">
    	<tuv xml:lang="en_US"><seg>The user "%1$s" does not have permission to access resource "%2$s".</seg></tuv>
    </tu>
    With those I can get the translations like so:

    Code:
    $translator->_('message_permission_denied')
    $translator->_('details_permission_denied', $user->getUserName(), $reqActionStr)
    Hope that helps, let me know if you have any questions.

Similar Threads

  1. Pagination With get parameter
    By Sami_ghname in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 03-02-2010, 12:43 PM
  2. Strange parameter errors
    By nandana in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 02-14-2009, 09:26 PM
  3. getting 404 with dashed parameter
    By digit in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 11-20-2008, 06:05 PM
  4. Omit parameter name in URL
    By cheyo in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 06-07-2008, 04:13 AM
  5. Passing a URL in a parameter
    By icedcheese in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 10-17-2007, 06:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •