Subversion Repositories LCARS

Rev

Rev 193 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

1
<?php

class IndexView extends \PointedEars\PHPX\View
{
  /**
   * @var \Zend\I18n\Translator\Translator
   */

  private $_translator;

  /**
   * @var string
   */

  private $_textDomain;

  /**
   * @var string
   */

  private $_language;

  /**
   * Creates a new index view
   *
   * @see View::__construct()
   */

  public function __construct ($template)
  {
    parent::__construct('application/layouts/index/index.phtml');

    require_once 'Zend/Loader/StandardAutoloader.php';
    $loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
    $loader->register();

    $translator = $this->_translator = new Zend\I18n\Translator\Translator();
    // $translator->setCache(new Zend\Cache\Storage\*Adapter());
    $type = 'gettext';
    $base_dir = $_SERVER['DOCUMENT_ROOT'] . '/i18n/LocaleData';
    $pattern = '%s/LC_MESSAGES/%1$s.pointedears.mo';
    $text_domain = $this->_textDomain = 'de.pointedears';
    $translator->addTranslationFilePattern($type, $base_dir, $pattern, $text_domain);
  }

  /**
   * @param string $value
   * @return IndexView
   */

  public function setLanguage ($value)
  {
    $this->_language = $value;
    return $this;
  }

  /**
   * Returns the translation of the parameter, if any,
   * using Zend Framework 2.1 Translate
   *
   * @param string $s
   * @return string
   */

  public function _ ($s)
  {
    return $this->_translator->translate($s, $this->_textDomain, $this->_language);
  }

  public function getCoverage ($seen)
  {
    if (!is_array($seen))
    {
      return '';
    }

    return implode(', ',
      array_map(
        function ($e) {
          if (is_array($e))
          {
            if ($e[1] === $e[0] + 1)
            {
              return implode(', ', $e);
            }

            return $e[0] . '&ndash;' . $e[1];
          }

          return $e;
        },
        $seen
      )
    );
  }
}