Skip to content

Commit

Permalink
Translate label when at least one individual label is a property label
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley committed Apr 17, 2024
1 parent 41d4597 commit 3478cfe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions application/src/Api/Adapter/AbstractResourceEntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,16 +676,29 @@ public function getSubjectValueProperties(Resource $resource, $resourceType = nu
foreach ($qb->getQuery()->getResult() as $result) {
if ($result['property_alternate_label']) {
$label = $result['property_alternate_label'];
$labelIsTranslatable = false;
$resourceTemplatePropertyId = $result['resource_template_property_id'];
} elseif ($result['resource_template_property_id']) {
$label = $result['property_label'];
$labelIsTranslatable = true;
$resourceTemplatePropertyId = $result['resource_template_property_id'];
} else {
$label = $result['property_label'];
$labelIsTranslatable = true;
$resourceTemplatePropertyId = 0;
}
$results[$result['property_id']][$label]['resource_template_property_ids'][] = $resourceTemplatePropertyId;
$results[$result['property_id']][$label]['term'] = $result['term'];
// The shared label is translatable if at least one of the individual
// labels is a property label. A shared label is not translatable if
// all the individual labels are alternate labels.
if (isset($results[$result['property_id']][$label]['label_is_translatable'])) {
if (true === $labelIsTranslatable) {
$results[$result['property_id']][$label]['label_is_translatable'] = true;
}
} else {
$results[$result['property_id']][$label]['label_is_translatable'] = $labelIsTranslatable;
}
}
// Build the properties array from grouped array.
$subjectValueProperties = [];
Expand All @@ -695,6 +708,7 @@ public function getSubjectValueProperties(Resource $resource, $resourceType = nu
'label' => $label,
'property_id' => $propertyId,
'term' => $data['term'],
'label_is_translatable' => $data['label_is_translatable'],
'compound_id' => sprintf('%s:%s-%s', $resourceType, $propertyId, implode(',', array_unique($data['resource_template_property_ids']))),
];
}
Expand Down
5 changes: 4 additions & 1 deletion application/view/common/linked-resources.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ foreach ($resourcePropertiesAll as $type => $resourceProperties) {
'options' => [sprintf('%s:', $type) => sprintf('%s: All', $labelMap[$type])],
];
foreach ($resourceProperties as $resourceProperty) {
$label = $resourceProperty['label_is_translatable']
? $this->translate($resourceProperty['label'])
: $resourceProperty['label'];
$valueOptions[$type]['options'][] = [
'value' => $resourceProperty['compound_id'],
'label' => sprintf('%s: %s', $labelMap[$type], $resourceProperty['label']),
'label' => sprintf('%s: %s', $labelMap[$type], $label),
'attributes' => [
'title' => $resourceProperty['term'],
],
Expand Down

0 comments on commit 3478cfe

Please sign in to comment.