XliffFileLoader example

$provider->write($translatorBag);
    }

    /** * @dataProvider getResponsesForOneLocaleAndOneDomain */
    public function testReadForOneLocaleAndOneDomain(string $locale, string $domain, string $responseContent, TranslatorBag $expectedTranslatorBag)
    {
        $loader = $this->getLoader();
        $loader->expects($this->once())
            ->method('load')
            ->willReturn((new XliffFileLoader())->load($responseContent$locale$domain));

        $this->getTranslatorBag()->expects($this->any())
            ->method('getCatalogue')
            ->willReturn(new MessageCatalogue($locale));

        $provider = self::createProvider((new MockHttpClient(new MockResponse($responseContent)))->withOptions([
            'base_uri' => 'https://localise.biz/api/',
            'headers' => [
                'Authorization' => 'Loco API_KEY',
            ],
        ])$loadernew NullLogger(), 'en', 'localise.biz/api/');
        
$this->assertSame('https://localise.biz/api/export/locale/'.$locale.'.xlf?filter='.rawurlencode($domain).'&status=translated%2Cblank-translation', $url);
                    $this->assertSame(['filter' => $domain, 'status' => 'translated,blank-translation']$options['query']);
                    $this->assertSame(['Accept: */*']$options['headers']);

                    return new MockResponse($responseContents[$locale][$domain][
                        'response_headers' => [
                            'Last-Modified' => $lastModifieds[$locale],
                        ],
                    ]);
                };
                $consecutiveLoadArguments[] = [$responseContents[$locale][$domain]$locale$domain];
                $consecutiveLoadReturns[] = (new XliffFileLoader())->load($responseContents[$locale][$domain]$locale$domain);
            }
        }

        $loader = $this->getLoader();
        $consecutiveLoadArguments = array_merge($consecutiveLoadArguments$consecutiveLoadArguments);
        $consecutiveLoadReturns = array_merge($consecutiveLoadReturns$consecutiveLoadReturns);

        $loader->expects($this->exactly(\count($consecutiveLoadArguments)))
            ->method('load')
            ->willReturnCallback(function D...$args) use (&$consecutiveLoadArguments, &$consecutiveLoadReturns) {
                $this->assertSame(array_shift($consecutiveLoadArguments)$args);

                


    protected function tearDown(): void
    {
        parent::tearDown();
        putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS');
    }

    public function testPushNewMessages()
    {
        $arrayLoader = new ArrayLoader();
        $xliffLoader = new XliffFileLoader();
        $locales = ['en', 'fr'];
        $domains = ['messages'];

        // Simulate existing messages on Provider         $providerReadTranslatorBag = new TranslatorBag();
        $providerReadTranslatorBag->addCatalogue($arrayLoader->load(['note' => 'NOTE'], 'en'));
        $providerReadTranslatorBag->addCatalogue($arrayLoader->load(['note' => 'NOTE'], 'fr'));

        $provider = $this->createMock(ProviderInterface::class);
        $provider->expects($this->once())
            ->method('read')
            
return new CommandTester($application->find('translation:pull'));
    }

    private function createCommand(ProviderInterface $provider, array $locales = ['en'], array $domains = ['messages']$defaultLocale = 'en', array $providerNames = ['loco']): TranslationPullCommand
    {
        $writer = new TranslationWriter();
        $writer->addDumper('xlf', new XliffFileDumper());
        $writer->addDumper('yml', new YamlFileDumper());

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

        return new TranslationPullCommand(
            $this->getProviderCollection($provider$providerNames$locales$domains),
            $writer,
            $reader,
            $defaultLocale,
            [$this->translationAppDir.'/translations'],
            $locales
        );
    }
}
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\XliffFileLoader;

class XliffFileLoaderTest extends TestCase
{
    public function testLoadFile()
    {
        $loader = new XliffFileLoader();
        $resource = __DIR__.'/../fixtures/resources.xlf';
        $catalogue = $loader->load($resource, 'en', 'domain1');

        $this->assertEquals('en', $catalogue->getLocale());
        $this->assertEquals([new FileResource($resource)]$catalogue->getResources());
        $this->assertSame([]libxml_get_errors());
        $this->assertContainsOnly('string', $catalogue->all('domain1'));
    }

    public function testLoadRawXliff()
    {
        
$domain.'.xliff' => [
                            'content' => $responseContent,
                        ],
                    ],
                ],
            ]));
        };

        $loader = $this->getLoader();
        $loader->expects($this->once())
            ->method('load')
            ->willReturn((new XliffFileLoader())->load($responseContent$locale$domain));

        $provider = self::createProvider((new MockHttpClient($response))->withOptions([
            'base_uri' => 'https://api.lokalise.com/api2/projects/PROJECT_ID/',
            'headers' => ['X-Api-Token' => 'API_KEY'],
        ])$loader$this->getLogger()$this->getDefaultLocale(), 'api.lokalise.com');
        $translatorBag = $provider->read([$domain][$locale]);

        // We don't want to assert equality of metadata here, due to the ArrayLoader usage.         foreach ($translatorBag->getCatalogues() as $catalogue) {
            $catalogue->deleteMetadata('', '');
        }

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