0

I'm facing problem while using translator in ZF2. i.e it accepting only inline string not Php variables.

It is working perfect and showing translator word in .PO file after "Update", when i give inline string to translate

    $translator = $this->getServiceLocator()->get('translator');
    $translator->translate("message to translate") ;

But i want to translate the string which is saved in PHP variable. It is not showing translator word in .PO file after "Update". See the code bellow.

    $translator = $this->getServiceLocator()->get('translator');
    $msg1="message to translate";
    $translator->translate($msg1) ;

This code is from one of my controller action.

Please advice

S B
  • 1,363
  • 12
  • 21

1 Answers1

0

You will need to specify a 'text domain', either a default or when you call the translate method. If that is done then make sure $msg1 actually has a string.

http://framework.zend.com/manual/2.0/en/modules/zend.i18n.translating.html

$translator->translate($message, $textDomain, $locale);

The message is the ID of your message to translate. If it does not exist in the loader translations or is empty, the original message ID will be returned. The text domain parameter is the one you specified when adding translations. If omitted, the default text domain will be used. The locale parameter will usually not be used in this context, as by default the locale is taken from the locale set in the translator.

Rijndael
  • 3,683
  • 2
  • 24
  • 26
  • Thanks @Rijidael. Why we need text domain.what is expected value of $textDomain? – S B May 30 '13 at 10:28