Zend_Translate 扫描翻译文件
我尝试使用 Zend Framework 中的 Zend_Translate
我正在使用“POEdit”生成“gettext”翻译文件。
我的文件位于 /www/mysite.com/webapps/includes/locale 下(此路径位于我的包含路径中)。 我有: 图片.en.mo 图片.en.po (我计划很快就有 pictures.es.mo)
如果我为每个文件手动执行 addTranslation() ,一切都会正常。但是我想使用自动文件扫描方法。
我尝试了这两种方法:
<?php
/*Localization*/
require_once 'Zend/Translate.php';
require_once 'Zend/Locale.php';
define('LOCALE','/www/mysite.com/webapps/includes/locale');
if(!empty($_GET['locale'])){
$locale = new Zend_Locale($_GET['locale']);
}
else{
$locale = new Zend_Locale();
}
$translate = new Zend_Translate('gettext', LOCALE, null, array('scan' => Zend_Translate::LOCALE_FILENAME));
if ( $translate->isAvailable( $locale->getLanguage() ) ){
$translate->setLocale($locale);
}
else{
$translate->setLocale('en');
}
而这个:
<?php
/*Localization*/
require_once 'Zend/Translate.php';
require_once 'Zend/Locale.php';
define('LOCALE','/www/mysite.com/webapps/includes/locale');
if(!empty($_GET['locale'])){
$locale = new Zend_Locale($_GET['locale']);
}
else{
$locale = new Zend_Locale();
}
$translate = new Zend_Translate('gettext', LOCALE);
if ( $translate->isAvailable( $locale->getLanguage() ) ){
$translate->setLocale($locale);
}
else{
$translate->setLocale('en');
}
在这两种情况下,我都会收到一条通知:没有可用的语言“en”翻译。在 /www/mysite.com/webapps/includes/Zend/Translate/Adapter.php 第 411 行,
如果我尝试进行目录扫描,它也有效。
I've trying to use Zend_Translate from Zend Framework
I am using "POEdit" to generate "gettext" translation files.
My files are under /www/mysite.com/webapps/includes/locale (this path is in my include path).
I have:
pictures.en.mo
pictures.en.po
(I plan on having pictures.es.mo soon)
It all works fine if I manually do addTranslation() for each file. However I want to use the automatic file scanning method.
I tried both of those:
<?php
/*Localization*/
require_once 'Zend/Translate.php';
require_once 'Zend/Locale.php';
define('LOCALE','/www/mysite.com/webapps/includes/locale');
if(!empty($_GET['locale'])){
$locale = new Zend_Locale($_GET['locale']);
}
else{
$locale = new Zend_Locale();
}
$translate = new Zend_Translate('gettext', LOCALE, null, array('scan' => Zend_Translate::LOCALE_FILENAME));
if ( $translate->isAvailable( $locale->getLanguage() ) ){
$translate->setLocale($locale);
}
else{
$translate->setLocale('en');
}
And this:
<?php
/*Localization*/
require_once 'Zend/Translate.php';
require_once 'Zend/Locale.php';
define('LOCALE','/www/mysite.com/webapps/includes/locale');
if(!empty($_GET['locale'])){
$locale = new Zend_Locale($_GET['locale']);
}
else{
$locale = new Zend_Locale();
}
$translate = new Zend_Translate('gettext', LOCALE);
if ( $translate->isAvailable( $locale->getLanguage() ) ){
$translate->setLocale($locale);
}
else{
$translate->setLocale('en');
}
In both cases, I get a Notice: No translation for the language 'en' available. in /www/mysite.com/webapps/includes/Zend/Translate/Adapter.php on line 411
It also worked if I tried to do directory scanning.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为只有一个小“错误”。
如果您使用 LOCALE_FILENAME,ZF 是否会在此文件中搜索您的翻译。
i think there is just one little "bug".
If you use LOCALE_FILENAME, is ZF searching inside this FILE for your Translation.