From b09e8a5ef25e414b4fa40ae5c2ee6f60adf3dd4e Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Mon, 3 Jul 2023 00:52:14 +0200 Subject: [PATCH] Fix lang on Top --- lib/Controller/TopController.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Controller/TopController.php b/lib/Controller/TopController.php index c0e681f..e5dc542 100644 --- a/lib/Controller/TopController.php +++ b/lib/Controller/TopController.php @@ -11,15 +11,18 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; use OCP\Http\Client\IClientService; use OCP\IRequest; +use OCP\IUserSession; +use OCP\L10N\IFactory; class TopController extends Controller { - private IClientService $clientService; - - public function __construct(IRequest $request, IClientService $clientService) { + public function __construct( + IRequest $request, + private IClientService $clientService, + private IFactory $l10nFactory, + private IUserSession $userSession + ) { parent::__construct(Application::APP_ID, $request); - - $this->clientService = $clientService; } /** @@ -32,8 +35,13 @@ class TopController extends Controller } try { + $lang = $this->l10nFactory->getUserLanguage($this->userSession->getUser()); + $lang = explode('_', $lang); + $lang = count($lang) > 1 ? $lang[1] : $lang[0]; + $lang = $lang === 'en' ? 'us' : $lang; + $client = $this->clientService->newClient(); - $response = $client->get("https://rss.applemarketingtools.com/api/v2/fr/podcasts/top/{$limit}/podcasts.json"); + $response = $client->get("https://rss.applemarketingtools.com/api/v2/{$lang}/podcasts/top/{$limit}/podcasts.json"); /** @var array $json */ $json = json_decode((string) $response->getBody(), flags: JSON_THROW_ON_ERROR); return new JSONResponse($json, $response->getStatusCode());