2

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?

Cawa
  • 1,269
  • 3
  • 25
  • 44
  • If, DE.mo and EN.mo work fine for you, why change em? ;) I don't know of a way without using text-domain, though you could always write your own view-helper... – Sam Oct 08 '12 at 12:22

1 Answers1

3

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.

Rob
  • 4,927
  • 4
  • 26
  • 41
Jurian Sluiman
  • 13,498
  • 3
  • 67
  • 99