Skip to content

Commit 9145a88

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: Fix language format on Lokalise Provider
2 parents 4011eb3 + b6adb52 commit 9145a88

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
560560
$expectedBody = json_encode([
561561
'format' => 'symfony_xliff',
562562
'original_filenames' => true,
563-
'directory_prefix' => '%LANG_ISO%',
564563
'filter_langs' => [$locale],
565564
'filter_filenames' => [$domain.'.xliff'],
566565
'export_empty_as' => 'skip',
@@ -582,15 +581,10 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
582581
]));
583582
};
584583

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

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

759+
$expectedTranslatorBagEnUS = new TranslatorBag();
760+
$expectedTranslatorBagEnUS->addCatalogue($arrayLoader->load([
761+
'index.hello' => 'Hello',
762+
'index.greetings' => 'Welcome, {firstname}!',
763+
], 'en_US'));
764+
765+
yield ['en_US', 'messages', <<<'XLIFF'
766+
<?xml version="1.0" encoding="UTF-8"?>
767+
<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">
768+
<file original="" datatype="plaintext" xml:space="preserve" source-language="en" target-language="en-US">
769+
<header>
770+
<tool tool-id="lokalise.com" tool-name="Lokalise"/>
771+
</header>
772+
<body>
773+
<trans-unit id="index.greetings" resname="index.greetings">
774+
<source>index.greetings</source>
775+
<target>Welcome, {firstname}!</target>
776+
</trans-unit>
777+
<trans-unit id="index.hello" resname="index.hello">
778+
<source>index.hello</source>
779+
<target>Hello</target>
780+
</trans-unit>
781+
</body>
782+
</file>
783+
</xliff>
784+
XLIFF
785+
,
786+
$expectedTranslatorBagEnUS,
787+
];
788+
765789
$expectedTranslatorBagFr = new TranslatorBag();
766790
$expectedTranslatorBagFr->addCatalogue($arrayLoader->load([
767791
'index.hello' => 'Bonjour',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy