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

Fix/translate aria label #2120

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public function __invoke(ContainerInterface $container, $name,
callable $callback, array $options = null
) {
$formSelect = $callback();
$formSelect->addTranslatableAttribute('aria-label');
$formSelect->addTranslatableAttribute('title');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title is a default translatable attribute defined in the Laminas abstract form view helper so I don't believe this line is needed

// The data-placeholder attribute is used by Chosen to display default
// field text. This will make sure that attribute is translated.
$formSelect->addTranslatableAttribute('data-placeholder');
Expand Down
2 changes: 1 addition & 1 deletion application/src/Site/BlockLayout/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function alignmentClassSelect(PhpRenderer $view, SitePageBlockRepresentat
'center', // @translate
];
$alignment = $block ? $block->dataValue('alignment', 'default') : 'default';
$selectLabel = 'Alignment'; // @translate
$select = new Select('o:block[__blockIndex__][o:data][alignment]');
$select->setValueOptions(array_combine($alignmentValues, $alignmentLabels))->setValue($alignment);
$selectLabel = 'Alignment'; // @translate
$select->setAttributes(['title' => $selectLabel, 'aria-label' => $selectLabel]);
$html = '<div class="field"><div class="field-meta">';
$html .= '<label for="o:block[__blockIndex__][o:data][alignment]">' . $selectLabel . '</label></div>';
Expand Down
2 changes: 1 addition & 1 deletion application/src/Site/BlockLayout/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function alignmentClassSelect(PhpRenderer $view,
$alignmentLabels = ['float left', 'float right', 'center'];
$alignmentValues = ['left', 'right', 'center'];
$alignment = $block ? $block->dataValue('alignment', 'left') : 'left';
$selectLabel = 'Alignment'; // @translate
$select = new Select('o:block[__blockIndex__][o:data][alignment]');
$select->setValueOptions(array_combine($alignmentValues, $alignmentLabels))->setValue($alignment);
$selectLabel = 'Alignment'; // @translate
$select->setAttributes(['title' => $selectLabel, 'aria-label' => $selectLabel]);
$html = '<div class="field"><div class="field-meta">';
$html .= '<label class="thumbnail-option" for="o:block[__blockIndex__][o:data][alignment]">' . $selectLabel . '</label></div>';
Expand Down
2 changes: 1 addition & 1 deletion application/src/View/Helper/BlockThumbnailTypeSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(SitePageBlockRepresentation $block = null)
$type = $block->dataValue('thumbnail_type');
}

$selectLabel = $view->translate('Thumbnail type');
$selectLabel = 'Thumbnail type'; // @translate
$select = new Select('o:block[__blockIndex__][o:data][thumbnail_type]');
$select->setValueOptions(array_combine($this->thumbnailTypes, $this->thumbnailTypes))->setValue($type);
$select->setAttributes(['title' => $selectLabel, 'aria-label' => $selectLabel]);
Expand Down
46 changes: 25 additions & 21 deletions application/src/View/Helper/SearchFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __invoke($partialName = null, array $query = null)
switch ($key) {
// Fulltext
case 'fulltext_search':
$filterLabel = $translate('Search full-text');
$filterLabel = $translate('Search full-text'); // @translate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$translate calls are detected by xgettext, so they don't need the @translate comment.

Generally the comment is only needed where the string literal is not used directly in a call to $translate or $this->translate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment applies to all the changes in this file, I believe

$filters[$filterLabel][] = $value;
break;

Expand All @@ -57,15 +57,15 @@ public function __invoke($partialName = null, array $query = null)
if (!is_array($value)) {
$value = [$value];
}
$filterLabel = $translate('Class'); // @translate
foreach ($value as $subValue) {
if (!is_numeric($subValue)) {
continue;
}
$filterLabel = $translate('Class');
try {
$filterValue = $translate($api->read('resource_classes', $subValue)->getContent()->label());
} catch (NotFoundException $e) {
$filterValue = $translate('Unknown class');
$filterValue = $translate('Unknown class'); // @translate
}
$filters[$filterLabel][] = $filterValue;
}
Expand Down Expand Up @@ -103,10 +103,10 @@ public function __invoke($partialName = null, array $query = null)
if ($property) {
$propertyLabel = $translate($property->label());
} else {
$propertyLabel = $translate('Unknown property');
$propertyLabel = $translate('Unknown property'); // @translate
}
} else {
$propertyLabel = $translate('[Any property]');
$propertyLabel = $translate('[Any property]'); // @translate
}
if (!isset($queryTypes[$queryType])) {
continue;
Expand All @@ -125,7 +125,7 @@ public function __invoke($partialName = null, array $query = null)
}
break;
case 'search':
$filterLabel = $translate('Search');
$filterLabel = $translate('Search'); // @translate
$filters[$filterLabel][] = $value;
break;

Expand All @@ -134,15 +134,15 @@ public function __invoke($partialName = null, array $query = null)
if (!is_array($value)) {
$value = [$value];
}
$filterLabel = $translate('Template'); // @translate
foreach ($value as $subValue) {
if (!is_numeric($subValue)) {
continue;
}
$filterLabel = $translate('Template');
try {
$filterValue = $api->read('resource_templates', $subValue)->getContent()->label();
} catch (NotFoundException $e) {
$filterValue = $translate('Unknown template');
$filterValue = $translate('Unknown template'); // @translate
}
$filters[$filterLabel][] = $filterValue;
}
Expand All @@ -153,15 +153,15 @@ public function __invoke($partialName = null, array $query = null)
if (!is_array($value)) {
$value = [$value];
}
$filterLabel = $translate('In item set'); // @translate
foreach ($value as $subValue) {
if (!is_numeric($subValue)) {
continue;
}
$filterLabel = $translate('In item set');
try {
$filterValue = $api->read('item_sets', $subValue)->getContent()->displayTitle();
} catch (NotFoundException $e) {
$filterValue = $translate('Unknown item set');
$filterValue = $translate('Unknown item set'); // @translate
}
$filters[$filterLabel][] = $filterValue;
}
Expand All @@ -171,53 +171,57 @@ public function __invoke($partialName = null, array $query = null)
if (!is_array($value)) {
$value = [$value];
}
$filterLabel = $translate('Not in item set'); // @translate
foreach ($value as $subValue) {
if (!is_numeric($subValue)) {
continue;
}
$filterLabel = $translate('Not in item set');
try {
$filterValue = $api->read('item_sets', $subValue)->getContent()->displayTitle();
} catch (NotFoundException $e) {
$filterValue = $translate('Unknown item set');
$filterValue = $translate('Unknown item set'); // @translate
}
$filters[$filterLabel][] = $filterValue;
}
break;

// Search user
case 'owner_id':
$filterLabel = $translate('User');
$filterLabel = $translate('User'); // @translate
try {
$filterValue = $api->read('users', $value)->getContent()->name();
} catch (NotFoundException $e) {
$filterValue = $translate('Unknown user');
$filterValue = $translate('Unknown user'); // @translate
}
$filters[$filterLabel][] = $filterValue;
break;

case 'site_id':
$filterLabel = $translate('Site');
$filterLabel = $translate('Site'); // @translate
try {
$filterValue = $api->read('sites', $value)->getContent()->title();
} catch (NotFoundException $e) {
$filterValue = $translate('Unknown site');
$filterValue = $translate('Unknown site'); // @translate
}
$filters[$filterLabel][] = $filterValue;
break;

case 'is_public':
$filterLabel = $translate('Visibility');
$filters[$filterLabel][] = $value ? $translate('Public') : $translate('Not public');
$filterLabel = $translate('Visibility'); // @translate
$filters[$filterLabel][] = $value
? $translate('Public') // @translate
: $translate('Not public'); // @translate
break;

case 'has_media':
$filterLabel = $translate('Media presence');
$filters[$filterLabel][] = $value ? $translate('Has media') : $translate('Has no media');
$filterLabel = $translate('Media presence'); // @translate
$filters[$filterLabel][] = $value
? $translate('Has media') // @translate
: $translate('Has no media'); // @translate
break;

case 'id':
$filterLabel = $translate('ID');
$filterLabel = $translate('ID'); // @translate
$ids = $value;
if (is_string($ids) || is_int($ids)) {
$ids = false === strpos($ids, ',') ? [$ids] : explode(',', $ids);
Expand Down
10 changes: 5 additions & 5 deletions application/view/common/advanced-search/has-media.phtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
$element = new \Laminas\Form\Element\Select('has_media');
$element->setLabel($this->translate('Search by media presence'))
$element
->setLabel('Search by media presence') // @translate
->setValueOptions([
'1' => $this->translate('Has media'),
'0' => $this->translate('Has no media'),
'1' => 'Has media', // @translate
'0' => 'Has no media', // @translate
])
->setEmptyOption($this->translate('Select media presence…'))
->setEmptyOption('Select media presence…') // @translate
->setValue($query['has_media'] ?? '')
->setAttribute('id', 'has_media');
echo $this->formRow($element);
?>
2 changes: 1 addition & 1 deletion application/view/common/advanced-search/item-sets.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if ($this->status()->isSiteRequest()) {
'attributes' => [
'value' => $itemSet['id'],
'class' => 'item-set-select',
'aria-labelledby' => 'by-item-set-label'
'aria-labelledby' => 'by-item-set-label',
],
'options' => $selectOptions,
]); ?>
Expand Down
1 change: 0 additions & 1 deletion application/view/common/advanced-search/owner.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@
]); ?>
</div>
</div>

