Encoding Problem with Zend Navigation using Zend Translate Spanish in XMLTPX File Special Characters
        Posted  
        
            by 
                Routy
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Routy
        
        
        
        Published on 2010-12-09T18:19:28Z
        Indexed on 
            2011/01/03
            9:54 UTC
        
        
        Read the original article
        Hit count: 464
        
Hello,
I have been attempting to use Zend Translate to display translated menu items to the user.
It works fine until I introduce special characters into the translation files.
I instantiate the Zend_Translate object in my bootstrap and pass it in as a translator into Zend_Navigation:
$translate = new Zend_Translate(
    array('adapter' => 'tmx',
          'content' => APPLICATION_PATH .'/languages/translation.tmx',
          'locale' => 'es'
          )
);
$navigation->setUseTranslator($translate);
I have used several different adapters (array,tmx) in order to see if that made a difference. I ended up with a TMX file that is encoded using ISO-8859-1 (otherwise that throws an XML parse error when introducing the menu item "Administrar Applicación".
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE tmx SYSTEM "tmx14.dtd">
<tmx version="1.4">
    <header creationtoolversion="1.0.0" datatype="tbx" segtype="sentence"
        adminlang="en" srclang="en" o-tmf="unknown"
        creationtool="XYZTool" >
    </header>
    <body>
        <tu tuid='link_signout'>
            <tuv xml:lang="en"><seg>Sign Out</seg></tuv>
            <tuv xml:lang="es"><seg>Salir</seg></tuv>
        </tu>
        <tu tuid='link_signin'>
            <tuv xml:lang="en"><seg>Login</seg></tuv>
            <tuv xml:lang="es"><seg>Acceder</seg></tuv>
        </tu>
        <tu tuid='Manage Application'>
            <tuv xml:lang="en"><seg>Manage Application</seg></tuv>
            <tuv xml:lang="es"><seg>Administrar Applicación</seg></tuv>
        </tu>
    </body>
</tmx>
Once I display the menu in the layout:
echo $this->navigation()->menu();
It will display all menu items just fine, EXCEPT the one using special characters. It will simply be blank.
NOW - If I use PHP's UTF8-encode inside of the zend framework class 'Menu' which I DO NOT want to do:
Line 215 in Zend_View_Helper_Navigation_Menu:
if ($this->getUseTranslator() && $t = $this->getTranslator()) {
    if (is_string($label) && !empty($label)) {
        $label = utf8_encode($t->translate($label));
    }
    if (is_string($title) && !empty($title)) {
        $title = utf8_encode($t->translate($title));
    }
}
Then it works. The menu item display correctly and all is joyful.
The thing is, I do not want to modify the library.
Is there some kind of an encoding setting in either zend translate or zend navigation that I am not finding?
Please Help!
Zend Library Version: 1.11
© Stack Overflow or respective owner