Skip to content

Commit

Permalink
API Update translation to use symfony 6
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 1, 2022
1 parent e6fb963 commit f8c7dbd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/i18n/Messages/Symfony/FlushInvalidatedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/Messages/Symfony/ModuleYamlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/Messages/Symfony/SymfonyMessageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f8c7dbd

Please sign in to comment.