original_string: public function formatMessage($key, $args = array())
      {
          if (!$this->_loaded) {
              $this->load();
          }
          if (!isset($this->messages[$key])) {
              return "[$key]";
          }
          $raw = $this->messages[$key];
          $subst = array();
          $generator = false;
          foreach ($args as $i => $value) {
              if (is_object($value)) {
                  if ($value instanceof HTMLPurifier_Token) {
                      // factor this out some time
                      if (!$generator) {
                          $generator = $this->context->get('Generator');
                      }
                      if (isset($value->name)) {
                          $subst['$'.$i.'.Name'] = $value->name;
                      }
                      if (isset($value->data)) {
                          $subst['$'.$i.'.Data'] = $value->data;
                      }
                      $subst['$'.$i.'.Compact'] =
                      $subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value);
                      // a more complex algorithm for compact representation
                      // could be introduced for all types of tokens. This
                      // may need to be factored out into a dedicated class
                      if (!empty($value->attr)) {
                          $stripped_token = clone $value;
                          $stripped_token->attr = array();
                          $subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token);
                      }
                      $subst['$'.$i.'.Line'] = $value->line ? $value->line : 'unknown';
                  }
                  continue;
              } elseif (is_array($value)) {
                  $keys = array_keys($value);
                  if (array_keys($keys) === $keys) {
                      // list
                      $subst['$'.$i] = $this->listify($value);
                  } else {
                      // associative array
                      // no $i implementation yet, sorry
                      $subst['$'.$i.'.Keys'] = $this->listify($keys);
                      $subst['$'.$i.'.Values'] = $this->listify(array_values($value));
                  }
                  continue;
              }
              $subst['$' . $i] = $value;
          }
          return strtr($raw, $subst);
      }
code: public function formatMessage($key, $args = array())
      {
          if (!$this->_loaded) {
              $this->load();
          }
          if (!isset($this->messages[$key])) {
              return "[$key]";
          }
          $raw = $this->messages[$key];
          $subst = array();
          $generator = false;
          foreach ($args as $i => $value) {
              if (is_object($value)) {
                  if ($value instanceof HTMLPurifier_Token) {
                      // factor this out some time
                      if (!$generator) {
                          $generator = $this->context->get('Generator');
                      }
                      if (isset($value->name)) {
                          $subst['$'.$i.'.Name'] = $value->name;
                      }
                      if (isset($value->data)) {
                          $subst['$'.$i.'.Data'] = $value->data;
                      }
                      $subst['$'.$i.'.Compact'] =
                      $subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value);
                      // a more complex algorithm for compact representation
                      // could be introduced for all types of tokens. This
                      // may need to be factored out into a dedicated class
                      if (!empty($value->attr)) {
                          $stripped_token = clone $value;
                          $stripped_token->attr = array();
                          $subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token);
                      }
                      $subst['$'.$i.'.Line'] = $value->line ? $value->line : 'unknown';
                  }
                  continue;
              } elseif (is_array($value)) {
                  $keys = array_keys($value);
                  if (array_keys($keys) === $keys) {
                      // list
                      $subst['$'.$i] = $this->listify($value);
                  } else {
                      // associative array
                      // no $i implementation yet, sorry
                      $subst['$'.$i.'.Keys'] = $this->listify($keys);
                      $subst['$'.$i.'.Values'] = $this->listify(array_values($value));
                  }
                  continue;
              }
              $subst['$' . $i] = $value;
          }
          return strtr($raw, $subst);
      }
code_tokens: public function formatMessage ( $ key , $ args = array ( ) ) { if ( ! $ this -> _loaded ) { $ this -> load ( ) ; } if ( ! isset ( $ this -> messages [ $ key ] ) ) { return "[$key]" ; } $ raw = $ this -> messages [ $ key ] ; $ subst = array ( ) ; $ generator = false ; foreach ( $ args as $ i => $ value ) { if ( is_object ( $ value ) ) { if ( $ value instanceof HTMLPurifier_Token ) { // factor this out some time if ( ! $ generator ) { $ generator = $ this -> context -> get ( 'Generator' ) ; } if ( isset ( $ value -> name ) ) { $ subst [ '$' . $ i . '.Name' ] = $ value -> name ; } if ( isset ( $ value -> data ) ) { $ subst [ '$' . $ i . '.Data' ] = $ value -> data ; } $ subst [ '$' . $ i . '.Compact' ] = $ subst [ '$' . $ i . '.Serialized' ] = $ generator -> generateFromToken ( $ value ) ; // a more complex algorithm for compact representation // could be introduced for all types of tokens. This // may need to be factored out into a dedicated class if ( ! empty ( $ value -> attr ) ) { $ stripped_token = clone $ value ; $ stripped_token -> attr = array ( ) ; $ subst [ '$' . $ i . '.Compact' ] = $ generator -> generateFromToken ( $ stripped_token ) ; } $ subst [ '$' . $ i . '.Line' ] = $ value -> line ? $ value -> line : 'unknown' ; } continue ; } elseif ( is_array ( $ value ) ) { $ keys = array_keys ( $ value ) ; if ( array_keys ( $ keys ) === $ keys ) { // list $ subst [ '$' . $ i ] = $ this -> listify ( $ value ) ; } else { // associative array // no $i implementation yet, sorry $ subst [ '$' . $ i . '.Keys' ] = $ this -> listify ( $ keys ) ; $ subst [ '$' . $ i . '.Values' ] = $ this -> listify ( array_values ( $ value ) ) ; } continue ; } $ subst [ '$' . $ i ] = $ value ; } return strtr ( $ raw , $ subst ) ; }
docstring: Formats a localised message with passed parameters
  @param string $key string identifier of message
  @param array $args Parameters to substitute in
  @return string localised message
  @todo Implement conditionals? Right now, some messages make
  reference to line numbers, but those aren't always available
docstring_tokens: Formats a localised message with passed parameters