| @@ 44-57 (lines=14) @@ | ||
| 41 | $lang = $this->clang; |
|
| 42 | } |
|
| 43 | if ($this->vocab->getConfig()->getLanguageOrder($lang)) { |
|
| 44 | foreach ($this->vocab->getConfig()->getLanguageOrder($lang) as $fallback) { |
|
| 45 | if ($this->resource->label($fallback) !== null) { |
|
| 46 | return $this->resource->label($fallback); |
|
| 47 | } |
|
| 48 | // We need to check all the labels in case one of them matches a subtag of the current language |
|
| 49 | if ($this->resource->allLiterals('skos:prefLabel')) { |
|
| 50 | foreach($this->resource->allLiterals('skos:prefLabel') as $label) { |
|
| 51 | // the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language |
|
| 52 | if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) { |
|
| 53 | return EasyRdf\Literal::create($label, $fallback); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | } |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||
| 60 | if ($this->resource->label($lang) !== null) { // current language |
|
| @@ 135-146 (lines=12) @@ | ||
| 132 | */ |
|
| 133 | public function getLabel() |
|
| 134 | { |
|
| 135 | foreach ($this->vocab->getConfig()->getLanguageOrder($this->clang) as $fallback) { |
|
| 136 | if ($this->resource->label($fallback) !== null) { |
|
| 137 | return $this->resource->label($fallback); |
|
| 138 | } |
|
| 139 | // We need to check all the labels in case one of them matches a subtag of the current language |
|
| 140 | foreach($this->resource->allLiterals('skos:prefLabel') as $label) { |
|
| 141 | // the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language |
|
| 142 | if ($label !== null && strpos($label->getLang(), $fallback . '-') === 0) { |
|
| 143 | return EasyRdf\Literal::create($label, $fallback); |
|
| 144 | } |
|
| 145 | } |
|
| 146 | } |
|
| 147 | ||
| 148 | // Last resort: label in any language, including literal with empty language tag |
|
| 149 | $label = $this->resource->label(); |
|