Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'weierophinney/feature/i18n-remove'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 265 deletions.
19 changes: 6 additions & 13 deletions src/Helper/HeadTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Zend\View\Helper;

use Zend\I18n\Translator\Translator;
use Zend\View\Exception;

/**
Expand Down Expand Up @@ -124,21 +125,13 @@ public function getDefaultAttachOrder()
/**
* Sets a translation Adapter for translation
*
* @param Zend_Translator|\Zend\Translator\Adapter\Adapter $translate
* @param Translator $translator
* @return \Zend\View\Helper\HeadTitle
* @throws Exception\InvalidArgumentException
*/
public function setTranslator($translate)
public function setTranslator(Translator $translator)
{
if ($translate instanceof \Zend\Translator\Adapter\AbstractAdapter) {
$this->_translator = $translate;
} elseif ($translate instanceof \Zend\Translator\Translator) {
$this->_translator = $translate->getAdapter();
} else {
throw new Exception\InvalidArgumentException(
"You must set an instance of Zend_Translator or Zend_Translator_Adapter"
);
}
$this->_translator = $translator;
return $this;
}

Expand All @@ -148,7 +141,7 @@ public function setTranslator($translate)
* If none is currently registered, attempts to pull it from the registry
* using the key 'Zend_Translator'.
*
* @return Zend_Translator_Adapter|null
* @return Translator|null
*/
public function getTranslator()
{
Expand Down Expand Up @@ -184,7 +177,7 @@ public function disableTranslation()
* @param string|null $locale
* @return string
*/
public function toString($indent = null, $locale = null)
public function toString($indent = null, $locale = 'default')
{
$indent = (null !== $indent)
? $this->getWhitespace($indent)
Expand Down
16 changes: 5 additions & 11 deletions src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use Zend\Navigation\Page\AbstractPage;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Translator;
use Zend\I18n\Translator\Translator;
use Zend\View;
use Zend\View\Exception;

Expand Down Expand Up @@ -81,7 +81,7 @@ abstract class AbstractHelper
/**
* Translator
*
* @var \Zend\Translator\Adapter
* @var Translator
*/
protected $translator;

Expand Down Expand Up @@ -315,15 +315,9 @@ public function getIndent()
* Default is null, which sets no translator.
* @return AbstractHelper fluent interface, returns self
*/
public function setTranslator($translator = null)
public function setTranslator(Translator $translator = null)
{
if (null == $translator ||
$translator instanceof Translator\Adapter\AbstractAdapter) {
$this->translator = $translator;
} elseif ($translator instanceof Translator\Translator) {
$this->translator = $translator->getAdapter();
}

$this->translator = $translator;
return $this;
}

Expand All @@ -332,7 +326,7 @@ public function setTranslator($translator = null)
*
* Implements {@link HelperInterface::getTranslator()}.
*
* @return Translator\Adapter\AbstractAdapter|null translator or null
* @return Translator|null translator or null
*/
public function getTranslator()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Helper/Navigation/HelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace Zend\View\Helper\Navigation;

use Zend\Acl;
use Zend\I18n\Translator\Translator;
use Zend\Navigation;

/**
Expand Down Expand Up @@ -62,7 +63,7 @@ public function getContainer();
* Default is null.
* @return HelperInterface fluent interface, returns self
*/
public function setTranslator($translator = null);
public function setTranslator(Translator $translator = null);

/**
* Returns translator used in helper
Expand Down
13 changes: 11 additions & 2 deletions test/Helper/HeadTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/

namespace ZendTest\View\Helper;

use Zend\I18n\Translator\Translator;
use Zend\View\Helper\Placeholder\Registry;
use Zend\View\Helper;

Expand Down Expand Up @@ -185,9 +187,16 @@ public function testZF3577()

public function testCanTranslateTitle()
{
$adapter = new \Zend\Translator\Adapter\Ini(__DIR__ . '/../../Translator/Adapter/_files/translation_en.ini', 'en');
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array(
'Message_1' => 'Message 1 (en)',
);
$translator = new Translator();
$translator->getPluginManager()->setService('default', $loader);
$translator->addTranslationFile('default', null);

$this->helper->enableTranslation();
$this->helper->setTranslator($adapter);
$this->helper->setTranslator($translator);
$this->helper->__invoke('Message_1');
$this->assertEquals('<title>Message 1 (en)</title>', $this->helper->toString());
}
Expand Down
12 changes: 8 additions & 4 deletions test/Helper/Navigation/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Service\ServiceManagerConfiguration;
use Zend\ServiceManager\ServiceManager;
use Zend\Translator\Translator;
use Zend\I18n\Translator\Translator;
use Zend\View\Renderer\PhpRenderer;
use ZendTest\View\Helper\TestAsset;

/**
* Base class for navigation view helper tests
Expand Down Expand Up @@ -196,7 +197,8 @@ protected function _getAcl()
*/
protected function _getTranslator()
{
$data = array(
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array(
'Page 1' => 'Side 1',
'Page 1.1' => 'Side 1.1',
'Page 2' => 'Side 2',
Expand All @@ -205,7 +207,9 @@ protected function _getTranslator()
'Home' => 'Hjem',
'Go home' => 'Gå hjem'
);

return new Translator('ArrayAdapter', $data, 'nb_NO');
$translator = new Translator();
$translator->getPluginManager()->setService('default', $loader);
$translator->addTranslationFile('default', null);
return $translator;
}
}
2 changes: 1 addition & 1 deletion test/Helper/Navigation/BreadcrumbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testTranslationUsingZendTranslate()
public function testTranslationUsingZendTranslateAdapter()
{
$translator = $this->_getTranslator();
$this->_helper->setTranslator($translator->getAdapter());
$this->_helper->setTranslator($translator);

$expected = $this->_getExpected('bc/translated.html');
$this->assertEquals($expected, $this->_helper->render());
Expand Down
2 changes: 1 addition & 1 deletion test/Helper/Navigation/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function testTranslationUsingZendTranslate()
public function testTranslationUsingZendTranslateAdapter()
{
$translator = $this->_getTranslator();
$this->_helper->setTranslator($translator->getAdapter());
$this->_helper->setTranslator($translator);

$expected = $this->_getExpected('menu/translated.html');
$this->assertEquals($expected, $this->_helper->render());
Expand Down
16 changes: 16 additions & 0 deletions test/Helper/TestAsset/ArrayTranslator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace ZendTest\View\Helper\TestAsset;

use Zend\I18n\Translator;

class ArrayTranslator implements Translator\Loader\LoaderInterface
{
public $translations;

public function load($filename, $locale)
{
$textDomain = new Translator\TextDomain($this->translations);
return $textDomain;
}
}
Loading

0 comments on commit 851904c

Please sign in to comment.