2013-05-08 53 views
0

我想知道是否可以使用已创建的注释来构建其他评论,其中包含除了其他文本以外的其他评论。zend框架2使用其他评论的gettext翻译

例如

// EN文件

msgid "User no logged" 
    msgstr "" 

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

// ES文件

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

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

我想使用这个翻译:

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

可能变化.....##什么字?

在此先感谢。

回答

1

这不是基本上你的另一个问题是什么吗?但如果我理解你正在试图做正确的东西,它可能是这样的:在这种情况下

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

不过话说回来,对我来说这是一排只有两个译本,如:

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

在这个问题中,我只想使用une time $ this-> translate()并且不想使用%s,因为我有一个包含所有消息的类(没有%s) – josepmra 2013-05-09 10:49:29

+0

好吧,我已经向你展示了我能想到的两个选项;)另外,我实际上不知道你的班级做了什么。我看不到它的一个好处^^ – Sam 2013-05-09 12:26:28

0

在这个问题中,我只想使用une time $ this-> translate()并且不想使用%s,因为我有一个包含所有消息(不含%s)的类。 我想只涉及在.po文件的意见(是可能的?)

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); 
     } 
    } 

正如你所看到的,getMessage方法只有一个翻译方法和调用函数是这样完成的:

echo Strings::getMessage(Strings::$USER_NO_LOGGED);