在 XMLTPX 文件中使用 Zend Translate 西班牙语处理 Zend Navigation 的编码问题特殊字符
我一直在尝试使用 Zend Translate 向用户显示翻译后的菜单项。
它工作得很好,直到我在翻译文件中引入特殊字符。
我在引导程序中实例化 Zend_Translate 对象,并将其作为转换器传递到 Zend_Navigation 中:
$translate = new Zend_Translate(
array('adapter' => 'tmx',
'content' => APPLICATION_PATH .'/languages/translation.tmx',
'locale' => 'es'
)
);
$navigation->setUseTranslator($translate);
我使用了几种不同的适配器(数组、tmx),以查看这是否有所不同。我最终得到了一个使用 ISO-8859-1 编码的 TMX 文件(否则在引入菜单项“Administrar Applicación”时会引发 XML 解析错误。
<?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>
一旦我在布局中显示菜单:
echo $this->navigation()->menu();
它将仅显示所有菜单项很好,除了使用特殊字符的那一个。
现在,如果我在 zend 框架类“Menu”中使用 PHP 的 UTF8 编码,我不想这样做:
Zend_View_Helper_Navigation_Menu 中的第 215 行:
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));
}
}
那么它就可以了。 项显示正确,一切都很愉快,
我不想修改该库,
我在 zend 翻译或 zend 导航中找不到某种编码设置吗?
请帮忙!
菜单 :1.11
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个相关的问题:zend 表单不显示像 ñ 这样的拉丁字符。尝试将以下内容添加到 bootstrap.php 中的 _initView 函数中:
I had a related problem: zend form didn't display latin characters like ñ. Try adding the following to your _initView function in bootstrap.php: