Skip to content
Snippets Groups Projects
Commit 4a2593da authored by Robert Lange's avatar Robert Lange Committed by Dorian Merz
Browse files

refs #18012 [finc] add more terms for Language Tag

* also see 18509
* use language tags in format facet
** refactor method getLanguageTag in side facets helper
*** add parameter for html attributes
*** always return html wrapped in specified element tag
*** lax check if tag key starts with term instead of full match
** fetch language tags in finc format-list for format facets on result list
* refactor language tags for performance
** avoid pregmatch, use fastest isset
*** keys in facet.ini must be case sensitive and full length
* add more tags in facet.ini
parent d1e70265
No related merge requests found
...@@ -241,12 +241,109 @@ hide_facets = "genre_facet,era_facet,geographic_facet" ...@@ -241,12 +241,109 @@ hide_facets = "genre_facet,era_facet,geographic_facet"
; Special terms (key), which can't / shouldn't be translated but marked as other language (value) for BARF reasons ; Special terms (key), which can't / shouldn't be translated but marked as other language (value) for BARF reasons
[LanguageTags] [LanguageTags]
De Gruyter Journals / Social Sciences and Humanities = "en" en[] = "American Museum of Natural History"
Free = "en" en[] = "American Museum of Natural History Library"
JSTOR Music Archive = "en" en[] = "Article"
Local = "en" en[] = "Article, E-Article"
Microform = "en" en[] = "BASE - Bielefeld Academic Search Engine"
Open Access = "en" en[] = "Biodiversity Heritage Library (BHL)"
Online = "en" en[] = "Bioregional Assessment Program (isOwnedBy)"
Proceeding = "en" en[] = "Book, E-Book"
Répertoire International des Sources Musicales = "fr" en[] = "CEEOL Central and Eastern European Online Library"
en[] = "Charles I King of England"
en[] = "Charles I, King of England,"
en[] = "Charles II, King of England,"
en[] = "Dance in Video"
en[] = "De Gruyter Journals / Social Sciences and Humanities"
en[] = "Department of Education (isOwnedBy)"
en[] = "DOAJ Directory of Open Access Journals"
en[] = "Early English Books Online"
en[] = "Early English Books Online EEBO"
en[] = "EconStor (German National Library of Economics, ZBW)"
en[] = "Eighteenth Century Collections Online / ECCO"
en[] = "Elsevier Journals"
en[] = "England and Wales Parliament"
en[] = "England and Wales Sovereign (1625-1649 : Charles I)"
en[] = "England and Wales. Parliament"
en[] = "England and Wales. Sovereign (1625-1649 : Charles I)"
en[] = "E-Article"
en[] = "E-Proceedings"
en[] = "Field Museum of Natural History Library"
en[] = "Free"
en[] = "Harvard University, Museum of Comparative Zoology, Ernst Mayr Library"
en[] = "IEEE Xplore Library"
en[] = "IMSLP (Petrucci Library)"
en[] = "JSTOR Arts & Sciences I Archive"
en[] = "JSTOR Arts & Sciences II Archive"
en[] = "JSTOR Arts & Sciences III Archive"
en[] = "JSTOR Arts & Sciences IV Archive"
en[] = "JSTOR Arts & Sciences V Archive"
en[] = "JSTOR Arts & Sciences VI Archive"
en[] = "JSTOR Arts & Sciences VII Archive"
en[] = "JSTOR Arts & Sciences VIII Archive"
en[] = "JSTOR Arts & Sciences IX Archive"
en[] = "JSTOR Arts & Sciences X Archive"
en[] = "JSTOR Arts & Sciences XO Archive"
en[] = "JSTOR Business & Economics"
en[] = "JSTOR Business I Archive"
en[] = "JSTOR Business II Archive"
en[] = "JSTOR Business III Archive"
en[] = "JSTOR Business IV Archive"
en[] = "JSTOR Business V Archive"
en[] = "JSTOR Life Sciences Archive"
en[] = "JSTOR Music"
en[] = "Kit"
en[] = "Local"
en[] = "Microform"
en[] = "Music Online Reference"
en[] = "NASA Technical Reports Server (NTRS)"
en[] = "National Bureau of Economic Research"
en[] = "Natural History Museum Library, London"
en[] = "Notated Music"
en[] = "not assigned"
en[] = "No linguistic content"
en[] = "Open Access"
en[] = "Online"
en[] = "Oxford University Research Archive (ORA)"
en[] = "PANGAEA - Data Publisher for Earth & Environmental Science (AWI Bremerhaven/MARUM Bremen)"
en[] = "Proceeding"
en[] = "Publication Server of Goethe University Frankfurt am Main"
en[] = "Rumsey Collection"
en[] = "Saskatchewan Natural History Society"
en[] = "Sheet"
en[] = "Smithsonian Institution Archives"
en[] = "Smithsonian Libraries"
en[] = "The Pennsylvania State University CiteSeerX Archives"
en[] = "Thesis"
en[] = "TwoDimensionalMovingImage"
en[] = "United States Congress House"
en[] = "United States Congress House Committee on Claims"
en[] = "United States Congress House Committee on Invalid Pensions"
en[] = "United States Congress Senate"
en[] = "United States Congress Senate Committee on Pensions"
en[] = "United States Congress House Committee on the Judiciary"
en[] = "United States War Dept"
en[] = "United States Dept. of the Treasury"
en[] = "United States Congress Senate Committee on Claims"
en[] = "United States Congress House Committee on Military Affairs"
en[] = "United States Court of Claims (1855-1982)"
en[] = "United States Congress Senate Committee on Military Affairs"
en[] = "United States Army Corps of Engineers"
en[] = "United States War Dept Engineer Dept"
en[] = "United States War Dept Ordnance Dept"
en[] = "United States Congress House Committee on War Claims"
en[] = "United States Congress House Committee on Interstate and Foreign Commerce"
en[] = "United States Congress Senate Committee on Commerce"
en[] = "United States Congress House Committee on Rules"
en[] = "United States Dept. of the Interior"
en[] = "United States Congress House Committee on Public Lands"
en[] = "United States Dept. of State"
en[] = "United States Congress House Committee on Pensions"
en[] = "United States Congress House Committee on the District of Columbia"
en[] = "United States Congress Senate Committee on the District of Columbia"
en[] = "United States Executive Office of the President Bureau of the Budget (1939-1970)"
en[] = "University Library, University of Illinois Urbana Champaign"
en[] = "University of California Libraries (archive.org)"
en[] = "Visual Media"
fr[] = "Persée"
fr[] = "Répertoire International des Sources Musicales"
...@@ -50,15 +50,25 @@ class SideFacet extends AbstractHelper ...@@ -50,15 +50,25 @@ class SideFacet extends AbstractHelper
*/ */
protected $config; protected $config;
/**
* Language tags
*
* @var array
*/
protected $languageTags = [];
/** /**
* Constructor * Constructor
* *
* @param \Zend\Config\Config $config VuFind configuration * @param \Zend\Config\Config $config VuFind configuration
* @access public
*/ */
public function __construct($config = null) public function __construct($config = null)
{ {
$this->config = $config; $this->config = $config;
foreach ($this->config->LanguageTags ?? [] as $langOfTags => $tags) {
$this->languageTags[$langOfTags] = array_flip($tags->toArray());
}
} }
/** /**
...@@ -67,7 +77,6 @@ class SideFacet extends AbstractHelper ...@@ -67,7 +77,6 @@ class SideFacet extends AbstractHelper
* @param array $sideFacets List of side facets * @param array $sideFacets List of side facets
* *
* @return array Filtered side facets * @return array Filtered side facets
* @access public
*/ */
public function displayAllowedFacetValues($sideFacets) public function displayAllowedFacetValues($sideFacets)
{ {
...@@ -93,25 +102,37 @@ class SideFacet extends AbstractHelper ...@@ -93,25 +102,37 @@ class SideFacet extends AbstractHelper
/** /**
* Get term with corresponding language tag within html element * Get term with corresponding language tag within html element
* *
* @param string $term translation to decorate with language tag * @param string $term translation to decorate with language tag
* @param string $element wrapping html element * @param string $element wrapping html element
* @param string $language current language * @param string $curLang current language
* @param array $attributes set additional attributes by key => value
* *
* @return string * @return string
* *
* @deprecated remove when there's a VuFind core solution * @deprecated remove when there's a VuFind core solution
*/ */
public function getLanguageTag(string $term, string $element, string $language) public function getLanguageTag(string $term, string $element, string $curLang, array $attributes = [])
{ {
$retval = $term; $attributesString = "";
foreach ($attributes as $attrKey => $attrVal) {
$attributesString .= "$attrKey=\"$attrVal\" ";
}
if (isset($this->config->LanguageTags[$term]) foreach ($this->languageTags as $langOfTags => $tags) {
&& $this->config->LanguageTags[$term] !== $language if ($curLang === $langOfTags) {
) { // no tag needed for native terms
$retval = "<$element " . 'lang="' . $this->config->LanguageTags[$term] continue;
. '">' . "$term</$element>"; }
if (isset($tags["$term"])) {
$termLang = $langOfTags;
break;
}
} }
return $retval; if (isset($termLang)) {
return "<$element lang=\"$termLang\" $attributesString>$term</$element>";
} else {
return "<$element $attributesString>$term</$element>";
}
} }
} }
<?php $formats = $this->driver->getFormats(); <?php $formats = $this->driver->getFormats();
$translated_formats = []; $translated_formats = [];
foreach ($formats as $format): ?> foreach ($formats as $format): ?>
<?php $translated_formats[] = $translated_format = $this->transEsc($format); ?> <?php
<span class="format <?=$this->record($this->driver)->getFormatClass($format)?>"><?=$translated_format?></span> $translated_formats[] = $translated_format = $this->transEsc($format);
$formatClass = $this->record($this->driver)->getFormatClass($format);
?>
<?php /* @deprecated: use SideFacets Helper to decorate language tags, remove when there's a VuFind core solution */ ?>
<?=$this->sideFacet()->getLanguageTag($translated_format, 'span', $this->layout()->userLang, ["class" => "format $formatClass"]);?>
<?php endforeach; ?> <?php endforeach; ?>
<?php /* New genre string to display nxt to format in RESULT LIST and RECORD/Detail View, #11703, limit to SID 0 CK */ ?> <?php /* New genre string to display nxt to format in RESULT LIST and RECORD/Detail View, #11703, limit to SID 0 CK */ ?>
<?php /* Removes (uncommented) new genre string to display with k10plus index in RESULT LIST and RECORD/Detail View, #14912 FM */ ?> <?php /* Removes (uncommented) new genre string to display with k10plus index in RESULT LIST and RECORD/Detail View, #14912 FM */ ?>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment