8000 [Translation][FrameworkBundle] Adding Translation Providers by welcoMattic · Pull Request #37462 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translation][FrameworkBundle] Adding Translation Providers #37462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
POEditor Provider
  • Loading branch information
welcoMattic committed Sep 28, 2020
commit 5cc43792e82b3811c73f17b40a66ecbc610662c6
< 8000 td id="diff-1f37873a32276d9edc3138716630ba8505dcc29b12930327d45caa000b8e3c47L136" data-line-number="136" class="blob-num blob-num-context js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct(TranslationProviders $providers, TranslationWriterIn
{
$this->providers = $providers;
$this->writer = $writer;
$this->reader = $reader;
$this->defaultLocale = $defaultLocale;
$this->transPaths = $transPaths;
$this->enabledLocales = $enabledLocales;
Expand Down Expand Up @@ -102,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$providerStorage = $this->providers->get($provider = $input->getArgument('provider'));
$provider = $this->providers->get($input->getArgument('provider'));
$locales = $input->getOption('locales') ?: $this->enabledLocales;
$domains = $input->getOption('domains');
$force = $input->getOption('force');
Expand All @@ -116,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$writeOptions['xliff_version'] = $input->getOption('xliff-version');
}

$providerTranslations = $providerStorage->read($domains, $locales);
$providerTranslations = $provider->read($domains, $locales);

