Skip to content

Commit

Permalink
using the configurable fallback languages for the concept property va…
Browse files Browse the repository at this point in the history
…lue labels as well, related to #688
  • Loading branch information
Henri Ylikotila committed Jan 22, 2018
1 parent 902e9be commit aacc68c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() . ")";
}
Expand Down
17 changes: 17 additions & 0 deletions model/ConceptPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion view/concept-shared.twig
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<a href="{{ propval.uri | link_url(propval.vocab, request.lang, 'page', request.contentLang) }}">{% if propval.notation %}<span class="versal">{{ propval.notation }} </span>{% endif %} {{ propval.label(request.contentLang) }}</a>
{% endif %}
{% endif %}
{% if propval.lang and (propval.lang != request.lang or explicit_langcodes) %}<span class="versal"> ({{ propval.label.lang }})</span>{% endif %}
{% if propval.label.lang and (propval.label.lang != request.lang or explicit_langcodes) %}<span class="versal"> ({{ propval.label(request.contentLang).lang }})</span>{% endif %}
{% if propval.SubMembers %}<div class="subvalue"> {# if property is a group concept that has sub properties #}
{% for sub_member in propval.SubMembers %}
<a class="propertyvalue" href="{{ sub_member.uri | link_url(propval.vocab,request.lang) }}">{{ sub_member.label(request.contentLang) }}</a>
Expand Down

0 comments on commit aacc68c

Please sign in to comment.