Cawa
Cawa

Reputation: 1299

How to use Zf2 translate withot textdomain?

My module works fine with

'translator' => array(  'locale' => 'de_DE',
            'translation_file_patterns' => array(
                    array(
                    'type'     => 'gettext',
                    'base_dir' => __DIR__ . '/../language',
                    'pattern'  => '%s.mo',

Only when i use MO files like DE.mo EN.mo but when files are en_US.mo , de_DE.mo i need to add to congik 'text_domain' => __NAMESPACE__ , and in my view $this->translate('some message',__NAMESPACE__) How i can escape this difference?

Upvotes: 2

Views: 2675

Answers (1)

Jurian Sluiman
Jurian Sluiman

Reputation: 13558

You can use text domains, but they are not obligatory. So:

'translator' => array('locale' => 'de_DE',
    'translation_file_patterns' => array(
        array(
            'type'     => 'gettext',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => '%s.mo',
        ),
    ),
)

And in your view script:

<?php echo $this->translate('My Foo'); ?>

If you use a text domain, then you must use them in both the configuration and the view helper:

'translator' => array('locale' => 'de_DE',
    'translation_file_patterns' => array(
        array(
            'type'        => 'gettext',
            'base_dir'    => __DIR__ . '/../language',
            'pattern'     => '%s.mo',
            'text_domain' => 'domain-1'
        ),
    ),
)

Then you must do this:

<?php 
    $this->plugin('translate')->setTranslatorTextDomain('domain-1');
    echo $this->translate('My Foo') 
?>

But either way are possible. It is not the case you need to use text domains for specific locales.

Upvotes: 3

Related Questions