0

I want know if is possible use comments already created for build other comment which contain the used commend in addition to other text.

e.g.

//EN file

  msgid "User no logged"
  msgstr ""

  msgid "#previous commend# as participant"
  msgstr ""

//Es file

  msgid "User no logged"
  msgstr "Usuario no logueado"

  msgid "#previous commend# as participant"
  msgstr "#previous translation# como participante"

I want use this translation:

  $this->translate('User no logged as participant');
  //I want obtain: Usuario no logueado como participante

Is possible change the #.....# words by anything?

Thanks in advance.

josepmra
  • 617
  • 9
  • 25

2 Answers2

1

Isn't this basically what your other question is about, too? Though if i understand correctly what you're trying to do, it may be something like this:

echo $this->translate(sprintf(
    '%s as participant', 
    $this->translate('User no logged')
));

But then again in THIS case, to me this is just two translations in a row, like:

echo sprintf('%s %s', 
    $this->translate('User no logged'),
    $this->translate('as participant')
);
Sam
  • 16,435
  • 6
  • 55
  • 89
  • In this question I want use only une time $this->translate() and don't want use the %s because I have a class which contains all messages (without %s) – josepmra May 09 '13 at 10:49
  • Well, I've shown you the two options that i can think of ;) In addition, i actually don't know what your class does at all. I see not a single benefit from it ^^ – Sam May 09 '13 at 12:26
0

In this question I want use only une time $this->translate() and don't want use the %s because I have a class which contains all messages (without %s). I would like relate the comments only in .po files (is possible?)

Strings.php

    class Strings {
        public static $USER_NO_LOGGED = 'El usuario no esta logueado.';
        private static $translator;
        private static $translatorTextDomain = 'default';

        public static function setTranslator(Translator $translator) {
            self::$translator = $translator;
        }
        public static function getTranslator() {
            return self::$translator;
        }   
        public static function setTranslatorTextDomain($textDomain = 'default') {
            self::$translatorTextDomain = $textDomain;
        }   
        public static function getTranslatorTextDomain() {
            return self::$translatorTextDomain;
        }   
        public static function getMessage($message) {       
            $translator = self::getTranslator();
            if (!$translator) return $message;

            return self::getTranslator()->translate($message, self::$translatorTextDomain);
        }
    }

As you can see, the getMessage method has only one translate method and the call to the function is done as follows:

  echo Strings::getMessage(Strings::$USER_NO_LOGGED); 
josepmra
  • 617
  • 9
  • 25