mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10491 from creative-commoners/pulls/5/symfony6-translation-2
API Update translation to use symfony 6
This commit is contained in:
commit
a6a07a7ef2
@ -33,7 +33,7 @@ SilverStripe\Core\Injector\Injector:
|
|||||||
constructor:
|
constructor:
|
||||||
0: [ '%$Symfony\Component\Config\Resource\SelfCheckingResourceChecker' ]
|
0: [ '%$Symfony\Component\Config\Resource\SelfCheckingResourceChecker' ]
|
||||||
# Create default translator with standard cache path and our custom loader
|
# Create default translator with standard cache path and our custom loader
|
||||||
Symfony\Component\Translation\TranslatorInterface:
|
Symfony\Contracts\Translation\TranslatorInterface:
|
||||||
class: Symfony\Component\Translation\Translator
|
class: Symfony\Component\Translation\Translator
|
||||||
constructor:
|
constructor:
|
||||||
0: 'en'
|
0: 'en'
|
||||||
@ -48,7 +48,7 @@ SilverStripe\Core\Injector\Injector:
|
|||||||
SilverStripe\i18n\Messages\MessageProvider:
|
SilverStripe\i18n\Messages\MessageProvider:
|
||||||
class: SilverStripe\i18n\Messages\Symfony\SymfonyMessageProvider
|
class: SilverStripe\i18n\Messages\Symfony\SymfonyMessageProvider
|
||||||
properties:
|
properties:
|
||||||
Translator: '%$Symfony\Component\Translation\TranslatorInterface'
|
Translator: '%$Symfony\Contracts\Translation\TranslatorInterface'
|
||||||
---
|
---
|
||||||
Name: textcollector
|
Name: textcollector
|
||||||
---
|
---
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
"symfony/cache": "^6.1",
|
"symfony/cache": "^6.1",
|
||||||
"symfony/config": "^6.1",
|
"symfony/config": "^6.1",
|
||||||
"symfony/filesystem": "^6.1",
|
"symfony/filesystem": "^6.1",
|
||||||
"symfony/translation": "^4.4.44",
|
"symfony/translation": "^6.1",
|
||||||
"symfony/yaml": "^6.1",
|
"symfony/yaml": "^6.1",
|
||||||
"ext-ctype": "*",
|
"ext-ctype": "*",
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
|
@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
namespace SilverStripe\i18n\Messages\Symfony;
|
namespace SilverStripe\i18n\Messages\Symfony;
|
||||||
|
|
||||||
use SilverStripe\Core\Config\Configurable;
|
|
||||||
use SilverStripe\Dev\Debug;
|
|
||||||
use SilverStripe\i18n\i18n;
|
use SilverStripe\i18n\i18n;
|
||||||
use SilverStripe\i18n\Messages\Reader;
|
use SilverStripe\i18n\Messages\Reader;
|
||||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||||
use Symfony\Component\Translation\PluralizationRules;
|
use Symfony\Component\Translation\MessageCatalogue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads yaml localisations across all modules simultaneously.
|
* Loads yaml localisations across all modules simultaneously.
|
||||||
@ -23,7 +21,7 @@ class ModuleYamlLoader extends ArrayLoader
|
|||||||
*/
|
*/
|
||||||
protected $reader = null;
|
protected $reader = null;
|
||||||
|
|
||||||
public function load($resource, $locale, $domain = 'messages')
|
public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue
|
||||||
{
|
{
|
||||||
$messages = [];
|
$messages = [];
|
||||||
foreach ($resource as $path) {
|
foreach ($resource as $path) {
|
||||||
|
@ -115,17 +115,15 @@ class SymfonyMessageProvider implements MessageProvider
|
|||||||
$this->load($locale);
|
$this->load($locale);
|
||||||
|
|
||||||
// Prepare arguments
|
// Prepare arguments
|
||||||
$arguments = $this->templateInjection(array_merge(
|
$arguments = $this->templateInjection($injection);
|
||||||
$injection,
|
$arguments['%count%'] = $count;
|
||||||
[ 'count' => $count ]
|
|
||||||
));
|
|
||||||
|
|
||||||
// Pass to symfony translator
|
// 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
|
// Manually inject default if no translation found
|
||||||
if ($entity === $result) {
|
if ($entity === $result) {
|
||||||
$result = $this->getTranslator()->transChoice($default, $count, $arguments, 'messages', $locale);
|
$result = $this->getTranslator()->trans($default, $arguments, 'messages', $locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
Loading…
Reference in New Issue
Block a user