From 00cce87a72b991569d5ad1870ecd3a509635c5be Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 2 Sep 2022 13:05:13 +1200 Subject: [PATCH] API Update translation to use symfony 6 --- composer.json | 6 +++--- src/i18n/Messages/Symfony/FlushInvalidatedResource.php | 2 +- src/i18n/Messages/Symfony/ModuleYamlLoader.php | 3 ++- src/i18n/Messages/Symfony/SymfonyMessageProvider.php | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index c6ce92f6f0a..968d59a7885 100644 --- a/composer.json +++ b/composer.json @@ -39,10 +39,10 @@ "sminnee/callbacklist": "^0.1.1", "swiftmailer/swiftmailer": "^6.3.0", "symfony/cache": "^4.4.44", - "symfony/config": "^4.4.44", + "symfony/config": "^6.1", "symfony/filesystem": "^5.4 || ^6.0", - "symfony/translation": "^4.4.44", - "symfony/yaml": "^4.4.44", + "symfony/translation": "^6.1", + "symfony/yaml": "^6.1", "ext-ctype": "*", "ext-dom": "*", "ext-hash": "*", diff --git a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php index 95de3bb1900..0fc066f5c3a 100644 --- a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php +++ b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php @@ -27,7 +27,7 @@ public function getResource() return null; } - public function isFresh($timestamp) + public function isFresh(int $timestamp): bool { // Check mtime of canary $canary = static::canary(); diff --git a/src/i18n/Messages/Symfony/ModuleYamlLoader.php b/src/i18n/Messages/Symfony/ModuleYamlLoader.php index d7f4f3fcefa..dc04f490e8c 100644 --- a/src/i18n/Messages/Symfony/ModuleYamlLoader.php +++ b/src/i18n/Messages/Symfony/ModuleYamlLoader.php @@ -7,6 +7,7 @@ use SilverStripe\i18n\i18n; use SilverStripe\i18n\Messages\Reader; use Symfony\Component\Translation\Loader\ArrayLoader; +use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\PluralizationRules; /** @@ -23,7 +24,7 @@ class ModuleYamlLoader extends ArrayLoader */ protected $reader = null; - public function load($resource, $locale, $domain = 'messages') + public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue { $messages = []; foreach ($resource as $path) { diff --git a/src/i18n/Messages/Symfony/SymfonyMessageProvider.php b/src/i18n/Messages/Symfony/SymfonyMessageProvider.php index 696a1d030f2..fa843916ba7 100644 --- a/src/i18n/Messages/Symfony/SymfonyMessageProvider.php +++ b/src/i18n/Messages/Symfony/SymfonyMessageProvider.php @@ -121,11 +121,11 @@ public function pluralise($entity, $default, $injection, $count) )); // Pass to symfony translator - $result = $this->getTranslator()->transChoice($entity, $count, $arguments, 'messages', $locale); + $result = $this->getTranslator()->trans($entity, $arguments, 'messages', $locale); // Manually inject default if no translation found if ($entity === $result) { - $result = $this->getTranslator()->transChoice($default, $count, $arguments, 'messages', $locale); + $result = $this->getTranslator()->trans($default, $arguments, 'messages', $locale); } return $result;