8000 Merge branch '4.3' into 4.4 · symfony/symfony@0119d21 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0119d21

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Translation] Fixed case sensitivity of lint:xliff command fix type hint for salt in PasswordEncoderInterface Simplify code - catch \Throwable capture all exceptions Collect locale details earlier in the process in TranslationDataCollector fix typo in PR #31802 update italian validator translation Add missing translations [TwigBridge] suggest Translation Component when TranslationExtension is used
2 parents 061f622 + 0a9d724 commit 0119d21

File tree

10 files changed

+99
-31
lines changed

10 files changed

+99
-31
lines changed

src/Symfony/Bridge/Twig/Extension/TranslationExtension.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ public function __construct($translator = null, NodeVisitorInterface $translatio
4949
}
5050

5151
/**
52-
* @deprecated since Symfony 4.2
52+
* @return TranslatorInterface|null
5353
*/
5454
public function getTranslator()
5555
{
56-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
56+
if (null === $this->translator) {
57+
if (!interface_exists(TranslatorInterface::class)) {
58+
throw new \LogicException(sprintf('You cannot use the "%s" if the Translation Contracts are not available. Try running "composer require symfony/translation".', __CLASS__));
59+
}
60+
61+
$this->translator = new class() implements TranslatorInterface {
62+
use TranslatorTrait;
63+
};
64+
}
5765

5866
return $this->translator;
5967
}
@@ -108,31 +116,22 @@ public function trans($message, array $arguments = [], $domain = null, $locale =
108116
if (null !== $count) {
109117
$arguments['%count%'] = $count;
110118
}
111-
if (null === $this->translator) {
112-
$this->translator = new class() implements TranslatorInterface {
113-
use TranslatorTrait;
114-
};
115-
}
116119

117-
return $this->translator->trans($message, $arguments, $domain, $locale);
120+
return $this->getTranslator()->trans($message, $arguments, $domain, $locale);
118121
}
119122

