From 7f870294122d554ba5c2e05f6f48b416c5a332db Mon Sep 17 00:00:00 2001 From: "Dan Kleine (Dan Untenzu)" Date: Fri, 6 Sep 2024 14:39:58 +0200 Subject: [PATCH 1/5] [FEATURE] Translate flash message title Refs #343 --- Classes/Hooks/UsageProcessAfterFinishHook.php | 9 ++++++--- Resources/Private/Language/locallang.xlf | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Classes/Hooks/UsageProcessAfterFinishHook.php b/Classes/Hooks/UsageProcessAfterFinishHook.php index 8464acd4..53f49488 100644 --- a/Classes/Hooks/UsageProcessAfterFinishHook.php +++ b/Classes/Hooks/UsageProcessAfterFinishHook.php @@ -39,7 +39,10 @@ public function processCmdmap_afterFinish(DataHandler $dataHandler): void return; } - $label = $this->getLanguageService()->sL( + $title = $this->getLanguageService()->sL( + 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.flashmassage.title' + ); + $message = $this->getLanguageService()->sL( 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.flashmassage.limit.description' ); @@ -53,8 +56,8 @@ public function processCmdmap_afterFinish(DataHandler $dataHandler): void $flashMessage = GeneralUtility::makeInstance( FlashMessage::class, - sprintf($label, $usage->character->count, $usage->character->limit), - 'Deepl Usage', + sprintf($message, $usage->character->count, $usage->character->limit), + $title, $severity, true ); diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 4ccdeb68..843e53c0 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -180,7 +180,7 @@ Information not available - DeepL Translate + DeepL usage and quota DeepL Translate Limit %s / %s From 51834cbc9a8cde97f9b19016ba7281830d24783a Mon Sep 17 00:00:00 2001 From: "Dan Kleine (Dan Untenzu)" Date: Fri, 6 Sep 2024 14:45:04 +0200 Subject: [PATCH 2/5] [FEATURE] Make translation limits more readable --- Classes/Hooks/UsageProcessAfterFinishHook.php | 7 ++++++- Resources/Private/Language/de.locallang.xlf | 8 ++++++++ Resources/Private/Language/locallang.xlf | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Classes/Hooks/UsageProcessAfterFinishHook.php b/Classes/Hooks/UsageProcessAfterFinishHook.php index 53f49488..b9a6ebba 100644 --- a/Classes/Hooks/UsageProcessAfterFinishHook.php +++ b/Classes/Hooks/UsageProcessAfterFinishHook.php @@ -56,7 +56,7 @@ public function processCmdmap_afterFinish(DataHandler $dataHandler): void $flashMessage = GeneralUtility::makeInstance( FlashMessage::class, - sprintf($message, $usage->character->count, $usage->character->limit), + sprintf($message, $this->formatNumber($usage->character->count), $this->formatNumber($usage->character->limit)), $title, $severity, true @@ -69,4 +69,9 @@ private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } + + private function formatNumber(int $number): string + { + return number_format($number, 0, ',', '.'); + } } diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 476ba437..748b9322 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -206,6 +206,14 @@ Information not available Information nicht verfügbar + + DeepL usage and quota + DeepL Nutzung und Limits + + + DeepL translations for current billing period: %s of %s characters + DeepL Übersetzungen für den aktuellen Abrechnungszeitraum: %s von %s Zeichen + diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 843e53c0..08cb7e37 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -183,7 +183,7 @@ DeepL usage and quota - DeepL Translate Limit %s / %s + DeepL translations for current billing period: %s of %s characters From d550fa05659613d27b6d85b3db2010e0919afe53 Mon Sep 17 00:00:00 2001 From: "Dan Kleine (Dan Untenzu)" Date: Fri, 6 Sep 2024 17:34:42 +0200 Subject: [PATCH 3/5] [FEATURE] Follow up: More readable quota in toolbar --- .../Listener/UsageToolBarEventListener.php | 27 ++++++++++++++----- Resources/Private/Language/de.locallang.xlf | 6 ++++- Resources/Private/Language/locallang.xlf | 5 +++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Classes/Event/Listener/UsageToolBarEventListener.php b/Classes/Event/Listener/UsageToolBarEventListener.php index 74c0104d..73cf4853 100644 --- a/Classes/Event/Listener/UsageToolBarEventListener.php +++ b/Classes/Event/Listener/UsageToolBarEventListener.php @@ -40,13 +40,17 @@ public function __invoke(SystemInformationToolbarCollectorEvent $systemInformati } return; } + + $title = $this->getLanguageService()->sL( + 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.toolbar-label' + ); + $message = $this->getLanguageService()->sL( + 'LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.toolbar.message' + ); + $systemInformation->getToolbarItem()->addSystemInformation( - $this->getLanguageService()->sL('LLL:EXT:wv_deepltranslate/Resources/Private/Language/locallang.xlf:usages.toolbar-label'), - sprintf( - '%d / %d', - $usage->character->count, - $usage->character->limit - ), + $title, + sprintf($message, $this->formatNumber($usage->character->count), $this->formatNumber($usage->character->limit)), 'actions-localize-deepl', ); } @@ -55,4 +59,15 @@ private function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } + + /** + * Make large API limits easier to read + * + * @param int $number Any large integer - 5000000 + * @return string Formated, better readable string variant of the integer - 5.000.000 + */ + private function formatNumber(int $number): string + { + return number_format($number, 0, ',', '.'); + } } diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 748b9322..929e8dbb 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -199,9 +199,13 @@ - DeepL Translate Limit + DeepL Translate Quota DeepL Übersetzung Limit + + %s / %s + %s / %s + Information not available Information nicht verfügbar diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 08cb7e37..a485b81a 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -174,7 +174,10 @@ - DeepL Translate Limit + DeepL Translate Quota + + + %s / %s Information not available From 6b388c7899e63e83919aa02a9a2dbd9e5025a120 Mon Sep 17 00:00:00 2001 From: "Dan Kleine (Dan Untenzu)" Date: Fri, 6 Sep 2024 21:29:51 +0200 Subject: [PATCH 4/5] [FEATURE] Replace severity numbers with constants --- Classes/Event/Listener/UsageToolBarEventListener.php | 2 ++ Classes/Hooks/UsageProcessAfterFinishHook.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Classes/Event/Listener/UsageToolBarEventListener.php b/Classes/Event/Listener/UsageToolBarEventListener.php index 73cf4853..0fda7c7f 100644 --- a/Classes/Event/Listener/UsageToolBarEventListener.php +++ b/Classes/Event/Listener/UsageToolBarEventListener.php @@ -7,6 +7,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent; +use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus; use TYPO3\CMS\Core\Localization\LanguageService; use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException; use WebVision\WvDeepltranslate\Service\UsageService; @@ -52,6 +53,7 @@ public function __invoke(SystemInformationToolbarCollectorEvent $systemInformati $title, sprintf($message, $this->formatNumber($usage->character->count), $this->formatNumber($usage->character->limit)), 'actions-localize-deepl', + InformationStatus::STATUS_NOTICE, ); } diff --git a/Classes/Hooks/UsageProcessAfterFinishHook.php b/Classes/Hooks/UsageProcessAfterFinishHook.php index b9a6ebba..c6071a7c 100644 --- a/Classes/Hooks/UsageProcessAfterFinishHook.php +++ b/Classes/Hooks/UsageProcessAfterFinishHook.php @@ -49,9 +49,9 @@ public function processCmdmap_afterFinish(DataHandler $dataHandler): void $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class); $notificationQueue = $flashMessageService->getMessageQueueByIdentifier(); - $severity = -1; // Info + $severity = FlashMessage::INFO; if ($this->usageService->isTranslateLimitExceeded()) { - $severity = 1; // Warning + $severity = FlashMessage::WARNING; } $flashMessage = GeneralUtility::makeInstance( From 4bd22c29c78061636cfced35583dec76613495ec Mon Sep 17 00:00:00 2001 From: "Dan Kleine (Dan Untenzu)" Date: Fri, 6 Sep 2024 21:32:27 +0200 Subject: [PATCH 5/5] [FEATURE] Enable color changes for DeepL action icon Action icons dont have a fixed color set, in order to let TYPO3 set the desired color - black in list actions, white in toolbar infos. Change the DeepL SVG to not use black in all places. --- .../Public/Icons/actions-localize-deepl.svg | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Resources/Public/Icons/actions-localize-deepl.svg b/Resources/Public/Icons/actions-localize-deepl.svg index 92dd89f6..269c69c1 100644 --- a/Resources/Public/Icons/actions-localize-deepl.svg +++ b/Resources/Public/Icons/actions-localize-deepl.svg @@ -1,18 +1,9 @@ - - - - - - - + + - - +