diff --git a/module/VuFind/src/VuFind/Auth/AbstractBase.php b/module/VuFind/src/VuFind/Auth/AbstractBase.php index f26bf29079118ce06997d03cd3a40f2b00e09af1..b33f4d398d999b6ac643a406b38ea846eef76c19 100644 --- a/module/VuFind/src/VuFind/Auth/AbstractBase.php +++ b/module/VuFind/src/VuFind/Auth/AbstractBase.php @@ -43,6 +43,8 @@ use Zend\Log\LoggerInterface; abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, \VuFind\I18n\Translator\TranslatorAwareInterface, \Zend\Log\LoggerAwareInterface { + use \VuFind\I18n\Translator\TranslatorAwareTrait; + /** * Has the configuration been validated? * @@ -64,13 +66,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, */ protected $tableManager; - /** - * Translator - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator; - /** * Logger (or false for none) * @@ -104,18 +99,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, } } - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return TranslatorAwareInterface - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - } - /** * Get configuration (load automatically if not previously set). Throw an * exception if the configuration is invalid. @@ -388,30 +371,4 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, ); } } - - /** - * Translate a string - * - * @param string $str String to translate - * @param array $tokens Tokens to inject into the translated string - * - * @return string - * @todo Use TranslatorAwareTrait instead when it's implemented - */ - public function translate($str, $tokens = array()) - { - $msg = $this->translator->translate($str); - - // Do we need to perform substitutions? - if (!empty($tokens)) { - $in = $out = array(); - foreach ($tokens as $key => $value) { - $in[] = $key; - $out[] = $value; - } - $msg = str_replace($in, $out, $msg); - } - - return $msg; - } } diff --git a/module/VuFind/src/VuFind/Connection/Wikipedia.php b/module/VuFind/src/VuFind/Connection/Wikipedia.php index c4dd9b5127c115b0eb7d2d2253b730c289b6e677..701a3ccb87d59db8ad4ce15bf4bb933c1814bbe5 100644 --- a/module/VuFind/src/VuFind/Connection/Wikipedia.php +++ b/module/VuFind/src/VuFind/Connection/Wikipedia.php @@ -40,6 +40,8 @@ use VuFind\I18n\Translator\TranslatorAwareInterface; */ class Wikipedia implements TranslatorAwareInterface { + use \VuFind\I18n\Translator\TranslatorAwareTrait; + /** * HTTP client * @@ -47,13 +49,6 @@ class Wikipedia implements TranslatorAwareInterface */ protected $client; - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; - /** * Selected language * @@ -78,41 +73,6 @@ class Wikipedia implements TranslatorAwareInterface $this->client = $client; } - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return Wikipedia - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Get translator object. - * - * @return \Zend\I18n\Translator\Translator - */ - public function getTranslator() - { - return $this->translator; - } - - /** - * Translate a string - * - * @param string $s String to translate - * - * @return string - */ - public function translate($s) - { - return null === $this->translator ? $s : $this->translator->translate($s); - } - /** * Set language * diff --git a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php index 06ec8fef58bb784b1986886a0c5f7492ca3289c5..3bd93facabfd2d9d1df136c5b431571d212141a9 100644 --- a/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php +++ b/module/VuFind/src/VuFind/Hierarchy/TreeRenderer/JSTree.php @@ -42,12 +42,7 @@ namespace VuFind\Hierarchy\TreeRenderer; class JSTree extends AbstractBase implements \VuFind\I18n\Translator\TranslatorAwareInterface { - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; + use \VuFind\I18n\Translator\TranslatorAwareTrait; /** * Router plugin @@ -66,32 +61,6 @@ class JSTree extends AbstractBase $this->router = $router; } - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return AbstractBase - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Translate a string if a translator is available. - * - * @param string $msg Message to translate - * - * @return string - */ - public function translate($msg) - { - return null !== $this->translator - ? $this->translator->translate($msg) : $msg; - } - /** * Get a list of trees containing the item represented by the stored record * driver. diff --git a/module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareInterface.php b/module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareInterface.php index be2e63233d8971c581dee4afa021fb51aa070adb..29aa6fcf91538725c8dfca46559b37e0b2a99ab6 100644 --- a/module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareInterface.php +++ b/module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareInterface.php @@ -26,12 +26,12 @@ * @link http://vufind.org Main Site */ namespace VuFind\I18n\Translator; +use Zend\I18n\Translator\TranslatorInterface; /** * Lightweight translator aware marker interface (used as an alternative to * \Zend\I18n\Translator\TranslatorAwareInterface, which requires an excessive - * number of methods to be implemented). If we switch to PHP 5.4 traits in the - * future, we can eliminate this interface in favor of the default Zend version. + * number of methods to be implemented). * * @category VuFind2 * @package Translator @@ -44,9 +44,9 @@ interface TranslatorAwareInterface /** * Set a translator * - * @param \Zend\I18n\Translator\Translator $translator Translator + * @param TranslatorInterface $translator Translator * * @return TranslatorAwareInterface */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator); + public function setTranslator(TranslatorInterface $translator); } diff --git a/module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareTrait.php b/module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..ec5cb822ac25af5293471816a15dce180540e60d --- /dev/null +++ b/module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareTrait.php @@ -0,0 +1,129 @@ +<?php +/** + * Lightweight translator aware marker interface. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Translator + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +namespace VuFind\I18n\Translator; +use Zend\I18n\Translator\TranslatorInterface; + +/** + * Lightweight translator aware marker interface (used as an alternative to + * \Zend\I18n\Translator\TranslatorAwareInterface, which requires an excessive + * number of methods to be implemented). If we switch to PHP 5.4 traits in the + * future, we can eliminate this interface in favor of the default Zend version. + * + * @category VuFind2 + * @package Translator + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +trait TranslatorAwareTrait +{ + /** + * Translator + * + * @var \Zend\I18n\Translator\TranslatorInterface + */ + protected $translator = null; + + /** + * Set a translator + * + * @param TranslatorInterface $translator Translator + * + * @return TranslatorAwareInterface + */ + public function setTranslator(TranslatorInterface $translator) + { + $this->translator = $translator; + return $this; + } + + /** + * Get translator object. + * + * @return \Zend\I18n\Translator\TranslatorInterface + */ + public function getTranslator() + { + return $this->translator; + } + + /** + * Get the locale from the translator. + * + * @param string $default Default to use if translator absent. + * + * @return string + */ + public function getTranslatorLocale($default = 'en') + { + return null === $this->translator + ? $this->translator->getLocale() + : $default; + } + + /** + * Translate a string + * + * @param string $str String to translate + * @param array $tokens Tokens to inject into the translated string + * + * @return string + */ + public function translate($str, $tokens = array()) + { + $msg = null === $this->translator + ? $str : $this->translator->translate($str); + + // Do we need to perform substitutions? + if (!empty($tokens)) { + $in = $out = array(); + foreach ($tokens as $key => $value) { + $in[] = $key; + $out[] = $value; + } + $msg = str_replace($in, $out, $msg); + } + + return $msg; + } + + /** + * Sleep magic method -- the translator can't be serialized, so we need to + * exclude it from serialization. Since we can't obtain a new one in the + * __wakeup() method, it needs to be re-injected from outside. + * + * @return array + */ + public function __sleep() + { + $vars = get_object_vars($this); + unset($vars['translator']); + $vars = array_keys($vars); + return $vars; + } +} diff --git a/module/VuFind/src/VuFind/ILS/Connection.php b/module/VuFind/src/VuFind/ILS/Connection.php index 917d33f1a001d86617d5d2a6a01f4f2d31bbec3c..a1f6003b1ecd4f9d99c36e393ba868a47085fce8 100644 --- a/module/VuFind/src/VuFind/ILS/Connection.php +++ b/module/VuFind/src/VuFind/ILS/Connection.php @@ -50,12 +50,7 @@ use VuFind\Exception\ILS as ILSException, */ class Connection implements TranslatorAwareInterface { - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; + use \VuFind\I18n\Translator\TranslatorAwareTrait; /** * Has the driver been initialized yet? @@ -135,19 +130,6 @@ class Connection implements TranslatorAwareInterface } } - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return Connection - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - /** * Set the hold configuration for the connection. * @@ -566,13 +548,8 @@ class Connection implements TranslatorAwareInterface protected function getHelpText($helpText) { if (is_array($helpText)) { - $lang = !is_null($this->translator) - ? $this->translator->getLocale() - : 'en'; - if (isset($helpText[$lang])) { - return $helpText[$lang]; - } - return ''; + $lang = $this->getTranslatorLocale(); + return isset($helpText[$lang]) ? $helpText[$lang] : ''; } return $helpText; } diff --git a/module/VuFind/src/VuFind/ILS/Driver/Amicus.php b/module/VuFind/src/VuFind/ILS/Driver/Amicus.php index 3010bd4b666ae2f6338f3cecf402bc7359d5ee13..968b93163fed0df9e65b774f2c88c119406ce4cd 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Amicus.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Amicus.php @@ -40,12 +40,7 @@ use PDO, PDOException, VuFind\Exception\ILS as ILSException, */ class Amicus extends AbstractBase implements TranslatorAwareInterface { - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; + use \VuFind\I18n\Translator\TranslatorAwareTrait; /** * Database connection @@ -972,30 +967,4 @@ class Amicus extends AbstractBase implements TranslatorAwareInterface return $list; } - - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return Amicus - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Translate a string if a translator is available. - * - * @param string $msg Message to translate - * - * @return string - */ - protected function translate($msg) - { - return null !== $this->translator - ? $this->translator->translate($msg) : $msg; - } } diff --git a/module/VuFind/src/VuFind/ILS/Driver/LBS4.php b/module/VuFind/src/VuFind/ILS/Driver/LBS4.php index b4afce7ad90c1dcb040081237744fd5bcfb089eb..68d554116ca21046d64bcd2f80fdbec0352be992 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/LBS4.php +++ b/module/VuFind/src/VuFind/ILS/Driver/LBS4.php @@ -40,6 +40,8 @@ use VuFind\ILS\Driver\AbstractBase as AbstractBase; */ class LBS4 extends AbstractBase implements TranslatorAwareInterface { + use \VuFind\I18n\Translator\TranslatorAwareTrait; + /** * Database connection * @@ -773,32 +775,6 @@ class LBS4 extends AbstractBase implements TranslatorAwareInterface return array(); } - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return Opus - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Translate a string if a translator is available. - * - * @param string $msg Message to translate - * - * @return string - */ - protected function translate($msg) - { - return null !== $this->translator - ? $this->translator->translate($msg) : $msg; - } - /** * Helper function to clean up bad characters * diff --git a/module/VuFind/src/VuFind/ILS/Driver/NoILS.php b/module/VuFind/src/VuFind/ILS/Driver/NoILS.php index 91689cbef1cd592553c63c90d7b1135040472304..592bc810680fcb0678edbe6ae9ebbe08816505d4 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/NoILS.php +++ b/module/VuFind/src/VuFind/ILS/Driver/NoILS.php @@ -42,12 +42,7 @@ use VuFind\Exception\ILS as ILSException, */ class NoILS extends AbstractBase implements TranslatorAwareInterface { - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; + use \VuFind\I18n\Translator\TranslatorAwareTrait; /** * Record loader @@ -360,30 +355,4 @@ class NoILS extends AbstractBase implements TranslatorAwareInterface // Block authentication: return null; } - - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return NoILS - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Translate a string if a translator is available. - * - * @param string $msg Message to translate - * - * @return string - */ - protected function translate($msg) - { - return null !== $this->translator - ? $this->translator->translate($msg) : $msg; - } } diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php index f84015441a89e50b86aad0c2d5fdef5aa625759f..d58b5820bdf7b398b48ea154e97815eebb3ed1f4 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php @@ -50,12 +50,7 @@ use File_MARC, PDO, PDOException, class Voyager extends AbstractBase implements TranslatorAwareInterface, \Zend\Log\LoggerAwareInterface { - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; + use \VuFind\I18n\Translator\TranslatorAwareTrait; /** * Database connection @@ -2410,32 +2405,6 @@ class Voyager extends AbstractBase return $list; } - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return Voyager - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Translate a string if a translator is available. - * - * @param string $msg Message to translate - * - * @return string - */ - protected function translate($msg) - { - return null !== $this->translator - ? $this->translator->translate($msg) : $msg; - } - /** * Execute an SQL query * diff --git a/module/VuFind/src/VuFind/Mailer/Mailer.php b/module/VuFind/src/VuFind/Mailer/Mailer.php index ad47a28b1729a1959919bcccad651c1ca61bb739..35965a3e9db47070164d2d5855502fc2e54339a6 100644 --- a/module/VuFind/src/VuFind/Mailer/Mailer.php +++ b/module/VuFind/src/VuFind/Mailer/Mailer.php @@ -41,6 +41,8 @@ use VuFind\Exception\Mail as MailException, */ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface { + use \VuFind\I18n\Translator\TranslatorAwareTrait; + /** * Mail transport * @@ -48,13 +50,6 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface */ protected $transport; - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; - /** * Constructor * @@ -65,32 +60,6 @@ class Mailer implements \VuFind\I18n\Translator\TranslatorAwareInterface $this->setTransport($transport); } - /** - * Translate a string if a translator is provided. - * - * @param string $msg Message to translate - * - * @return string - */ - public function translate($msg) - { - return (null !== $this->translator) - ? $this->translator->translate($msg) : $msg; - } - - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return Mailer - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - /** * Get the mail transport object. * diff --git a/module/VuFind/src/VuFind/Recommend/AuthorInfo.php b/module/VuFind/src/VuFind/Recommend/AuthorInfo.php index 8172400f456c9ef46c7b2be8386b4de1670e3ed8..e0f86e48f8281aac53b45af47b2593037d816df8 100644 --- a/module/VuFind/src/VuFind/Recommend/AuthorInfo.php +++ b/module/VuFind/src/VuFind/Recommend/AuthorInfo.php @@ -29,6 +29,7 @@ namespace VuFind\Recommend; use VuFind\Connection\Wikipedia; use VuFind\I18n\Translator\TranslatorAwareInterface; use VuFindSearch\Query\Query; +use Zend\I18n\Translator\TranslatorInterface; /** * AuthorInfo Recommendations Module @@ -45,6 +46,10 @@ use VuFindSearch\Query\Query; */ class AuthorInfo implements RecommendInterface, TranslatorAwareInterface { + use \VuFind\I18n\Translator\TranslatorAwareTrait { + setTranslator as setTranslatorThroughTrait; + } + /** * HTTP client * @@ -59,13 +64,6 @@ class AuthorInfo implements RecommendInterface, TranslatorAwareInterface */ protected $wikipedia; - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; - /** * Saved search results * @@ -123,11 +121,6 @@ class AuthorInfo implements RecommendInterface, TranslatorAwareInterface */ public function setConfig($settings) { - $translator = $this->getTranslator(); - $this->wikipedia->setLanguage( - is_object($translator) ? $translator->getLocale() : 'en' - ); - $parts = explode(':', $settings); if (isset($parts[0]) && !empty($parts[0]) && strtolower(trim($parts[0])) !== 'false' @@ -139,27 +132,18 @@ class AuthorInfo implements RecommendInterface, TranslatorAwareInterface /** * Set a translator * - * @param \Zend\I18n\Translator\Translator $translator Translator + * @param TranslatorInterface $translator Translator * - * @return AuthorInfo + * @return TranslatorAwareInterface */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) + public function setTranslator(TranslatorInterface $translator) { - $this->translator = $translator; + $this->setTranslatorThroughTrait($translator); $this->wikipedia->setTranslator($translator); + $this->wikipedia->setLanguage($this->getTranslatorLocale()); return $this; } - /** - * Get translator object. - * - * @return \Zend\I18n\Translator\Translator - */ - public function getTranslator() - { - return $this->translator; - } - /** * init * diff --git a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php index 5bcb6a14565abc9841af24f88d319675a7475880..f07e5d20370c4b933e789aa5e6ef660f589f2557 100644 --- a/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php +++ b/module/VuFind/src/VuFind/RecordDriver/AbstractBase.php @@ -44,6 +44,8 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, \VuFind\I18n\Translator\TranslatorAwareInterface, \VuFindSearch\Response\RecordInterface { + use \VuFind\I18n\Translator\TranslatorAwareTrait; + /** * Used for identifying search backends * @@ -86,13 +88,6 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, */ protected $tableManager; - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; - /** * Constructor * @@ -535,30 +530,4 @@ abstract class AbstractBase implements \VuFind\Db\Table\DbTableAwareInterface, { $this->tableManager = $manager; } - - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return AbstractBase - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Translate a string if a translator is available. - * - * @param string $msg Message to translate - * - * @return string - */ - public function translate($msg) - { - return null !== $this->translator - ? $this->translator->translate($msg) : $msg; - } } diff --git a/module/VuFind/src/VuFind/Search/Base/Options.php b/module/VuFind/src/VuFind/Search/Base/Options.php index c49efc94921c467222dd4f6a9596139aac218a41..45be6b2075603c9027484437594661202a7d72d5 100644 --- a/module/VuFind/src/VuFind/Search/Base/Options.php +++ b/module/VuFind/src/VuFind/Search/Base/Options.php @@ -42,6 +42,8 @@ use VuFind\I18n\Translator\TranslatorAwareInterface, */ abstract class Options implements TranslatorAwareInterface { + use \VuFind\I18n\Translator\TranslatorAwareTrait; + /** * Available sort options * @@ -203,13 +205,6 @@ abstract class Options implements TranslatorAwareInterface */ protected $facetsIni = 'facets'; - /** - * Translator (or null if unavailable) - * - * @var \Zend\I18n\Translator\Translator - */ - protected $translator = null; - /** * Constructor * @@ -714,45 +709,4 @@ abstract class Options implements TranslatorAwareInterface // No limit by default: return -1; } - - /** - * Sleep magic method -- the translator can't be serialized, so we need to - * exclude it from serialization. Since we can't obtain a new one in the - * __wakeup() method, it needs to be re-injected from outside. - * - * @return array - */ - public function __sleep() - { - $vars = get_object_vars($this); - unset($vars['translator']); - $vars = array_keys($vars); - return $vars; - } - - /** - * Set a translator - * - * @param \Zend\I18n\Translator\Translator $translator Translator - * - * @return Options - */ - public function setTranslator(\Zend\I18n\Translator\Translator $translator) - { - $this->translator = $translator; - return $this; - } - - /** - * Translate a string if a translator is available. - * - * @param string $msg Message to translate - * - * @return string - */ - public function translate($msg) - { - return null !== $this->translator - ? $this->translator->translate($msg) : $msg; - } } \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php b/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php index 64883176e55fd578f1e00b4920d043f71b70d21e..9a7b9767a1c6de6ebd695730981237c8a4d89ee1 100644 --- a/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php +++ b/module/VuFind/src/VuFind/Search/Solr/HierarchicalFacetListener.php @@ -36,7 +36,7 @@ use VuFindSearch\Backend\BackendInterface; use Zend\EventManager\SharedEventManagerInterface; use Zend\EventManager\EventInterface; use Zend\ServiceManager\ServiceLocatorInterface; -use Zend\I18n\Translator\Translator; +use Zend\I18n\Translator\TranslatorInterface; /** * Solr hierarchical facet handling listener. @@ -81,7 +81,7 @@ class HierarchicalFacetListener /** * Translator. * - * @var Translator + * @var TranslatorInterface */ protected $translator; diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index de827249ce2b55ca1e62f9bfc06c808b62a93952..1982865785bbc900f5339c73a8c6b60c81ff05ff 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -723,7 +723,7 @@ class Factory * * @param ServiceManager $sm Service manager. * - * @return \Zend\I18n\Translator\Translator + * @return \Zend\I18n\Translator\TranslatorInterface */ public static function getTranslator(ServiceManager $sm) { diff --git a/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php b/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php index 5bfa333c695e68b39c90deae8576712959da49bd..b552f55c062f878344642fba17d3e96864805060 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/DisplayLanguageOption.php @@ -26,6 +26,7 @@ * @link http://vufind.org/wiki/vufind2:developer_manual Wiki */ namespace VuFind\View\Helper\Root; +use Zend\I18n\Translator\TranslatorInterface; /** * DisplayLanguageOption view helper @@ -41,16 +42,16 @@ class DisplayLanguageOption extends \Zend\View\Helper\AbstractHelper /** * Translator (or null if unavailable) * - * @var \Zend\I18n\Translator\Translator + * @var TranslatorInterface */ protected $translator = null; /** * Constructor * - * @param \Zend\I18n\Translator\Translator $translator Main VuFind translator + * @param TranslatorInterface $translator Main VuFind translator */ - public function __construct(\Zend\I18n\Translator\Translator $translator) + public function __construct(TranslatorInterface $translator) { // Clone the translator; we need to switch language for the purposes // of this plugin, but we don't want that change to happen globally.