Exemplo n.º 1
0
 /**
  * Test translatePlural()
  */
 public function testTranslatePlural()
 {
     $translator = Translator::factory(array('locale' => array('en', 'en'), 'translation_file_my_patterns' => array('test my translations' => array('type' => 'phpArray', 'base_dir' => __DIR__ . '/_files/my-translations', 'pattern' => '%s/%s/%s.php'))));
     $translator->setMySchemas(array('schema1', 'schema2'));
     $this->assertEquals('test1 at schema1', $translator->translatePlural('domain.test1', 'domain.test2', 1));
     $this->assertEquals('test2 at schema2', $translator->translatePlural('domain.test1', 'domain.test2', 2));
     $this->assertEquals('1 match', sprintf($translator->translatePlural('domain.matches', 'domain.matches', 1), 1));
     $this->assertEquals('2 matches', sprintf($translator->translatePlural('domain.matches', 'domain.matches', 2), 2));
 }
Exemplo n.º 2
0
 /**
  * Create translator service
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Zend\I18n\Translator\Translator
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $translator \Zork\I18n\Translator\Translator */
     $locale = $serviceLocator->get('Locale');
     $config = $serviceLocator->get('Config');
     $trConfig = isset($config['translator']) ? $config['translator'] : array();
     $translator = Translator::factory($trConfig);
     $translator->setFallbackLocale($locale->getFallback());
     $translator->addMySchema('_central');
     try {
         $schema = $serviceLocator->get('SiteInfo')->getSchema();
     } catch (ServiceNotFoundException $ex) {
         $schema = null;
     }
     $translator->addMySchema($schema ?: '_template');
     return $translator;
 }