From 7ece95e452989ffb129c651459752de47079a6e5 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 18 Oct 2024 22:48:17 -0400 Subject: [PATCH] Fix locale is not displayed --- CHANGELOG.md | 3 +++ app/src/Controller/User/UserPageAction.php | 3 +++ app/templates/pages/user.html.twig | 2 +- .../Controller/User/UserPageActionTest.php | 25 +++++++++++++++++++ package.json | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 987413b..56c76fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/app/src/Controller/User/UserPageAction.php b/app/src/Controller/User/UserPageAction.php index 273356c..65ca023 100644 --- a/app/src/Controller/User/UserPageAction.php +++ b/app/src/Controller/User/UserPageAction.php @@ -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; @@ -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 diff --git a/app/templates/pages/user.html.twig b/app/templates/pages/user.html.twig index 67495b7..0ab921e 100644 --- a/app/templates/pages/user.html.twig +++ b/app/templates/pages/user.html.twig @@ -111,7 +111,7 @@
{{translate("LOCALE")}}

- {{locales[user.locale]}} + {{ fields.locale_name }}

{% endif %} diff --git a/app/tests/Controller/User/UserPageActionTest.php b/app/tests/Controller/User/UserPageActionTest.php index c0fab0d..59e8de4 100644 --- a/app/tests/Controller/User/UserPageActionTest.php +++ b/app/tests/Controller/User/UserPageActionTest.php @@ -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()); + } } diff --git a/package.json b/package.json index 9fffe2c..34e3738 100644 --- a/package.json +++ b/package.json @@ -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",