if ($force) {
if ($deleteObsolete) {
Expand All @@ -131,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->success(sprintf(
'Local translations are up to date with %s (for [%s] locale(s), and [%s] domain(s)).',
$provider,
$input->getArgument('provider'),
implode(', ', $locales),
implode(', ', $domains)
));
Expand Down Expand Up @@ -159,8 +160,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$io->success(sprintf(
'New provider translations from %s are written locally (for [%s] locale(s), and [%s] domain(s)).',
$provider,
'New translations from %s are written locally (for [%s] locale(s), and [%s] domain(s)).',
$input->getArgument('provider'),
implode(', ', $locales),
implode(', ', $domains)
));
Expand Down
8000
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
use Symfony\Component\Translation\TranslationProviders;

Expand All @@ -32,15 +31,13 @@ final class TranslationPushCommand extends Command
private $reader;
private $transPaths;
private $enabledLocales;
private $arrayLoader;

public function __construct(TranslationProviders $providers, TranslationReaderInterface $reader, string $defaultTransPath = null, array $transPaths = [], array $enabledLocales = [])
{
$this->providers = $providers;
$this->reader = $reader;
$this->transPaths = $transPaths;
$this->enabledLocales = $enabledLocales;
$this->arrayLoader = new ArrayLoader();

if (null !== $defaultTransPath) {
$this->transPaths[] = $defaultTransPath;
Expand Down Expand Up @@ -104,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io = new SymfonyStyle($input, $output);

$providerStorage = $this->providers->get($provider = $input->getArgument('provider'));
$provider = $this->providers->get($provider = $input->getArgument('provider'));
$domains = $input->getOption('domains');
$locales = $input->getOption('locales');
$force = $input->getOption('force');
Expand All @@ -117,16 +114,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (!$deleteObsolete && $force) {
$providerStorage->write($localTranslations);
$provider->write($localTranslations, true);

return 0;
}

$providerTranslations = $providerStorage->read($domains, $locales);
$providerTranslations = $provider->read($domains, $locales);

if ($deleteObsolete) {
$obsoleteMessages = $providerTranslations->diff($localTranslations);
$providerStorage->delete($obsoleteMessages);
$provider->delete($obsoleteMessages);

$io->success(sprintf(
'Obsolete translations on %s are deleted (for [%s] locale(s), and [%s] domain(s)).',
Expand All @@ -142,12 +139,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$translationsToWrite->addBag($localTranslations->intersect($providerTranslations));
}

$providerStorage->write($translationsToWrite);
$provider->write($translationsToWrite);

$io->success(sprintf(
'%s local translations are sent to %s (for [%s] locale(s), and [%s] domain(s)).',
$force ? 'All' : 'New',
$provider,
$input->getArgument('provider'),
implode(', ', $locales),
implode(', ', $domains)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
use Symfony\Component\Translation\Bridge\Crowdin\CrowdinProviderFactory;
use Symfony\Component\Translation\Bridge\Loco\LocoProviderFactory;
use Symfony\Component\Translation\Bridge\Phrase\PhraseProviderFactory;
use Symfony\Component\Translation\Bridge\PoEditor\PoEditorProviderFactory;
use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand;
use Symfony\Component\Translation\PseudoLocalizationTranslator;
use Symfony\Component\Translation\Translator;
Expand Down Expand Up @@ -1233,6 +1234,9 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder

$classToServices = [
LocoProviderFactory::class => 'translation.provider_factory.loco',
CrowdinProviderFactory::class => 'translation.provider_factory.crowdin',
PhraseProviderFactory::class => 'translation.provider_factory.phrase',
PoEditorProviderFactory::class => 'translation.provider_factory.poeditor',
];

foreach ($classToServices as $class => $service) {
Expand Down Expand Up @@ -1332,6 +1336,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
LocoProviderFactory::class => 'translation.provider_factory.loco',
CrowdinProviderFactory::class => 'translation.provider_factory.crowdin',
PhraseProviderFactory::class => 'translation.provider_factory.phrase',
PoEditorProviderFactory::class => 'translation.provider_factory.poeditor',
];

foreach ($classToServices as $class => $service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Symfony\Component\Translation\Extractor\ExtractorInterface;
use Symfony\Component\Translation\Extractor\PhpExtractor;
use Symfony\Component\Translation\Formatter\MessageFormatter;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Loader\CsvFileLoader;
use Symfony\Component\Translation\Loader\IcuDatFileLoader;
use Symfony\Component\Translation\Loader\IcuResFileLoader;
Expand Down Expand Up @@ -78,6 +79,9 @@
->set('translator.formatter.default', MessageFormatter::class)
->args([service('identity_translator')])

->set('translation.loader.array', ArrayLoader::class)
->tag('translation.loader', ['alias' => 'array'])

->set('translation.loader.php', PhpFileLoader::class)
->tag('translation.loader', ['alias' => 'php'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,43 @@
use Symfony\Component\Translation\Bridge\Crowdin\CrowdinProviderFactory;
use Symfony\Component\Translation\Bridge\Phrase\PhraseProviderFactory;
use Symfony\Component\Translation\Bridge\Loco\LocoProviderFactory;
use Symfony\Component\Translation\Bridge\PoEditor\PoEditorProviderFactory;
use Symfony\Component\Translation\Provider\AbstractProviderFactory;

return static function (ContainerConfigurator $container) {
$container->services()
->set('translation.provider_factory.abstract', AbstractProviderFactory::class)
->args([
service('http_client')->ignoreOnInvalid(),
service('translation.loader.xliff_raw'),
service('logger')->nullOnInvalid(),
param('kernel.default_locale'),
])
->abstract()

->set('translation.provider_factory.loco', LocoProviderFactory::class)
->args([
service('translator.data_collector')->nullOnInvalid(),
service('translation.loader.xliff_raw'),
])
->parent('translation.provider_factory.abstract')
->tag('translation.provider_factory')

->set('translation.provider_factory.crowdin', CrowdinProviderFactory::class)
->args([
service('translator.data_collector')->nullOnInvalid(),
service('translation.loader.xliff_raw'),
])
->parent('translation.provider_factory.abstract')
->tag('translation.provider_factory')

->set('translation.provider_factory.phrase', PhraseProviderFactory::class)
->args([
service('translator.data_collector')->nullOnInvalid(),
service('translation.loader.xliff_raw'),
])
->parent('translation.provider_factory.abstract')
->tag('translation.provider_factory')

->set('translation.provider_factory.poeditor', PoEditorProviderFactory::class)
->args([
service('translation.loader.array'),
])
->parent('translation.provider_factory.abstract')
->tag('translation.provider_factory')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@

namespace Symfony\Component\Translation\Bridge\Crowdin;

use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\AbstractProviderFactory;
use Symfony\Component\Translation\Provider\Dsn;
use Symfony\Component\Translation\Provider\ProviderInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class CrowdinProviderFactory extends AbstractProviderFactory
{
/** @var LoaderInterface */
private $loader;

public function __construct(HttpClientInterface $client = null, LoggerInterface $logger = null, string $defaultLocale = null, LoaderInterface $loader = null)
{
parent::__construct($client, $logger, $defaultLocale);

$this->loader = $loader;
}

/**
* @return CrowdinProvider
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@

namespace Symfony\Component\Translation\Bridge\Loco;

use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\AbstractProviderFactory;
use Symfony\Component\Translation\Provider\Dsn;
use Symfony\Component\Translation\Provider\ProviderInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class LocoProviderFactory extends AbstractProviderFactory
{
/** @var LoaderInterface */
private $loader;

public function __construct(HttpClientInterface $client = null, LoggerInterface $logger = null, string $defaultLocale = null, LoaderInterface $loader = null)
{
parent::__construct($client, $logger, $defaultLocale);

$this->loader = $loader;
}

/**
* @return LocoProvider
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@

namespace Symfony\Component\Translation\Bridge\Phrase;

use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\AbstractProviderFactory;
use Symfony\Component\Translation\Provider\Dsn;
use Symfony\Component\Translation\Provider\ProviderInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class PhraseProviderFactory extends AbstractProviderFactory
{
/** @var LoaderInterface */
private $loader;

public function __construct(HttpClientInterface $client = null, LoggerInterface $logger = null, string $defaultLocale = null, LoaderInterface $loader = null)
{
parent::__construct($client, $logger, $defaultLocale);

$this->loader = $loader;
}

/**
* @return PhraseProvider
*/
Expand Down
Loading
0