Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the short name for a vocabulary in content language #1089

Open
kouralex opened this issue Oct 28, 2020 · 1 comment
Open

Expose the short name for a vocabulary in content language #1089

kouralex opened this issue Oct 28, 2020 · 1 comment

Comments

@kouralex
Copy link
Contributor

As @osma said in #1084 (comment), short names for vocabularies can be language specific. However, it turns out the related code parts (listed below)

public function getShortName()
{
$shortname = $this->getLiteral('skosmos:shortName');
if ($shortname)
return $shortname;
// if no shortname exists fall back to the id
return $this->getId();
}

/**
* Returns a boolean value based on a literal value from the config.ttl configuration.
* @param string $property the property to query
* @param string $default default value
* @param string $lang preferred language for the literal
*/
protected function getLiteral($property, $default=null, $lang=null)
{
if (!isset($lang)) {;
$lang = $this->getEnvLang();
}
$literal = $this->getResource()->getLiteral($property, $lang);
if ($literal) {
return $literal->getValue();
}
// not found with selected language, try any language
$literal = $this->getResource()->getLiteral($property);
if ($literal)
return $literal->getValue();
return $default;
}
}

Skosmos/model/Concept.php

Lines 207 to 210 in 5a7175e

public function getShortName()
{
return $this->vocab ? $this->vocab->getShortName() : null;
}

public function getShortName() {
return $this->config->getShortName();
}

are not applicable for fetching the short name in another language than the UI language (which, I guess, is the usual use case).

However, now, if one wants to display the vocabulary short name in a plugin in the content language, it simply can not be done in a straightforward way (I know that it is possible to make parametrized plugins but it would feel a bit awkward way to convey vocabulary configuration related information via parameters to the plugin).

It could be possible to change the signature of the getShortName() method in VocabularyConfig.php so that the required information could be fetched and used directly in twig templates and exposed to JavaScript (via the normal https://github.com/NatLibFi/Skosmos/blob/master/view/scripts.twig procedure).

There is just one problem here, the current implementation of getLiteral() in BaseConfig.php limits the values returned (may be arbitrary in case of a non-existing literal language value) as default value is only returned in case no value is found for the property in question (this could be solved by following the language order of the vocabulary).

@osma do you think this is a plausible solution?

@kouralex kouralex added this to the Next Tasks milestone Oct 28, 2020
@kouralex kouralex changed the title Expose the short name for a vocabulary Expose the short name for a vocabulary in content language Oct 28, 2020
@osma
Copy link
Member

osma commented Oct 29, 2020

I agree that the short name of the vocabulary needs to be exported to the plugins, probably as a javascript variable like other similar information (vocabulary id, concept URI etc).

However, now, if one wants to display the vocabulary short name in a plugin in the content language, it simply can not be done in a straightforward way (I know that it is possible to make parametrized plugins but it would feel a bit awkward way to convey vocabulary configuration related information via parameters to the plugin).

I don't see a need for expressing the vocabulary name in the content language. For one, it may not be defined at all (consider e.g. Lexvo which has many content languages) since the vocabulary names and short names are usually defined only in the UI languages in the configuration file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants