From 4cdda83e0ba81ac924b303c580ed79edaa1a4e75 Mon Sep 17 00:00:00 2001
From: Juha Luoma <33253757+LuomaJuha@users.noreply.github.com>
Date: Tue, 17 Sep 2019 21:37:58 +0300
Subject: [PATCH] Citation improvements (#1417)

- Include all authors, not just first primary author
- Translate 'and'
- Correct 'et al.' punctuation
---
 languages/en.ini                              |  1 +
 languages/fi.ini                              |  1 +
 languages/sv.ini                              |  1 +
 .../src/VuFind/View/Helper/Root/Citation.php  | 24 ++++++++++---------
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/languages/en.ini b/languages/en.ini
index 92f69cd1b97..92d4692b660 100644
--- a/languages/en.ini
+++ b/languages/en.ini
@@ -59,6 +59,7 @@ alphabrowselink_html = "Browse entries by %%index%% starting from <a href="%%url
 An error has occurred = "An error has occurred"
 An error occurred during execution; please try again later. = "An error occurred during execution; please try again later."
 AND = "AND"
+and = "and"
 anonymous_tags = "Anonymous Tags"
 APA Citation = "APA Citation"
 applied_filter = "Applied Filter"
diff --git a/languages/fi.ini b/languages/fi.ini
index 6c7afcc2c3b..08cd48f82f7 100644
--- a/languages/fi.ini
+++ b/languages/fi.ini
@@ -58,6 +58,7 @@ alphabrowselink_html = "Selaa %%index%%-indeksiä alkaen kohdasta <a href="%%url
 An error has occurred = "Tapahtui virhe"
 An error occurred during execution; please try again later. = "Virhe toimintoa suoritettaessa. Yritä myöhemmin uudelleen."
 AND = "JA"
+and = "ja"
 anonymous_tags = "Tuntemattomien tagit"
 APA Citation = "APA-viite"
 applied_filter = "Käytetty suodatus"
diff --git a/languages/sv.ini b/languages/sv.ini
index 885236d1a8e..8ca9d4a5218 100644
--- a/languages/sv.ini
+++ b/languages/sv.ini
@@ -58,6 +58,7 @@ alphabrowselink_html = "Bläddra efter %%index%% från <a href="%%url%%">%%from%
 An error has occurred = "Det har uppstått ett fel"
 An error occurred during execution; please try again later. = "Utförandet misslyckades. Försök på nytt efter en stund."
 AND = "OCH"
+and = "och"
 anonymous_tags = "Anonyma taggar"
 APA Citation = "APA-referens"
 applied_filter = "Filter i bruk"
diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Citation.php b/module/VuFind/src/VuFind/View/Helper/Root/Citation.php
index dff3e52860b..a8fb868655a 100644
--- a/module/VuFind/src/VuFind/View/Helper/Root/Citation.php
+++ b/module/VuFind/src/VuFind/View/Helper/Root/Citation.php
@@ -22,12 +22,14 @@
  * @category VuFind
  * @package  View_Helpers
  * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Juha Luoma <juha.luoma@helsinki.fi>
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org/wiki/development Wiki
  */
 namespace VuFind\View\Helper\Root;
 
 use VuFind\Date\DateException;
+use VuFind\I18n\Translator\TranslatorAwareInterface;
 
 /**
  * Citation view helper
@@ -35,11 +37,15 @@ use VuFind\Date\DateException;
  * @category VuFind
  * @package  View_Helpers
  * @author   Demian Katz <demian.katz@villanova.edu>
+ * @author   Juha Luoma <juha.luoma@helsinki.fi>
  * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
  * @link     https://vufind.org/wiki/development Wiki
  */
 class Citation extends \Zend\View\Helper\AbstractHelper
+    implements TranslatorAwareInterface
 {
+    use \VuFind\I18n\Translator\TranslatorAwareTrait;
+
     /**
      * Citation details
      *
@@ -82,16 +88,12 @@ class Citation extends \Zend\View\Helper\AbstractHelper
     public function __invoke($driver)
     {
         // Build author list:
-        $authors = [];
-        $primary = $driver->tryMethod('getPrimaryAuthor');
-        if (empty($primary)) {
-            $primary = $driver->tryMethod('getCorporateAuthor');
-        }
-        if (!empty($primary)) {
-            $authors[] = $primary;
+        $authors = (array)$driver->tryMethod('getPrimaryAuthors');
+        if (empty($authors)) {
+            $authors = (array)$driver->tryMethod('getCorporateAuthors');
         }
-        $secondary = $driver->tryMethod('getSecondaryAuthors');
-        if (is_array($secondary) && !empty($secondary)) {
+        $secondary = (array)$driver->tryMethod('getSecondaryAuthors');
+        if (!empty($secondary)) {
             $authors = array_unique(array_merge($authors, $secondary));
         }
 
@@ -702,12 +704,12 @@ class Citation extends \Zend\View\Helper\AbstractHelper
             $i = 0;
             if (count($this->details['authors']) > $etAlThreshold) {
                 $author = $this->details['authors'][0];
-                $authorStr = $this->cleanNameDates($author) . ', et al';
+                $authorStr = $this->cleanNameDates($author) . ', et al.';
             } else {
                 foreach ($this->details['authors'] as $author) {
                     if (($i + 1 == count($this->details['authors'])) && ($i > 0)) {
                         // Last
-                        $authorStr .= ', and ' .
+                        $authorStr .= ', ' . $this->translate('and') . ' ' .
                             $this->reverseName($this->stripPunctuation($author));
                     } elseif ($i > 0) {
                         $authorStr .= ', ' .
-- 
GitLab