Skip to content

Commit

Permalink
Merge branch '5.4' into 6.4
Browse files Browse the repository at this point in the history
* 5.4:
  explicitly mark nullable parameters as nullable
  fix low deps tests
  [HttpKernel] Fix datacollector caster for reference object property
  bug #51578 [Cache] always select database for persistent redis connections
  [Security] Validate that CSRF token in form login is string similar to username/password
  [validator] validated Dutch translation
  Improve dutch translations
  [Translation] Skip state=needs-translation entries only when source == target
  [HttpKernel] Ensure controllers are not lazy
  [Validator] Fill in trans-unit id 113: This URL does not contain a TLD.
  [Validator] added missing Polish translation for unit 113
  [Validator] add missing lv translation
  [HttpClient] Let curl handle transfer encoding
  [Messenger] Make Doctrine connection ignore unrelated tables on setup
  [HttpFoundation] Set content-type header in RedirectResponse
  add translations for the requireTld constraint option message
  [Serializer] Fix unexpected allowed attributes
  [FrameworkBundle] Fix registration of the bundle path to translation
  • Loading branch information
xabbuh committed Apr 12, 2024
2 parents 44eda81 + 5ef72d5 commit fc05d2d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
12 changes: 8 additions & 4 deletions Loader/XliffFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,20 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, s
continue;
}

if (isset($translation->target) && 'needs-translation' === (string) $translation->target->attributes()['state']) {
$source = (string) (isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source);

if (isset($translation->target)
&& 'needs-translation' === (string) $translation->target->attributes()['state']
&& \in_array((string) $translation->target, [$source, (string) $translation->source], true)
) {
continue;
}

$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values
$target = $this->utf8ToCharset((string) ($translation->target ?? $translation->source), $encoding);

$catalogue->set((string) $source, $target, $domain);
$catalogue->set($source, $target, $domain);

$metadata = [
'source' => (string) $translation->source,
Expand All @@ -144,7 +148,7 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, s
$metadata['id'] = (string) $attributes['id'];
}

$catalogue->setMetadata((string) $source, $metadata, $domain);
$catalogue->setMetadata($source, $metadata, $domain);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Resources/bin/translation-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ function extractLocaleFromFilePath($filePath)
function extractTranslationKeys($filePath): array
{
$translationKeys = [];
$contents = new \SimpleXMLElement(file_get_contents($filePath));
$contents = new SimpleXMLElement(file_get_contents($filePath));

foreach ($contents->file->body->{'trans-unit'} as $translationKey) {
$translationId = (string) $translationKey['id'];
$translationKey = (string) $translationKey->source;
$translationKey = (string) ($translationKey['resname'] ?? $translationKey->source);

$translationKeys[$translationId] = $translationKey;
}
Expand Down
11 changes: 10 additions & 1 deletion Tests/Loader/XliffFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ public function testLoadRawXliff()
</trans-unit>
<trans-unit id="4">
<source>test</source>
<target>with</target>
<target state="needs-translation">with</target>
<note>note</note>
</trans-unit>
<trans-unit id="5">
<source>baz</source>
<target state="needs-translation">baz</target>
</trans-unit>
<trans-unit id="6" resname="buz">
<source>baz</source>
<target state="needs-translation">buz</target>
</trans-unit>
</body>
</file>
</xliff>
Expand All @@ -65,6 +73,7 @@ public function testLoadRawXliff()
$this->assertEquals('en', $catalogue->getLocale());
$this->assertSame([], libxml_get_errors());
$this->assertContainsOnly('string', $catalogue->all('domain1'));
$this->assertSame(['foo', 'extra', 'key', 'test'], array_keys($catalogue->all('domain1')));
}

public function testLoadWithInternalErrorsEnabled()
Expand Down

0 comments on commit fc05d2d

Please sign in to comment.