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

Translated user bar in user locale (fix #2088). #2124

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
21 changes: 14 additions & 7 deletions application/src/View/Helper/UserBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class UserBar extends AbstractHelper
/**
* Render the user bar.
*
* The bar is translated in the user language if any, else the install
* language, else the site language.
*
* @param string|null $partialName Name of view script, or a view model
* @return string
*/
Expand All @@ -42,7 +45,9 @@ public function __invoke($partialName = null)
return '';
}

$links = $user ? $this->links($view, $site, $user) : [];
$locale = $view->userSetting('locale') ?: ($view->setting('locale') ?: null);

$links = $user ? $this->links($view, $site, $user, $locale) : [];

$partialName = $partialName ?: self::PARTIAL_NAME;

Expand All @@ -52,6 +57,7 @@ public function __invoke($partialName = null)
'site' => $site,
'user' => $user,
'links' => $links,
'userLocale' => $locale,
]
);
}
Expand All @@ -62,9 +68,10 @@ public function __invoke($partialName = null)
* @param RendererInterface $view
* @param SiteRepresentation $site
* @param User $user
* @param string|null $locale
* @return array
*/
protected function links(RendererInterface $view, SiteRepresentation $site, User $user)
protected function links(RendererInterface $view, SiteRepresentation $site, User $user, ?string $locale = null)
{
if (!$view->userIsAllowed('Omeka\Controller\Admin\Index', 'index')) {
return [];
Expand Down Expand Up @@ -108,7 +115,7 @@ protected function links(RendererInterface $view, SiteRepresentation $site, User
$links[] = [
'resource' => $controller,
'action' => 'browse',
'text' => $translate($mapPluralLabels[$controller]),
'text' => $translate($mapPluralLabels[$controller], null, $locale),
'url' => $url('admin/site/slug/action', ['site-slug' => $site->slug(), 'action' => 'page']),
];
try {
Expand All @@ -117,7 +124,7 @@ protected function links(RendererInterface $view, SiteRepresentation $site, User
$links[] = [
'resource' => $controller,
'action' => 'edit',
'text' => $translate('Edit'),
'text' => $translate('Edit', null, $locale),
'url' => $page->adminUrl('edit'),
];
}
Expand All @@ -140,7 +147,7 @@ protected function links(RendererInterface $view, SiteRepresentation $site, User
$links[] = [
'resource' => $controller,
'action' => 'browse',
'text' => $translate($mapPluralLabels[$controller]),
'text' => $translate($mapPluralLabels[$controller], null, $locale),
'url' => $url('admin/default', ['controller' => $controller], ['query' => ['site_id' => $site->id()]]),
];

Expand All @@ -156,14 +163,14 @@ protected function links(RendererInterface $view, SiteRepresentation $site, User
$links[] = [
'resource' => $controller,
'action' => 'show',
'text' => $translate('View'),
'text' => $translate('View', null, $locale),
'url' => $resource->adminUrl(),
];
if ($resource->userIsAllowed('edit')) {
$links[] = [
'resource' => $controller,
'action' => 'edit',
'text' => $translate('Edit'),
'text' => $translate('Edit', null, $locale),
'url' => $resource->adminUrl('edit'),
];
}
Expand Down
4 changes: 2 additions & 2 deletions application/view/common/user-bar.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ $this->headLink()->prependStylesheet('//fonts.googleapis.com/css?family=Source+C
<span class="user-id">
<?php
$url = $urlHelper('admin/id', ['controller' => 'user', 'id' => $user->getId()]);
echo sprintf($translate('Signed in as %s'), $hyperlink($user->getName(), $url));
echo sprintf($translate('Signed in as %s', null, $userLocale), $hyperlink($user->getName(), $url));
?>
</span>
<?php echo $hyperlink($translate('Logout'), $urlHelper('logout'), ['class' => 'logout']); ?>
<?php echo $hyperlink($translate('Logout', null, $userLocale), $urlHelper('logout'), ['class' => 'logout']); ?>
</div>
<?php else: ?>
<?php echo $hyperlink($translate('Log in'), $urlHelper('login'), ['class' => 'login']); ?>
Expand Down