kitodo / kitodo-presentation

Kitodo.Presentation is a feature-rich framework for building a METS- or IIIF-based digital library. It is part of the Kitodo Digital Library Suite.
https://kitodo.org
GNU General Public License v3.0
38 stars 45 forks source link

[BUG] Translation of structure type doesn't work #1314

Closed beatrycze-volk closed 3 weeks ago

beatrycze-volk commented 1 month ago

Description

Structure types are currently not translated. Instead of it the index name of structure is displayed. It is caused by explicit casting value of metadata from array to string. Then parseType() tries to retrieve from database the translation for the first element of array. But after cast the actual first element of array is the letter 'i' instead of the word 'issue'.

Code:

    private function parseType(int $i, array &$metadata) : void
    {
        $structure = $this->structureRepository->findOneByIndexName($metadata[$i]['type'][0]);
        if ($structure) {
            $metadata[$i]['type'][0] = $structure->getLabel();
        }
    }

Expected Behavior

Structure types should be translated and displayed translated in metadata plugin (MetadataController).

Screenshots and Examples

translate

Additional Context

Related to #1308

BFallert commented 1 month ago

To correct the error, the line $structure = $this->structureRepository->findOneByIndexName($metadata[$i]['type'][0]); must be changed to $structure = $this->structureRepository->findOneByIndexName($metadata[$i]['type']); and the line $metadata[$i]['type'][0] = $structure->getLabel(); as well, see #1316

beatrycze-volk commented 1 month ago

Actually the correction should happen in this line:

$metadata[$i][$name] = is_array($value) ? implode($this->settings['separator'], $value) : $value;

Because it is totally normal to get here array of values. It is even expected as we need to iterate over for e.g collections (it is totally ok that document belongs to many collections and then they need to be retrieved from database) or languages The implosion happens in buildMetaConfigObjectData() function which takes as argument$metadata array.

Example:

    private function parseCollections(int $i, $value, array &$metadata) : void
    {
        $j = 0;
        foreach ($value as $entry) {
            $collection = $this->collectionRepository->findOneByIndexName($entry);
            if ($collection) {
                $metadata[$i]['collection'][$j] = $collection->getLabel() ? : '';
                $j++;
            }
        }
    }

Actually this part is now also broken, I just didn't make a ticket yet for it.

BFallert commented 1 month ago

Related to [BUGFIX ] Reading of collections from database doesn't work #1318

sebastian-meyer commented 1 month ago

If I see this correctly all of this was introduced with the two-level metadata feature. So I again tag @chrizzor to please fix this.