From ecd1ab8740f893d534f923cc95f39b74d132e5d8 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Wed, 18 Feb 2015 15:33:31 -0500
Subject: [PATCH] Centralized locale setting and made it more robust. - Thanks
 to Ere Maijala for suggested test improvements.

---
 module/VuFind/src/VuFind/Bootstrapper.php             |  7 +++++--
 .../VuFind/src/VuFind/Controller/BrowseController.php | 11 ++++-------
 .../View/Helper/Root/SafeMoneyFormatTest.php          |  5 ++++-
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/module/VuFind/src/VuFind/Bootstrapper.php b/module/VuFind/src/VuFind/Bootstrapper.php
index a0357003d15..b352f21ffb6 100644
--- a/module/VuFind/src/VuFind/Bootstrapper.php
+++ b/module/VuFind/src/VuFind/Bootstrapper.php
@@ -179,8 +179,11 @@ class Bootstrapper
         // the config file if this doesn't work -- different systems may vary in
         // their behavior here.
         setlocale(
-            LC_MONETARY,
-            ["{$this->config->Site->locale}.UTF-8", $this->config->Site->locale]
+            LC_ALL, [
+                "{$this->config->Site->locale}.UTF8",
+                "{$this->config->Site->locale}.UTF-8",
+                $this->config->Site->locale
+            ]
         );
         date_default_timezone_set($this->config->Site->timezone);
     }
diff --git a/module/VuFind/src/VuFind/Controller/BrowseController.php b/module/VuFind/src/VuFind/Controller/BrowseController.php
index 540eb226366..a7576dd4f4d 100644
--- a/module/VuFind/src/VuFind/Controller/BrowseController.php
+++ b/module/VuFind/src/VuFind/Controller/BrowseController.php
@@ -611,13 +611,10 @@ class BrowseController extends AbstractBase
             if (isset($this->config->Browse->alphabetical_order)
                 && $this->config->Browse->alphabetical_order
             ) {
-                if (isset($this->config->Site->locale)) {
-                    setlocale(LC_ALL, $this->config->Site->locale . ".utf8");
-                    $callback = function ($a, $b) {
-                        return strcoll($a['displayText'], $b['displayText']);
-                    };
-                    usort($result[$facet]['list'], $callback);
-                }
+                $callback = function ($a, $b) {
+                    return strcoll($a['displayText'], $b['displayText']);
+                };
+                usort($result[$facet]['list'], $callback);
             }
             return $result[$facet]['list'];
         } else {
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/SafeMoneyFormatTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/SafeMoneyFormatTest.php
index 90f8248efe7..7824e799be6 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/SafeMoneyFormatTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/SafeMoneyFormatTest.php
@@ -55,7 +55,10 @@ class SafeMoneyFormatTest extends \PHPUnit_Framework_TestCase
     {
         // store current default and set a value for consistency in testing
         $this->locale = setlocale(LC_MONETARY, 0);
-        setlocale(LC_MONETARY, 'en_US.UTF8');
+        $locales = ['en_US.UTF8', 'en_US.UTF-8', 'en_US'];
+        if (false === setlocale(LC_MONETARY, $locales)) {
+            $this->markTestSkipped('Problem setting up locale');
+        }
     }
 
     /**
-- 
GitLab