From a3b59c6df5aeb03bf9506c423d68933c0cc53257 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 19 Apr 2013 15:16:44 -0400
Subject: [PATCH] Cleaner translator injection for search options.

---
 .../VuFind/src/VuFind/Search/Base/Options.php | 31 ++++++++++++++++---
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/module/VuFind/src/VuFind/Search/Base/Options.php b/module/VuFind/src/VuFind/Search/Base/Options.php
index e914f699045..560102a9411 100644
--- a/module/VuFind/src/VuFind/Search/Base/Options.php
+++ b/module/VuFind/src/VuFind/Search/Base/Options.php
@@ -26,7 +26,8 @@
  * @link     http://www.vufind.org  Main Page
  */
 namespace VuFind\Search\Base;
-use Zend\ServiceManager\ServiceLocatorAwareInterface,
+use VuFind\I18n\Translator\TranslatorAwareInterface,
+    Zend\ServiceManager\ServiceLocatorAwareInterface,
     Zend\ServiceManager\ServiceLocatorInterface,
     Zend\Session\Container as SessionContainer;
 
@@ -41,7 +42,8 @@ use Zend\ServiceManager\ServiceLocatorAwareInterface,
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     http://www.vufind.org  Main Page
  */
-abstract class Options implements ServiceLocatorAwareInterface
+abstract class Options implements ServiceLocatorAwareInterface,
+    TranslatorAwareInterface
 {
     // Available sort options
     protected $sortOptions = array();
@@ -111,6 +113,13 @@ abstract class Options implements ServiceLocatorAwareInterface
      */
     protected $facetsIni = 'facets';
 
+    /**
+     * Translator (or null if unavailable)
+     *
+     * @var \Zend\I18n\Translator\Translator
+     */
+    protected $translator = null;
+
     /**
      * Service locator
      *
@@ -607,6 +616,19 @@ abstract class Options implements ServiceLocatorAwareInterface
         return $this->serviceLocator;
     }
 
+    /**
+     * 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.
      *
@@ -616,8 +638,7 @@ abstract class Options implements ServiceLocatorAwareInterface
      */
     public function translate($msg)
     {
-        return $this->getServiceLocator()->has('VuFind\Translator')
-            ? $this->getServiceLocator()->get('VuFind\Translator')->translate($msg)
-            : $msg;
+        return null !== $this->translator
+            ? $this->translator->translate($msg) : $msg;
     }
 }
\ No newline at end of file
-- 
GitLab