4 changes: 2 additions & 2 deletions application/view/common/advanced-search/properties.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ if ($this->status()->isSiteRequest()) {
'name' => $stem . '[property]',
'attributes' => [
'class' => 'query-property',
'value' => isset($property['property']) ? $property['property'] : null,
'aria-label' => $translate('Property'),
'value' => $property['property'] ?? null,
'aria-label' => 'Property', // @translate
],
'options' => [
'empty_option' => '[Any Property]', // @translate
Expand Down
12 changes: 6 additions & 6 deletions application/view/common/advanced-search/sort.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ switch ($resourceType) {
$sortConfig = $this->browse()->getBrowseService()->getSortConfig($sortConfigContext, $sortConfigResourceType);

$sortBy = new Element\Select('sort_by');
$sortBy->setAttribute('aria-label', $this->translate('Sort by'));
$sortBy->setEmptyOption($this->translate('Select sort by…'));
$sortBy->setAttribute('aria-label', 'Sort by'); // @translate
$sortBy->setEmptyOption('Select sort by…'); // @translate
$sortBy->setValueOptions($sortConfig);
$sortBy->setValue((!isset($query['sort_by_default']) && isset($query['sort_by'])) ? $query['sort_by'] : '');

$sortOrder = new Element\Select('sort_order');
$sortOrder->setAttribute('aria-label', $this->translate('Sort order'));
$sortOrder->setEmptyOption($this->translate('Select sort order…'));
$sortOrder->setAttribute('aria-label', 'Sort order'); // @translate
$sortOrder->setEmptyOption('Select sort order…'); // @translate
$sortOrder->setValueOptions([
'asc' => $this->translate('Ascending'),
'desc' => $this->translate('Descending'),
'asc' => 'Ascending', // @translate
'desc' => 'Descending', // @translate
]);
$sortOrder->setValue($query['sort_order'] ?? '');
?>
Expand Down
9 changes: 4 additions & 5 deletions application/view/common/advanced-search/visibility.phtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
$element = new \Laminas\Form\Element\Select('is_public');
$element->setLabel($this->translate('Search by visibility'))
$element->setLabel('Search by visibility') // @translate
->setValueOptions([
'1' => $this->translate('Public'),
'0' => $this->translate('Not public'),
'1' => 'Public', // @translate
'0' => 'Not public', // @translate
])
->setEmptyOption($this->translate('Select visibility…'))
->setEmptyOption('Select visibility…') // @translate
->setValue($query['is_public'] ?? '')
->setAttribute('id', 'is_public');
echo $this->formRow($element);
?>