Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9a230fd

Browse filesBrowse files
committed
Init Crowdin remote storage
1 parent b443ed1 commit 9a230fd
Copy full SHA for 9a230fd

File tree

Expand file treeCollapse file tree

5 files changed

+182
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+182
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/translation_remotes.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/translation_remotes.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Symfony\Component\Translation\Bridge\Crowdin\CrowdinRemoteFactory;
1415
use Symfony\Component\Translation\Bridge\Loco\LocoRemoteFactory;
1516
use Symfony\Component\Translation\Remote\AbstractRemoteFactory;
1617

@@ -30,5 +31,12 @@
3031
])
3132
->parent('translation.remote_factory.abstract')
3233
->tag('translation.remote_factory')
34+
35+
->set('translation.remote_factory.crowdin', CrowdinRemoteFactory::class)
36+
->args([
37+
service('translator.data_collector')->nullOnInvalid(),
38+
])
39+
->parent('translation.remote_factory.abstract')
40+
->tag('translation.remote_factory')
3341
;
3442
};
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Bridge\Crowdin;
13+
14+
use Symfony\Component\HttpFoundation\Response;
15+
use Symfony\Component\Translation\Exception\TransportException;
16+
use Symfony\Component\Translation\Loader\LoaderInterface;
17+
use Symfony\Component\Translation\Remote\AbstractRemote;
18+
use Symfony\Component\Translation\TranslatorBag;
19+
use Symfony\Contracts\HttpClient\HttpClientInterface;
20+
21+
/**
22+
* @author Fabien Potencier <fabien@symfony.com>
23+
*
24+
* @experimental in 5.2
25+
* @final
26+
*
27+
* In Crowdin:
28+
*/
29+
class CrowdinRemote extends AbstractRemote
30+
{
31+
protected const HOST = 'crowdin.com/api/v2';
32+
33+
private $apiKey;
34+
private $loader;
35+
private $defaultLocale;
36+
37+
public function __construct(string $apiKey, HttpClientInterface $client = null, LoaderInterface $loader = null, string $defaultLocale = null)
38+
{
39+
$this->apiKey = $apiKey;
40+
$this->loader = $loader;
41+
$this->defaultLocale = $defaultLocale;
42+
43+
parent::__construct($client);
44+
}
45+
46+
public function __toString(): string
47+
{
48+
return sprintf('crowdin://%s', $this->getEndpoint());
49+
}
50+
51+
public function write(TranslatorBag $translations, bool $override = false): void
52+
{
53+
// TODO: Implement write() method.
54+
}
55+
56+
public function read(array $domains, array $locales): TranslatorBag
57+
{
58+
// TODO: Implement read() method.
59+
}
60+
61+
public function delete(TranslatorBag $translations): void
62+
{
63+
// TODO: Implement delete() method.
64+
}
65+
}
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Bridge\Crowdin;
13+
14+
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
15+
use Symfony\Component\Translation\Remote\AbstractRemoteFactory;
16+
use Symfony\Component\Translation\Remote\Dsn;
17+
use Symfony\Component\Translation\Remote\RemoteInterface;
18+
19+
final class CrowdinRemoteFactory extends AbstractRemoteFactory
20+
{
21+
/**
22+
* @return CrowdinRemote
23+
*/
24+
public function create(Dsn $dsn): RemoteInterface
25+
{
26+
$scheme = $dsn->getScheme();
27+
$apiKey = $this->getUser($dsn);
28+
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
29+
$port = $dsn->getPort();
30+
31+
if ('crowdin' === $scheme) {
32+
return (new CrowdinRemote($apiKey, $this->client, $this->loader, $this->defaultLocale))
33+
->setHost($host)
34+
->setPort($port)
35+
;
36+
}
37+
38+
throw new UnsupportedSchemeException($dsn, 'crowdin', $this->getSupportedSchemes());
39+
}
40+
41+
protected function getSupportedSchemes(): array
42+
{
43+
return ['crowdin'];
44+
}
45+
}
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Exception;
13+
14+
class IncompleteDsnException extends InvalidArgumentException
15+
{
16+
public function __construct(string $message, string $dsn = null, ?\Throwable $previous = null)
17+
{
18+
if ($dsn) {
19+
$message = sprintf('Invalid "%s" remote storage DSN: ', $dsn).$message;
20+
}
21+
22+
parent::__construct($message, 0, $previous);
23+
}
24+
}
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Exception;
13+
14+
use Symfony\Component\Translation\Remote\Dsn;
15+
16+
class UnsupportedSchemeException extends LogicException
17+
{
18+
private const SCHEME_TO_PACKAGE_MAP = [];
19+
20+
public function __construct(Dsn $dsn, string $name = null, array $supported = [])
21+
{
22+
$provider = $dsn->getScheme();
23+
if (false !== $pos = strpos($provider, '+')) {
24+
$provider = substr($provider, 0, $pos);
25+
}
26+
$package = self::SCHEME_TO_PACKAGE_MAP[$provider] ?? null;
27+
if ($package && !class_exists($package['class'])) {
28+
parent::__construct(sprintf('Unable to send emails via "%s" as the bridge is not installed; try running "composer require %s".', $provider, $package['package']));
29+
30+
return;
31+
}
32+
33+
$message = sprintf('The "%s" scheme is not supported', $dsn->getScheme());
34+
if ($name && $supported) {
35+
$message .= sprintf('; supported schemes for mailer "%s" are: "%s"', $name, implode('", "', $supported));
36+
}
37+
38+
parent::__construct($message.'.');
39+
}
40+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.