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
This commit is contained in:
Nicolas Grekas 2019-06-03 22:28:03 +02:00
commit 0119d217ca
10 changed files with 100 additions and 32 deletions

View File

@ -49,11 +49,19 @@ class TranslationExtension extends AbstractExtension
}
/**
* @deprecated since Symfony 4.2
* @return TranslatorInterface|null
*/
public function getTranslator()
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
if (null === $this->translator) {
if (!interface_exists(TranslatorInterface::class)) {
throw new \LogicException(sprintf('You cannot use the "%s" if the Translation Contracts are not available. Try running "composer require symfony/translation".', __CLASS__));
}
$this->translator = new class() implements TranslatorInterface {
use TranslatorTrait;
};
}
return $this->translator;
}
@ -108,13 +116,8 @@ class TranslationExtension extends AbstractExtension
if (null !== $count) {
$arguments['%count%'] = $count;
}
if (null === $this->translator) {
$this->translator = new class() implements TranslatorInterface {
use TranslatorTrait;
};
}
return $this->translator->trans($message, $arguments, $domain, $locale);
return $this->getTranslator()->trans($message, $arguments, $domain, $locale);
}
/**
@ -122,17 +125,13 @@ class TranslationExtension extends AbstractExtension
*/
public function transchoice($message, $count, array $arguments = [], $domain = null, $locale = null)
{
if (null === $this->translator) {
$this->translator = new class() implements TranslatorInterface {
use TranslatorTrait;
};
$translator = $this->getTranslator();
if ($translator instanceof TranslatorInterface) {
return $translator->trans($message, array_merge(['%count%' => $count], $arguments), $domain, $locale);
}
if ($this->translator instanceof TranslatorInterface) {
return $this->translator->trans($message, array_merge(['%count%' => $count], $arguments), $domain, $locale);
}
return $this->translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
return $translator->transChoice($message, $count, array_merge(['%count%' => $count], $arguments), $domain, $locale);
}
/**

View File

@ -751,7 +751,6 @@ class Filesystem
return $result;
} catch (\Throwable $e) {
} catch (\Exception $e) {
}
\restore_error_handler();

View File

@ -494,7 +494,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
$fresh = true;
}
} catch (\Throwable $e) {
} catch (\Exception $e) {
} finally {
error_reporting($errorLevel);
}
@ -563,7 +562,6 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
try {
$oldContainer = include $cache->getPath();
} catch (\Throwable $e) {
} catch (\Exception $e) {
} finally {
error_reporting($errorLevel);
}

View File

@ -48,8 +48,8 @@ abstract class BasePasswordEncoder implements PasswordEncoderInterface
/**
* Merges a password and a salt.
*
* @param string $password The password to be used
* @param string $salt The salt to be used
* @param string $password The password to be used
* @param string|null $salt The salt to be used
*
* @return string a merged password and salt
*

View File

@ -23,8 +23,8 @@ interface PasswordEncoderInterface
/**
* Encodes the raw password.
*
* @param string $raw The password to encode
* @param string $salt The salt
* @param string $raw The password to encode
* @param string|null $salt The salt
*
* @return string The encoded password
*
@ -36,9 +36,9 @@ interface PasswordEncoderInterface
/**
* Checks a raw password against an encoded password.
*
* @param string $encoded An encoded password
* @param string $raw A raw password
* @param string $salt The salt
* @param string $encoded An encoded password
* @param string $raw A raw password
* @param string|null $salt The salt
*
* @return bool true if the password is valid, false otherwise
*

View File

@ -124,7 +124,9 @@ EOF
$normalizedLocale = preg_quote(str_replace('-', '_', $targetLanguage), '/');
// strict file names require translation files to be named '____.locale.xlf'
// otherwise, both '____.locale.xlf' and 'locale.____.xlf' are allowed
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.%s\.xlf/', $normalizedLocale) : sprintf('/^(.*\.%s\.xlf|%s\..*\.xlf)/', $normalizedLocale, $normalizedLocale);
// also, the regexp matching must be case-insensitive, as defined for 'target-language' values
// http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#target-language
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.xlf/', $normalizedLocale) : sprintf('/^(.*\.(?i:%s)\.xlf|(?i:%s)\..*\.xlf)/', $normalizedLocale, $normalizedLocale);
if (0 === preg_match($expectedFilenamePattern, basename($file))) {
$errors[] = [

View File

@ -36,12 +36,9 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto
{
$messages = $this->sanitizeCollectedMessages($this->translator->getCollectedMessages());
$this->data = $this->computeCount($messages);
$this->data += $this->computeCount($messages);
$this->data['messages'] = $messages;
$this->data['locale'] = $this->translator->getLocale();
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();
$this->data = $this->cloneVar($this->data);
}
@ -50,6 +47,8 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data['locale'] = $this->translator->getLocale();
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();
}
/**

View File

@ -94,6 +94,17 @@ class XliffLintCommandTest extends TestCase
$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()));
}
public function testLintTargetLanguageIsCaseInsensitive()
{
$tester = $this->createCommandTester();
$filename = $this->createFile('note', 'zh-cn', 'messages.zh_CN.xlf');
$tester->execute(['filename' => $filename], ['decorated' => false]);
$this->assertEquals(0, $tester->getStatusCode());
$this->assertContains('[OK] All 1 XLIFF files contain valid syntax.', trim($tester->getDisplay()));
}
/**
* @expectedException \RuntimeException
*/

View File

@ -334,6 +334,34 @@
<source>This value should be valid JSON.</source>
<target>Ova vrijednost treba biti validan JSON.</target>
</trans-unit>
<trans-unit id="87">
<source>This collection should contain only unique elements.</source>
<target>Ova kolekcija treba sadržavati samo unikatne elemente.</target>
</trans-unit>
<trans-unit id="88">
<source>This value should be positive.</source>
<target>Ova vrijednost treba biti pozitivna.</target>
</trans-unit>
<trans-unit id="89">
<source>This value should be either positive or zero.</source>
<target>Ova vrijednost treba biti pozitivna ili jednaka nuli.</target>
</trans-unit>
<trans-unit id="90">
<source>This value should be negative.</source>
<target>Ova vrijednost treba biti negativna.</target>
</trans-unit>
<trans-unit id="91">
<source>This value should be either negative or zero.</source>
<target>Ova vrijednost treba biti negativna ili jednaka nuli.</target>
</trans-unit>
<trans-unit id="92">
<source>This value is not a valid timezone.</source>
<target>Ova vrijednost nije validna vremenska zona.</target>
</trans-unit>
<trans-unit id="93">
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
<target>Ova lozinka je procurila u nekom od sigurnosnih propusta, te je potrebno koristiti drugu lozinku.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -330,6 +330,38 @@
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
<target>Questo codice identificativo bancario (BIC) non è associato all'IBAN {{ iban }}.</target>
</trans-unit>
<trans-unit id="86">
<source>This value should be valid JSON.</source>
<target>Questo valore dovrebbe essere un JSON valido.</target>
</trans-unit>
<trans-unit id="87">
<source>This collection should contain only unique elements.</source>
<target>Questa collezione dovrebbe contenere solo elementi unici.</target>
</trans-unit>
<trans-unit id="88">
<source>This value should be positive.</source>
<target>Questo valore dovrebbe essere positivo.</target>
</trans-unit>
<trans-unit id="89">
<source>This value should be either positive or zero.</source>
<target>Questo valore dovrebbe essere positivo oppure zero.</target>
</trans-unit>
<trans-unit id="90">
<source>This value should be negative.</source>
<target>Questo valore dovrebbe essere negativo.</target>
</trans-unit>
<trans-unit id="91">
<source>This value should be either negative or zero.</source>
<target>Questo valore dovrebbe essere negativo oppure zero.</target>
</trans-unit>
<trans-unit id="92">
<source>This value is not a valid timezone.</source>
<target>Questo valore non è un fuso orario valido.</target>
</trans-unit>
<trans-unit id="93">
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
<target>Questa password è trapelata durante una compromissione di dati, non deve essere usata. Si prega di usare una password diversa.</target>
</trans-unit>
</body>
</file>
</xliff>