diff --git a/controller/WebController.php b/controller/WebController.php index 97a02d921..734514afe 100644 --- a/controller/WebController.php +++ b/controller/WebController.php @@ -178,6 +178,8 @@ public function invokeVocabularyConcept(Request $request) if ($this->notModified($results[0])) { return; } + $customLabels = $vocab->getConfig()->getPropertyLabelOverrides(); + $pluginParameters = json_encode($vocab->getConfig()->getPluginParameters()); $template = (in_array('skos:Concept', $results[0]->getType()) || in_array('skos:ConceptScheme', $results[0]->getType())) ? $this->twig->loadTemplate('concept-info.twig') : $this->twig->loadTemplate('group-contents.twig'); @@ -191,7 +193,8 @@ public function invokeVocabularyConcept(Request $request) 'bread_crumbs' => $crumbs['breadcrumbs'], 'combined' => $crumbs['combined'], 'request' => $request, - 'plugin_params' => $pluginParameters) + 'plugin_params' => $pluginParameters, + 'custom_labels' => $customLabels) ); } diff --git a/model/VocabularyConfig.php b/model/VocabularyConfig.php index 117533758..e33dc3249 100644 --- a/model/VocabularyConfig.php +++ b/model/VocabularyConfig.php @@ -8,6 +8,7 @@ class VocabularyConfig extends BaseConfig private $pluginRegister; private $pluginParameters = array(); private $languageOrderCache = array(); + private $labelOverrides = array(); const DEFAULT_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy", "skos:definition", "skos:broader", "isothes:broaderGeneric", @@ -33,6 +34,7 @@ public function __construct($resource, $globalPlugins=array()) $this->resource = $resource; $this->globalPlugins = $globalPlugins; $this->setParameterizedPlugins(); + $this->setPropertyLabelOverrides(); $pluginArray = $this->getPluginArray(); $this->pluginRegister = new PluginRegister($pluginArray); } @@ -71,7 +73,6 @@ public function getPluginArray() : array /** * Sets array of parameterized plugins - * @param Easyrdf\Resource $pluginResource * @return void */ private function setParameterizedPlugins() : void @@ -123,6 +124,46 @@ private function setPluginParameters(Easyrdf\Resource $pluginResource) : void } } + /** + * Sets array of configured property label overrides + * @return void + */ + private function setPropertyLabelOverrides() : void + { + $this->labelOverrides = array(); + $overrides = $this->resource->allResources('skosmos:propertyLabelOverride'); + if (!empty($overrides)) { + foreach ($overrides as $override) { + $this->setLabelOverride($override); + } + } + } + + /** + * Updates array of label overrides by adding a new override from the configuration file + * @param Easyrdf\Resource $labelOverride + * @return void + */ + private function setLabelOverride(Easyrdf\Resource $override) : void + { + $labelProperty = $override->getResource('skosmos:property'); + $labelPropUri = $labelProperty->shorten(); + if (empty($this->labelOverrides[$labelPropUri])) { + $this->labelOverrides[$labelPropUri] = array(); + } + $newOverrides = array(); + + $labels = $override->allLiterals('rdfs:label'); //property label overrides + foreach ($labels as $label) { + $newOverrides['label'][$label->getLang()] = $label->getValue(); + } + $descriptions = $override->allLiterals('rdfs:comment'); //optionally override property label tooltips + foreach ($descriptions as $description) { + $newOverrides['description'][$description->getLang()] = $description->getValue(); + } + $this->labelOverrides[$labelPropUri] = array_merge($newOverrides, $this->labelOverrides[$labelPropUri]); + } + /** * Get the SPARQL endpoint URL for this vocabulary * @@ -505,6 +546,14 @@ public function getPluginParameters() { return $this->pluginParameters; } + /** + * Get the list of property label overrides + * @return array of custom property labels + */ + public function getPropertyLabelOverrides() { + return $this->labelOverrides; + } + /** * Returns the vocabulary default sidebar view. * @return string name of the view diff --git a/tests/VocabularyConfigTest.php b/tests/VocabularyConfigTest.php index 895c7bda8..e87440883 100644 --- a/tests/VocabularyConfigTest.php +++ b/tests/VocabularyConfigTest.php @@ -618,4 +618,22 @@ public function testGetPropertyOrderCustom() { $this->assertEquals($order, $params); } + /** + * @covers VocabularyConfig::getPropertyLabelOverrides + * @covers VocabularyConfig::setPropertyLabelOverrides + * @covers VocabularyConfig::setLabelOverride + */ + public function testGetPropertyLabelOverrides() { + $vocab = $this->model->getVocabulary('conceptPropertyLabels'); + + $overrides = $vocab->getConfig()->getPropertyLabelOverrides(); + + $expected = array( + 'skos:prefLabel' => array( 'label' => array ( 'en' => 'Caption', 'fi' => 'Luokka' ) ), + 'skos:notation' => array( 'label' => array ( 'en' => 'UDC number', 'fi' => 'UDC-numero', 'sv' => 'UDC-nummer' ), + 'description' => array( 'en' => 'Class Number') ), + ); + $this->assertEquals($expected, $overrides); + } + } diff --git a/tests/testconfig.ttl b/tests/testconfig.ttl index ddc8b8ad6..923f404ec 100644 --- a/tests/testconfig.ttl +++ b/tests/testconfig.ttl @@ -298,6 +298,22 @@ skosmos:language "fi"; skosmos:sparqlGraph . +:conceptPropertyLabels a skosmos:Vocabulary, void:Dataset ; + dc:title "Test custom property labels"@en ; + dc:subject :cat_science ; + dc:type mdrtype:ONTOLOGY ; + void:dataDump ; + void:uriSpace "http://www.skosmos.skos/test/"; + skosmos:defaultLanguage "en"; + skosmos:language "en"; + skosmos:propertyLabelOverride + [ skosmos:property skos:prefLabel ; + rdfs:label "Caption"@en, "Luokka"@fi ], + [ skosmos:property skos:notation ; + rdfs:label "UDC number"@en, "UDC-numero"@fi, "UDC-nummer"@sv ; + rdfs:comment "Class Number"@en ] ; + skosmos:sparqlGraph . + :cbd a skosmos:Vocabulary, void:Dataset ; dc11:title "A vocabulary for testing blank node processing and reification"@en ; dc:subject :cat_general ; diff --git a/view/concept-shared.twig b/view/concept-shared.twig index 7670c41ff..36d1d69ec 100644 --- a/view/concept-shared.twig +++ b/view/concept-shared.twig @@ -42,7 +42,16 @@ {% spaceless %}
-

{% set subPrefLabelTranslation = concept.preferredSubpropertyLabelTranslation(request.lang) %}{% if subPrefLabelTranslation %}{{ subPrefLabelTranslation }}{% else %}{{ 'skos:prefLabel'|trans }}{% endif %}

+

+ {% set subPrefLabelTranslation = concept.preferredSubpropertyLabelTranslation(request.lang) %} + {% if subPrefLabelTranslation %} + {{ subPrefLabelTranslation }} + {% elseif custom_labels['skos:prefLabel']['label'][request.lang] %} + {{ custom_labels['skos:prefLabel']['label'][request.lang] }} + {% else %} + {{ 'skos:prefLabel'|trans }} + {% endif %} +

{% if concept.foundBy %} {# hit has been found through an alternative label #} {{ concept.foundBy }} > @@ -90,7 +99,16 @@ {% if property.getSubPropertyOf != 'skos:hiddenLabel' %}
-

{{ property.label }}

+

+ {% if custom_labels[property.type]['label'][request.lang] %} + {{ custom_labels[property.type]['label'][request.lang] }} + {% else %} + {{ property.label }} + {% endif %} +

{% if request.vocab.config.hasMultiLingualProperty(property.type) %}