Skip to content

Commit a5e7c8b

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: Fix language format on Lokalise Provider
2 parents 9109dc6 + 9145a88 commit a5e7c8b

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/Symfony/Component/Translation/Bridge/Lokalise/LokaliseProvider.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ private function exportFiles(array $locales, array $domains): array
145145
'json' => [
146146
'format' => 'symfony_xliff',
147147
'original_filenames' => true,
148-
'directory_prefix' => '%LANG_ISO%',
149148
'filter_langs' => array_values($locales),
150149
'filter_filenames' => array_map($this->getLokaliseFilenameFromDomain(...), $domains),
151150
'export_empty_as' => 'skip',
@@ -165,7 +164,12 @@ private function exportFiles(array $locales, array $domains): array
165164
throw new ProviderException(sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
166165
}
167166

168-
return $responseContent['files'];
167+
// Lokalise returns languages with "-" separator, we need to reformat them to "_" separator.
168+
$reformattedLanguages = array_map(function ($language) {
169+
return str_replace('-', '_', $language);
170+
}, array_keys($responseContent['files']));
171+
172+
return array_combine($reformattedLanguages, $responseContent['files']);
169173
}
170174

171175
private function createKeys(array $keys, string $domain): array

src/Symfony/Component/Translation/Bridge/Lokalise/Tests/LokaliseProviderTest.php

+31-7
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
561561
$expectedBody = json_encode([
562562
'format' => 'symfony_xliff',
563563
'original_filenames' => true,
564-
'directory_prefix' => '%LANG_ISO%',
565564
'filter_langs' => [$locale],
566565
'filter_filenames' => [$domain.'.xliff'],
567566
'export_empty_as' => 'skip',
@@ -583,15 +582,10 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
583582
]);
584583
};
585584

586-
$loader = $this->getLoader();
587-
$loader->expects($this->once())
588-
->method('load')
589-
->willReturn((new XliffFileLoader())->load($responseContent, $locale, $domain));
590-
591585
$provider = self::createProvider((new MockHttpClient($response))->withOptions([
592586
'base_uri' => 'https://api.lokalise.com/api2/projects/PROJECT_ID/',
593587
'headers' => ['X-Api-Token' => 'API_KEY'],
594-
]), $loader, $this->getLogger(), $this->getDefaultLocale(), 'api.lokalise.com');
588+
]), new XliffFileLoader(), $this->getLogger(), $this->getDefaultLocale(), 'api.lokalise.com');
595589
$translatorBag = $provider->read([$domain], [$locale]);
596590

597591
// We don't want to assert equality of metadata here, due to the ArrayLoader usage.
@@ -763,6 +757,36 @@ public static function getResponsesForOneLocaleAndOneDomain(): \Generator
763757
$expectedTranslatorBagEn,
764758
];
765759

760+
$expectedTranslatorBagEnUS = new TranslatorBag();
761+
$expectedTranslatorBagEnUS->addCatalogue($arrayLoader->load([
762+
'index.hello' => 'Hello',
763+
'index.greetings' => 'Welcome, {firstname}!',
764+
], 'en_US'));
765+
766+
yield ['en_US', 'messages', <<<'XLIFF'
767+
<?xml version="1.0" encoding="UTF-8"?>
768+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
769+
<file original="" datatype="plaintext" xml:space="preserve" source-language="en" target-language="en-US">
770+
<header>
771+
<tool tool-id="lokalise.com" tool-name="Lokalise"/>
772+
</header>
773+
<body>
774+
<trans-unit id="index.greetings" resname="index.greetings">
775+
<source>index.greetings</source>
776+
<target>Welcome, {firstname}!</target>
777+
</trans-unit>
778+
<trans-unit id="index.hello" resname="index.hello">
779+
<source>index.hello</source>
780+
<target>Hello</target>
781+
</trans-unit>
782+
</body>
783+
</file>
784+
</xliff>
785+
XLIFF
786+
,
787+
$expectedTranslatorBagEnUS,
788+
];
789+
766790
$expectedTranslatorBagFr = new TranslatorBag();
767791
$expectedTranslatorBagFr->addCatalogue($arrayLoader->load([
768792
'index.hello' => 'Bonjour',

0 commit comments

Comments
 (0)