public function name($output = 'native')
{
if (!empty($this->names[$output])) {
return (string) $this->names[$output];
}
if (!empty($this->names["{$output}_name"])) {
return (string) $this->names["{$output}_name"];
}
if (in_array($output, ['language_short', 'lang'], true)) {
return strtok($this->names['http_name'], '-');
}
if ('language_long' === $output) {
return (string) $this->names['http_name'];
}
if ('none' === $output) {
return '';
}
// Since the given output type is either empty or invalid, return the native or English language name, if set.
foreach (['native_name', 'english_name'] as $key) {
if (!empty($this->names[$key])) {
return (string) $this->names[$key];
}
}
return '';
}