120123
/**
121124
* @deprecated since Symfony 4.2, use the trans() method instead with a %count% parameter
122125
*/
123126
public function transchoice($message, $count, array $arguments = [], $domain = null, $locale = null)
124127
{
125-
if (null === $this->translator) {
126-
$this->translator = new class() implements TranslatorInterface {
127-
use TranslatorTrait;
128-
};
129-
}
128+
$translator = $this->getTranslator();
130129

131-
if ($this->translator instanceof TranslatorInterface) {
132-
return $this->translator->trans($message, array_merge(['%count%' => $count], $arguments), $domain, $locale);
130+
if ($translator instanceof TranslatorInterface) {
131+
return $translator->trans($message, array_merge(['%count%' => $count], $arguments), $domain, $locale);
133132
}
134133

135-
return $this->translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
134+
return $translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
136135
}
137136

138137
/**

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ private static function box($func)
751751

752752
return $result;
753753
} catch (\Throwable $e) {
754-
} catch (\Exception $e) {
755754
}
756755
\restore_error_handler();
757756

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ protected function initializeContainer()
494494
$fresh = true;
495495
}
496496
} catch (\Throwable $e) {
497-
} catch (\Exception $e) {
498497
} finally {
499498
error_reporting($errorLevel);
500499
}
@@ -563,7 +562,6 @@ protected function initializeContainer()
563562
try {
564563
$oldContainer = include $cache->getPath();
565564
} catch (\Throwable $e) {
566-
} catch (\Exception $e) {
567565
} finally {
568566
error_reporting($errorLevel);
569567
}

src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ protected function demergePasswordAndSalt($mergedPasswordSalt)
4848
/**
4949
* Merges a password and a salt.
5050
*
51-
* @param string $password The password to be used
52-
* @param string $salt The salt to be used
51+
* @param string $password The password to be used
52+
* @param string|null $salt The salt to be used
5353
*
5454
* @return string a merged password and salt
5555
*

src/Symfony/Component/Security/Core/Encoder/PasswordEncoderInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ interface PasswordEncoderInterface
2323
/**
2424
* Encodes the raw password.
2525
*
26-
* @param string $raw The password to encode
27-
* @param string $salt The salt
26+
* @param string $raw The password to encode
27+
* @param string|null $salt The salt
2828
*
2929
* @return string The encoded password
3030
*
@@ -36,9 +36,9 @@ public function encodePassword($raw, $salt);
3636
/**
3737
* Checks a raw password against an encoded password.
3838
*
39-
* @param string $encoded An encoded password
40-
* @param string $raw A raw password
41-
* @param string $salt The salt
39+
* @param string $encoded An encoded password
40+
* @param string $raw A raw password
41+
* @param string|null $salt The salt
4242
*
4343
* @return bool true if the password is valid, false otherwise
4444
*

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ private function validate($content, $file = null)
124124
$normalizedLocale = preg_quote(str_replace('-', '_', $targetLanguage), '/');
125125
// strict file names require translation files to be named '____.locale.xlf'
126126
// otherwise, both '____.locale.xlf' and 'locale.____.xlf' are allowed
127-
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.%s\.xlf/', $normalizedLocale) : sprintf('/^(.*\.%s\.xlf|%s\..*\.xlf)/', $normalizedLocale, $normalizedLocale);
127+
// also, the regexp matching must be case-insensitive, as defined for 'target-language' values
128+
// http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#target-language
129+
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.xlf/', $normalizedLocale) : sprintf('/^(.*\.(?i:%s)\.xlf|(?i:%s)\..*\.xlf)/', $normalizedLocale, $normalizedLocale);
128130

129131
if (0 === preg_match($expectedFilenamePattern, basename($file))) {
130132
$errors[] = [

src/Symfony/Component/Translation/DataCollector/TranslationDataCollector.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ public function lateCollect()
3636
{
3737
$messages = $this->sanitizeCollectedMessages($this->translator->getCollectedMessages());
3838

39-
$this->data = $this->computeCount($messages);
39+
$this->data += $this->computeCount($messages);
4040
$this->data['messages'] = $messages;
4141

42-
$this->data['locale'] = $this->translator->getLocale();
43-
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();
44-
4542
$this->data = $this->cloneVar($this->data);
4643
}
4744

@@ -50,6 +47,8 @@ public function lateCollect()
5047
*/
5148
public function collect(Request $request, Response $response, \Exception $exception = null)
5249
{
50+
$this->data['locale'] = $this->translator->getLocale();
51+
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();
5352
}
5453

5554
/**

src/Symfony/Component/Translation/Tests/Command/XliffLintCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ public function testLintIncorrectTargetLanguage()
9494
$this->assertContains('There is a mismatch between the language included in the file name ("messages.en.xlf") and the "es" value used in the "target-language" attribute of the file.', trim($tester->getDisplay()));
9595
}
9696

97+
public function testLintTargetLanguageIsCaseInsensitive()
98+
{
99+
$tester = $this->createCommandTester();
100+
$filename = $this->createFile('note', 'zh-cn', 'messages.zh_CN.xlf');
101+
102+
$tester->execute(['filename' => $filename], ['decorated' => false]);
103+
104+
$this->assertEquals(0, $tester->getStatusCode());
105+
$this->assertContains('[OK] All 1 XLIFF files contain valid syntax.', trim($tester->getDisplay()));
106+
}
107+
97108
/**
98109
* @expectedException \RuntimeException
99110
*/

src/Symfony/Component/Validator/Resources/translations/validators.hr.xlf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,34 @@
334334
<source>This value should be valid JSON.</source>
335335
<target>Ova vrijednost treba biti validan JSON. 1CF5 </target>
336336
</trans-unit>
337+
<trans-unit id="87">
338+
<source>This collection should contain only unique elements.</source>
339+
<target>Ova kolekcija treba sadržavati samo unikatne elemente.</target>
340+
</trans-unit>
341+
<trans-unit id="88">
342+
<source>This value should be positive.</source>
343+
<target>Ova vrijednost treba biti pozitivna.</target>
344+
</trans-unit>
345+
<trans-unit id="89">
346+
<source>This value should be either positive or zero.</source>
347+
<target>Ova vrijednost treba biti pozitivna ili jednaka nuli.</target>
348+
</trans-unit>
349+
<trans-unit id="90">
350+
<source>This value should be negative.</source>
351+
<target>Ova vrijednost treba biti negativna.</target>
352+
</trans-unit>
353+
<trans-unit id="91">
354+
<source>This value should be either negative or zero.</source>
355+
<target>Ova vrijednost treba biti negativna ili jednaka nuli.</target>
356+
</trans-unit>
357+
<trans-unit id="92">
358+
<source>This value is not a valid timezone.</source>
359+
<target>Ova vrijednost nije validna vremenska zona.</target>
360+
</trans-unit>
361+
<trans-unit id="93">
362+
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
363+
<target>Ova lozinka je procurila u nekom od sigurnosnih propusta, te je potrebno koristiti drugu lozinku.</target>
364+
</trans-unit>
337365
</body>
338366
</file>
339367
</xliff>

src/Symfony/Component/Validator/Resources/translations/validators.it.xlf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,38 @@
330330
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
331331
<target>Questo codice identificativo bancario (BIC) non è associato all'IBAN {{ iban }}.</target>
332332
</trans-unit>
333+
<trans-unit id="86">
334+
<source>This value should be valid JSON.</source>
335+
<target>Questo valore dovrebbe essere un JSON valido.</target>
336+
</trans-unit>
337+
<trans-unit id="87">
338+
<source>This collection should contain only unique elements.</source>
339+
<target>Questa collezione dovrebbe contenere solo elementi unici.</target>
340+
</trans-unit>
341+
<trans-unit id="88">
342+
<source>This value should be positive.</source>
343+
<target>Questo valore dovrebbe essere positivo.</target>
344+
</trans-unit>
345+
<trans-unit id="89">
346+
<source>This value should be either positive or zero.</source>
347+
<target>Questo valore dovrebbe essere positivo oppure zero.</target>
348+
</trans-unit>
349+
<trans-unit id="90">
350+
<source>This value should be negative.</source>
351+
<target>Questo valore dovrebbe essere negativo.</target>
352+
</trans-unit>
353+
<trans-unit id="91">
354+
<source>This value should be either negative or zero.</source>
355+
<target>Questo valore dovrebbe essere negativo oppure zero.</target>
356+
</trans-unit>
357+
<trans-unit id="92">
358+
<source>This value is not a valid timezone.</source>
359+
<target>Questo valore non è un fuso orario valido.</target>
360+
</trans-unit>
361+
<trans-unit id="93">
362+
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
363+
<target>Questa password è trapelata durante una compromissione di dati, non deve essere usata. Si prega di usare una password diversa.</target>
364+
</trans-unit>
333365
</body>
334366
</file>
335367
</xliff>

0 commit comments

Comments
 (0)
0