diff --git a/model/Concept.php b/model/Concept.php index 06cb5e91c..88da9619b 100644 --- a/model/Concept.php +++ b/model/Concept.php @@ -125,7 +125,7 @@ public function getLabel() $label = $this->resource->label(); if ($label !== null) { if (!$label->getLang()) { - $label->getValue(); + return $label->getValue(); } return $label->getValue() . " (" . $label->getLang() . ")"; } diff --git a/model/ConceptPropertyValue.php b/model/ConceptPropertyValue.php index 5e1e3604c..fa529e312 100644 --- a/model/ConceptPropertyValue.php +++ b/model/ConceptPropertyValue.php @@ -40,6 +40,22 @@ public function getLabel($lang = '') if ($this->clang) { $lang = $this->clang; } + if ($this->vocab->getConfig()->getLanguageOrder($lang)) { + foreach ($this->vocab->getConfig()->getLanguageOrder($lang) as $fallback) { + if ($this->resource->label($fallback) !== null) { + return $this->resource->label($fallback); + } + // We need to check all the labels in case one of them matches a subtag of the current language + if ($this->resource->allLiterals('skos:prefLabel')) { + foreach($this->resource->allLiterals('skos:prefLabel') as $label) { + // the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language + if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) { + return EasyRdf\Literal::create($label, $fallback); + } + } + } + } + } if ($this->resource->label($lang) !== null) { // current language return $this->resource->label($lang); @@ -52,6 +68,7 @@ public function getLabel($lang = '') } elseif ($this->resource->getLiteral('rdf:value') !== null) { // any language return $this->resource->getLiteral('rdf:value'); } + // uri if no label is found $label = $this->resource->shorten() ? $this->resource->shorten() : $this->getUri(); return $label; } diff --git a/view/concept-shared.twig b/view/concept-shared.twig index 5e123dca1..a48556e88 100644 --- a/view/concept-shared.twig +++ b/view/concept-shared.twig @@ -86,7 +86,7 @@ {% if propval.notation %}{{ propval.notation }} {% endif %} {{ propval.label(request.contentLang) }} {% endif %} {% endif %} - {% if propval.lang and (propval.lang != request.lang or explicit_langcodes) %} ({{ propval.label.lang }}){% endif %} + {% if propval.label.lang and (propval.label.lang != request.lang or explicit_langcodes) %} ({{ propval.label(request.contentLang).lang }}){% endif %} {% if propval.SubMembers %}