From 244177811a904451503d0454ae4c27f9b0043a70 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 5 Feb 2015 15:41:29 -0500 Subject: [PATCH] Refactored translation code for Zend Framework 2.3.4 compatibility. --- .../VuFind/src/VuFind/Auth/AbstractBase.php | 47 +------ .../src/VuFind/Connection/Wikipedia.php | 44 +----- .../VuFind/Hierarchy/TreeRenderer/JSTree.php | 33 +---- .../Translator/TranslatorAwareInterface.php | 8 +- .../I18n/Translator/TranslatorAwareTrait.php | 129 ++++++++++++++++++ module/VuFind/src/VuFind/ILS/Connection.php | 29 +--- .../VuFind/src/VuFind/ILS/Driver/Amicus.php | 33 +---- module/VuFind/src/VuFind/ILS/Driver/LBS4.php | 28 +--- module/VuFind/src/VuFind/ILS/Driver/NoILS.php | 33 +---- .../VuFind/src/VuFind/ILS/Driver/Voyager.php | 33 +---- module/VuFind/src/VuFind/Mailer/Mailer.php | 35 +---- .../src/VuFind/Recommend/AuthorInfo.php | 36 ++--- .../src/VuFind/RecordDriver/AbstractBase.php | 35 +---- .../VuFind/src/VuFind/Search/Base/Options.php | 50 +------ .../Search/Solr/HierarchicalFacetListener.php | 4 +- module/VuFind/src/VuFind/Service/Factory.php | 2 +- .../Helper/Root/DisplayLanguageOption.php | 7 +- 17 files changed, 169 insertions(+), 417 deletions(-) create mode 100644 module/VuFind/src/VuFind/I18n/Translator/TranslatorAwareTrait.php diff --git a/module/VuFind/src/VuFind/Auth/AbstractBase.php b/module/VuFind/src/VuFind/Auth/AbstractBase.php index f26bf290791..b33f4d398d9 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 c4dd9b5127c..701a3ccb87d 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 06ec8fef58b..3bd93facabf 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 be2e63233d8..29aa6fcf915 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 00000000000..ec5cb822ac2 --- /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 917d33f1a00..a1f6003b1ec 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 3010bd4b666..968b93163fe 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 b4afce7ad90..68d554116ca 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 91689cbef1c..592bc810680 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 f84015441a8..d58b5820bdf 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 ad47a28b172..35965a3e9db 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 8172400f456..e0f86e48f82 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 5bcb6a14565..f07e5d20370 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 c49efc94921..45be6b20756 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 64883176e55..9a7b9767a1c 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 de827249ce2..1982865785b 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 5bfa333c695..b552f55c062 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. -- GitLab