我的模块可以正常工作
'translator' => array( 'locale' => 'de_DE',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
仅当我使用 DE.mo EN.mo 等 MO 文件时,但当文件为 en_US.mo 、 de_DE.mo 时,我需要添加到 congik 'text_domain' => __NAMESPACE__
,并在我的查看$this->translate('一些消息',__NAMESPACE__)
我怎样才能摆脱这种差异?
最佳答案
您可以使用文本域,但这不是强制性的。所以:
'translator' => array('locale' => 'de_DE',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
)
在您的 View 脚本中:
<?php echo $this->translate('My Foo'); ?>
如果您使用文本域,那么您必须在配置和 View 助手中使用它们:
'translator' => array('locale' => 'de_DE',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
'text_domain' => 'domain-1'
),
),
)
那么你必须这样做:
<?php
$this->plugin('translate')->setTranslatorTextDomain('domain-1');
echo $this->translate('My Foo')
?>
但无论哪种方式都是可能的。您不需要为特定区域设置使用文本域。
关于translation - 如何在没有文本域的情况下使用 Zf2 翻译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12781543/