Skip to content

Commit f3dcca5

Browse files
committed
Fix language format on Lokalise Provider
1 parent 48be4b3 commit f3dcca5

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ private function exportFiles(array $locales, array $domains): array
147147
'json' => [
148148
'format' => 'symfony_xliff',
149149
'original_filenames' => true,
150-
'directory_prefix' => '%LANG_ISO%',
151150
'filter_langs' => array_values($locales),
152151
'filter_filenames' => array_map([$this, 'getLokaliseFilenameFromDomain'], $domains),
153152
'export_empty_as' => 'skip',
@@ -167,7 +166,10 @@ private function exportFiles(array $locales, array $domains): array
167166
throw new ProviderException(sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
168167
}
169168

170-
return $responseContent['files'];
169+
// Lokalise returns languages with "-" separator, we need to reformat them to "_" separator.
170+
$reformattedLanguages = array_map(static fn ($language) => strtr($language, '-', '_'), array_keys($responseContent['files']));
171+
172+
return array_combine($reformattedLanguages, $responseContent['files']);
171173
}
172174

173175
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
@@ -559,7 +559,6 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
559559
$expectedBody = json_encode([
560560
'format' => 'symfony_xliff',
561561
'original_filenames' => true,
562-
'directory_prefix' => '%LANG_ISO%',
563562
'filter_langs' => [$locale],
564563
'filter_filenames' => [$domain.'.xliff'],
565564
'export_empty_as' => 'skip',
@@ -581,15 +580,10 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
581580
]));
582581
};
583582

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

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

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