Skip to content

Commit

Permalink
Fix locale is not displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Oct 19, 2024
1 parent 43ef82b commit 7ece95e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.1.3](https://github.com/userfrosting/sprinkle-admin/compare/5.1.2...5.1.3)
- [Fix] Locale is not displayed on the user page

## [5.1.2](https://github.com/userfrosting/sprinkle-admin/compare/5.1.1...5.1.2)
- Fix Unable to create a user without a group on MySQL (Fix [#1273](https://github.com/userfrosting/UserFrosting/issues/1273))

Expand Down
3 changes: 3 additions & 0 deletions app/src/Controller/User/UserPageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
use UserFrosting\I18n\Locale;
use UserFrosting\Sprinkle\Account\Authenticate\Authenticator;
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface;
use UserFrosting\Sprinkle\Account\Exceptions\ForbiddenException;
Expand Down Expand Up @@ -99,6 +100,8 @@ protected function handle(UserInterface $user): array
$locales = $this->siteLocale->getAvailableIdentifiers();
if (count($locales) <= 1) {
$fields['hidden'][] = 'locale';
} else {
$fields['locale_name'] = (new Locale($user->locale))->getRegionalName();
}

// Determine buttons to display
Expand Down
2 changes: 1 addition & 1 deletion app/templates/pages/user.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<hr>
<strong><i class="fa-solid fa-language margin-r-5"></i> {{translate("LOCALE")}}</strong>
<p class="text-muted box-profile-property">
{{locales[user.locale]}}
{{ fields.locale_name }}
</p>
{% endif %}

Expand Down
25 changes: 25 additions & 0 deletions app/tests/Controller/User/UserPageActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,29 @@ public function testPage(): void
$this->assertResponseStatus(200, $response);
$this->assertNotEmpty((string) $response->getBody());
}

public function testPageWithMultipleLocales(): void
{
/** @var User */
$user = User::factory()->create();
$this->actAsUser($user, permissions: ['uri_user']);

/** @var Config */
$config = $this->ci->get(Config::class);

// Force locale config.
$config->set('site.registration.user_defaults.locale', 'en_US');
$config->set('site.locales.available', [
'en_US' => true,
'fr_FR' => true,
]);

// Create request with method and url and fetch response
$request = $this->createRequest('GET', '/users/u/' . $user->user_name);
$response = $this->handleRequest($request);

// Assert response status & body
$this->assertResponseStatus(200, $response);
$this->assertNotEmpty((string) $response->getBody());
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@userfrosting/sprinkle-admin",
"version": "5.1.1",
"version": "5.1.3",
"description": "Admin Sprinkle for UserFrosting 5",
"funding": "https://opencollective.com/userfrosting",
"license": "MIT",
Expand Down

0 comments on commit 7ece95e

Please sign in to comment.