8000 Added PoEditor Provider · symfony/symfony@4952323 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4952323

Browse files
committed
Added PoEditor Provider
1 parent dc9648a commit 4952323

File tree

16 files changed

+948
-39
lines changed

16 files changed

+948
-39
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
use Symfony\Component\String\LazyString;
171171
use Symfony\Component\String\Slugger\SluggerInterface;
172172
use Symfony\Component\Translation\Bridge\Loco\LocoProviderFactory;
173+
use Symfony\Component\Translation\Bridge\PoEditor\PoEditorProviderFactory;
173174
use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand;
174175
use Symfony\Component\Translation\PseudoLocalizationTranslator;
175176
use Symfony\Component\Translation\Translator;
@@ -1355,14 +1356,17 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
13551356

13561357
$classToServices = [
13571358
LocoProviderFactory::class => 'translation.provider_factory.loco',
1359+
PoEditorProviderFactory::class => 'translation.provider_factory.poeditor',
13581360
];
13591361

13601362
$parentPackages = ['symfony/framework-bundle', 'symfony/translation', 'symfony/http-client'];
13611363

13621364
foreach ($classToServices as $class => $service) {
1363-
$package = sprintf('symfony/%s-translation-provider', substr($service, \strlen('translation.provider_factory.')));
1365+
switch ($package = substr($service, \strlen('translation.provider_factory.'))) {
1366+
case 'poeditor': $package = 'po-editor'; break;
1367+
}
13641368

1365-
if (!$container->hasDefinition('http_client') || !ContainerBuilder::willBeAvailable($package, $class, $parentPackages)) {
1369+
if (!$container->hasDefinition('http_client') || !ContainerBuilder::willBeAvailable(sprintf('symfony/%s-translation-provider', $package), $class, $parentPackages)) {
13661370
$container->removeDefinition($service);
13671371
}
13681372
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/translation_providers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

1414
use Symfony\Component\Translation\Bridge\Loco\LocoProviderFactory;
15+
use Symfony\Component\Translation\Bridge\PoEditor\PoEditorProviderFactory;
1516
use Symfony\Component\Translation\Provider\NullProviderFactory;
1617
use Symfony\Component\Translation\Provider\TranslationProviderCollection;
1718
use Symfony\Component\Translation\Provider\TranslationProviderCollectionFactory;
@@ -41,5 +42,14 @@
4142
service('translation.loader.xliff'),
4243
])
4344
->tag('translation.provider_factory')
45+
46+
->set('translation.provider_factory.poeditor', PoEditorProviderFactory::class)
47+
->args([
48+
service('http_client'),
49+
service('logger'),
50+
param('kernel.default_locale'),
51+
service('translation.loader.xliff'),
52+
])
53+
->tag('translation.provider_factory')
4454
;
4555
};

src/Symfony/Component/Translation/Bridge/Loco/Tests/LocoProviderTest.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@ public function createProvider(HttpClientInterface $client, LoaderInterface $loa
2222
return new LocoProvider($client, $loader, $logger, $defaultLocale, $endpoint);
2323
}
2424

25+
public function toStringProvider(): iterable
26+
{
27+
yield [
28+
new LocoProvider($this->getClient()->withOptions([
29+
'base_uri' => 'https://localise.biz/api/',
30+
'headers' => [
31+
'Authorization' => 'Loco API_KEY',
32+
],
33+
]), $this->getLoader(), $this->getLogger(), $this->getDefaultLocale(), 'localise.biz/api/'),
34+
'loco://localise.biz/api/',
35+
];
36+
37+
yield [
38+
new LocoProvider($this->getClient()->withOptions([
39+
'base_uri' => 'https://example.com',
40+
'headers' => [
41+
'Authorization' => 'Loco API_KEY',
42+
],
43+
]), $this->getLoader(), $this->getLogger(), $this->getDefaultLocale(), 'example.com'),
44+
'loco://example.com',
45+
];
46+
47+
yield [
48+
new LocoProvider($this->getClient()->withOptions([
49+
'base_uri' => 'https://example.com:99',
50+
'headers' => [
51+
'Authorization' => 'Loco API_KEY',
52+
],
53+
]), $this->getLoader(), $this->getLogger(), $this->getDefaultLocale(), 'example.com:99'),
54+
'loco://example.com:99',
55+
];
56+
}
57+
2558
public function testCompleteWriteProcess()
2659
{
2760
$createAssetResponse = $this->createMock(ResponseInterface::class);
@@ -234,7 +267,7 @@ public function testCompleteWriteProcess()
234267
}
235268

236269
/**
237-
* @dataProvider getLocoResponsesForOneLocaleAndOneDomain
270+
* @dataProvider getResponsesForOneLocaleAndOneDomain
238271
*/
239272
public function testReadForOneLocaleAndOneDomain(string $locale, string $domain, string $responseContent, TranslatorBag $expectedTranslatorBag)
240273
{
@@ -263,7 +296,7 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
263296
}
264297

265298
/**
266-
* @dataProvider getLocoResponsesForManyLocalesAndManyDomains
299+
* @dataProvider getResponsesForManyLocalesAndManyDomains
267300
*/
268301
public function testReadForManyLocalesAndManyDomains(array $locales, array $domains, array $responseContents, array $expectedTranslatorBags)
269302
{
@@ -292,40 +325,7 @@ public function testReadForManyLocalesAndManyDomains(array $locales, array $doma
292325
}
293326
}
294327

295-
public function toStringProvider(): iterable
296-
{
297-
yield [
298-
new LocoProvider($this->getClient()->withOptions([
299-
'base_uri' => 'https://localise.biz/api/',
300-
'headers' => [
301-
'Authorization' => 'Loco API_KEY',
302-
],
303-
]), $this->getLoader(), $this->getLogger(), $this->getDefaultLocale(), 'localise.biz/api/'),
304-
'loco://localise.biz/api/',
305-
];
306-
307-
yield [
308-
new LocoProvider($this->getClient()->withOptions([
309-
'base_uri' => 'https://example.com',
310-
'headers' => [
311-
'Authorization' => 'Loco API_KEY',
312-
],
313-
]), $this->getLoader(), $this->getLogger(), $this->getDefaultLocale(), 'example.com'),
314-
'loco://example.com',
315-
];
316-
317-
yield [
318-
new LocoProvider($this->getClient()->withOptions([
319-
'base_uri' => 'https://example.com:99',
320-
'headers' => [
321-
'Authorization' => 'Loco API_KEY',
322-
],
323-
]), $this->getLoader(), $this->getLogger(), $this->getDefaultLocale(), 'example.com:99'),
324-
'loco://example.com:99',
325-
];
326-
}
327-
328-
public function getLocoResponsesForOneLocaleAndOneDomain(): \Generator
328+
public function getResponsesForOneLocaleAndOneDomain(): \Generator
329329
{
330330
$arrayLoader = new ArrayLoader();
331331

@@ -390,7 +390,7 @@ public function getLocoResponsesForOneLocaleAndOneDomain(): \Generator
390390
];
391391
}
392392

393-
public function getLocoResponsesForManyLocalesAndManyDomains(): \Generator
393+
public function getResponsesForManyLocalesAndManyDomains(): \Generator
394394
{
395395
$arrayLoader = new ArrayLoader();
396396

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
5.3
5+
---
6+
7+
* Create the bridge
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

0 commit comments

Comments
 (0)
0