TranslationProviderCollection example

parent::tearDown();
    }

    protected function getProviderCollection(ProviderInterface $provider, array $providerNames = ['loco'], array $locales = ['en'], array $domains = ['messages']): TranslationProviderCollection
    {
        $collection = [];

        foreach ($providerNames as $providerName) {
            $collection[$providerName] = new FilteringProvider($provider$locales$domains);
        }

        return new TranslationProviderCollection($collection);
    }

    protected function createYamlFile(array $messages = ['node' => 'NOTE']$targetLanguage = 'en', $fileNamePattern = 'messages.%locale%.yml'): string
    {
        $yamlContent = '';
        foreach ($messages as $key => $value) {
            $yamlContent .= "$key: $value\n";
        }
        $yamlContent .= "\n";

        $filename = sprintf('%s/%s', $this->translationAppDir.'/translations', str_replace('%locale%', $targetLanguage$fileNamePattern));
        
public function fromConfig(array $config): TranslationProviderCollection
    {
        $providers = [];
        foreach ($config as $name => $currentConfig) {
            $providers[$name] = $this->fromDsnObject(
                new Dsn($currentConfig['dsn']),
                !$currentConfig['locales'] ? $this->enabledLocales : $currentConfig['locales'],
                !$currentConfig['domains'] ? [] : $currentConfig['domains']
            );
        }

        return new TranslationProviderCollection($providers);
    }

    public function fromDsnObject(Dsn $dsn, array $locales, array $domains = []): ProviderInterface
    {
        foreach ($this->factories as $factory) {
            if ($factory->supports($dsn)) {
                return new FilteringProvider($factory->create($dsn)$locales$domains);
            }
        }

        throw new UnsupportedSchemeException($dsn);
    }
->method('write')
            ->with($localTranslatorBag->diff($providerReadTranslatorBag));

        $provider->expects($this->once())
            ->method('__toString')
            ->willReturn('null://default');

        $reader = new TranslationReader();
        $reader->addLoader('xlf', new XliffFileLoader());

        $command = new TranslationPushCommand(
            new TranslationProviderCollection([
                'loco' => $provider,
            ]),
            $reader,
            [$this->translationAppDir.'/translations'],
            $locales
        );

        $application = new Application();
        $application->add($command);
        $tester = new CommandTester($application->find('translation:push'));

        
Home | Imprint | This part of the site doesn't use cookies.