From 282d1f7f277851ee39ae311b064d89098bb07e3b Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 3 Sep 2014 10:44:43 -0400 Subject: [PATCH] Consistent, prefixed translation of item locations. - Resolves VUFIND-1027. --- .../src/VuFind/Controller/AjaxController.php | 33 +++++++++++++++---- .../templates/RecordTab/holdingsils.phtml | 2 +- .../templates/ajax/status-full.phtml | 2 +- .../templates/RecordTab/holdingsils.phtml | 2 +- .../templates/ajax/status-full.phtml | 2 +- .../templates/RecordTab/holdingsils.phtml | 2 +- .../templates/ajax/status-full.phtml | 2 +- .../templates/RecordTab/holdingsils.phtml | 2 +- 8 files changed, 33 insertions(+), 14 deletions(-) diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 5d415ded688..987dd22ed2a 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -277,13 +277,15 @@ class AjaxController extends AbstractBase * Support method for getItemStatuses() -- when presented with multiple values, * pick which one(s) to send back via AJAX. * - * @param array $list Array of values to choose from. - * @param string $mode config.ini setting -- first, all or msg - * @param string $msg Message to display if $mode == "msg" + * @param array $list Array of values to choose from. + * @param string $mode config.ini setting -- first, all or msg + * @param string $msg Message to display if $mode == "msg" + * @param string $transPrefix Translator prefix to apply to values (false to + * omit translation of values) * * @return string */ - protected function pickValue($list, $mode, $msg) + protected function pickValue($list, $mode, $msg, $transPrefix = false) { // Make sure array contains only unique values: $list = array_unique($list); @@ -291,11 +293,25 @@ class AjaxController extends AbstractBase // If there is only one value in the list, or if we're in "first" mode, // send back the first list value: if ($mode == 'first' || count($list) == 1) { - return $list[0]; + if (!$transPrefix) { + return $list[0]; + } else { + return $this->translate($transPrefix . $list[0], array(), $list[0]); + } } else if (count($list) == 0) { // Empty list? Return a blank string: return ''; } else if ($mode == 'all') { + // Translate values if necessary: + if ($transPrefix) { + $transList = array(); + foreach ($list as $current) { + $transList[] = $this->translate( + $transPrefix . $current, array(), $current + ); + } + $list = $transList; + } // All values mode? Return comma-separated values: return implode(', ', $list); } else { @@ -349,7 +365,7 @@ class AjaxController extends AbstractBase // Determine location string based on findings: $location = $this->pickValue( - $locations, $locationSetting, 'Multiple Locations' + $locations, $locationSetting, 'Multiple Locations', 'location_' ); $availability_message = $use_unknown_status @@ -416,7 +432,10 @@ class AjaxController extends AbstractBase $locationInfo = array( 'availability' => isset($details['available']) ? $details['available'] : false, - 'location' => htmlentities($location, ENT_COMPAT, 'UTF-8'), + 'location' => htmlentities( + $this->translate('location_' . $location, array(), $location), + ENT_COMPAT, 'UTF-8' + ), 'callnumbers' => htmlentities($locationCallnumbers, ENT_COMPAT, 'UTF-8') ); diff --git a/themes/blueprint/templates/RecordTab/holdingsils.phtml b/themes/blueprint/templates/RecordTab/holdingsils.phtml index f8f5a227290..8b6ab43d8a9 100644 --- a/themes/blueprint/templates/RecordTab/holdingsils.phtml +++ b/themes/blueprint/templates/RecordTab/holdingsils.phtml @@ -46,7 +46,7 @@ <? if ($openUrl): ?><?=$this->openUrl($openUrl);?><? endif; ?> <? endif; ?> <? foreach ($holdings as $holding): ?> -<h3><?=$this->transEsc($holding['location'])?></h3> +<h3><?=$this->transEsc('location_' . $holding['location'], array(), $holding['location'])?></h3> <table cellpadding="2" cellspacing="0" border="0" class="citation" summary="<?=$this->transEsc('Holdings details from')?> <?=$this->transEsc($holding['location'])?>"> <? $callNos = $this->tab->getUniqueCallNumbers($holding['items']); if (!empty($callNos)): ?> <tr> diff --git a/themes/blueprint/templates/ajax/status-full.phtml b/themes/blueprint/templates/ajax/status-full.phtml index b760be9469e..2368f3f1f51 100644 --- a/themes/blueprint/templates/ajax/status-full.phtml +++ b/themes/blueprint/templates/ajax/status-full.phtml @@ -8,7 +8,7 @@ <? $i = 0; foreach ($this->statusItems as $item): ?> <? if (++$i == 5) break; // Show no more than 5 items ?> <tr> - <td class="locationColumn"><?=$this->escapeHtml($item['location'])?></td> + <td class="locationColumn"><?=$this->transEsc('location_' . $item['location'], array(), $item['location'])?></td> <td class="callnumColumn"><?=$this->escapeHtml($item['callnumber'])?></td> <td class="statusColumn"> <? if (isset($item['use_unknown_message']) && $item['use_unknown_message']): ?> diff --git a/themes/bootstrap/templates/RecordTab/holdingsils.phtml b/themes/bootstrap/templates/RecordTab/holdingsils.phtml index d9297d7010d..5ecf6200269 100644 --- a/themes/bootstrap/templates/RecordTab/holdingsils.phtml +++ b/themes/bootstrap/templates/RecordTab/holdingsils.phtml @@ -46,7 +46,7 @@ <? if ($openUrl): ?><?=$this->openUrl($openUrl);?><? endif; ?> <? endif; ?> <? foreach ($holdings as $holding): ?> -<h3><?=$this->transEsc($holding['location'])?></h3> +<h3><?=$this->transEsc('location_' . $holding['location'], array(), $holding['location'])?></h3> <table class="table table-striped" summary="<?=$this->transEsc('Holdings details from')?> <?=$this->transEsc($holding['location'])?>"> <? $callNos = $this->tab->getUniqueCallNumbers($holding['items']); if (!empty($callNos)): ?> <tr> diff --git a/themes/bootstrap/templates/ajax/status-full.phtml b/themes/bootstrap/templates/ajax/status-full.phtml index 443a1a3f1db..d5d84c1e870 100644 --- a/themes/bootstrap/templates/ajax/status-full.phtml +++ b/themes/bootstrap/templates/ajax/status-full.phtml @@ -7,7 +7,7 @@ <? $i = 0; foreach ($this->statusItems as $item): ?> <? if (++$i == 5) break; // Show no more than 5 items ?> <tr> - <td><?=$this->escapeHtml($item['location'])?></td> + <td><?=$this->transEsc('location_' . $item['location'], array(), $item['location'])?></td> <td><?=$this->escapeHtml($item['callnumber'])?></td> <td> <? if (isset($item['use_unknown_message']) && $item['use_unknown_message']): ?> diff --git a/themes/bootstrap3/templates/RecordTab/holdingsils.phtml b/themes/bootstrap3/templates/RecordTab/holdingsils.phtml index 8e10a7af8f5..dca7e05bee1 100644 --- a/themes/bootstrap3/templates/RecordTab/holdingsils.phtml +++ b/themes/bootstrap3/templates/RecordTab/holdingsils.phtml @@ -46,7 +46,7 @@ <? if ($openUrl): ?><?=$this->openUrl($openUrl);?><? endif; ?> <? endif; ?> <? foreach ($holdings as $holding): ?> -<h3><?=$this->transEsc($holding['location'])?></h3> +<h3><?=$this->transEsc('location_' . $holding['location'], array(), $holding['location'])?></h3> <table class="table table-striped" summary="<?=$this->transEsc('Holdings details from')?> <?=$this->transEsc($holding['location'])?>"> <? $callNos = $this->tab->getUniqueCallNumbers($holding['items']); if (!empty($callNos)): ?> <tr> diff --git a/themes/bootstrap3/templates/ajax/status-full.phtml b/themes/bootstrap3/templates/ajax/status-full.phtml index 5d79eca7ed2..7e5404672b0 100644 --- a/themes/bootstrap3/templates/ajax/status-full.phtml +++ b/themes/bootstrap3/templates/ajax/status-full.phtml @@ -7,7 +7,7 @@ <? $i = 0; foreach ($this->statusItems as $item): ?> <? if (++$i == 5) break; // Show no more than 5 items ?> <tr> - <td><?=$this->escapeHtml($item['location'])?></td> + <td><?=$this->transEsc('location_' . $item['location'], array(), $item['location'])?></td> <td><?=$this->escapeHtml($item['callnumber'])?></td> <td> <? if (isset($item['use_unknown_message']) && $item['use_unknown_message']): ?> diff --git a/themes/jquerymobile/templates/RecordTab/holdingsils.phtml b/themes/jquerymobile/templates/RecordTab/holdingsils.phtml index d2f1bb380f3..cae9ae0446e 100644 --- a/themes/jquerymobile/templates/RecordTab/holdingsils.phtml +++ b/themes/jquerymobile/templates/RecordTab/holdingsils.phtml @@ -34,7 +34,7 @@ <a rel="external" class="holdPlace" href="<?=$this->recordLink()->getRequestUrl($holdingTitleHold, false)?>"><?=$this->transEsc('title_hold_place')?></a> <? endif; ?> <? foreach ($holdings as $holding): ?> -<h4><?=$this->transEsc($holding['location'])?></h4> +<h4><?=$this->transEsc('location_' . $holding['location'], array(), $holding['location'])?></h4> <table class="holdings" summary="<?=$this->transEsc('Holdings details from')?> <?=$this->transEsc($holding['location'])?>"> <? $callNos = $this->tab->getUniqueCallNumbers($holding['items']); if (!empty($callNos)): ?> <tr> -- GitLab