Skip to content

Commit

Permalink
Fix translation of password requirements info
Browse files Browse the repository at this point in the history
(fix #1535)
  • Loading branch information
zerocrates committed Apr 9, 2020
1 parent 8839977 commit c1993e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 18 additions & 6 deletions application/src/Form/Element/PasswordConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Omeka\Form\Element;

use Laminas\Form\Fieldset;
use Laminas\I18n\Translator\TranslatorInterface;
use Laminas\InputFilter\InputFilterProviderInterface;

class PasswordConfirm extends Fieldset implements InputFilterProviderInterface
Expand All @@ -14,33 +15,34 @@ class PasswordConfirm extends Fieldset implements InputFilterProviderInterface
public function init()
{
$config = $this->getPasswordConfig();
$translator = $this->getTranslator();

$requirements = [];
if (isset($config['min_length']) && is_numeric($config['min_length'])) {
$requirements[] = sprintf('be a minimum of %s characters in length.', // @translate
$requirements[] = sprintf($translator->translate('be a minimum of %s characters in length.'),
$config['min_length']);
}
if (isset($config['min_lowercase']) && is_numeric($config['min_lowercase'])) {
$requirements[] = sprintf('contain at least %s lowercase characters.', // @translate
$requirements[] = sprintf($translator->translate('contain at least %s lowercase characters.'),
$config['min_lowercase']);
}
if (isset($config['min_uppercase']) && is_numeric($config['min_uppercase'])) {
$requirements[] = sprintf('contain at least %s uppercase characters.', // @translate
$requirements[] = sprintf($translator->translate('contain at least %s uppercase characters.'),
$config['min_uppercase']);
}
if (isset($config['min_number']) && is_numeric($config['min_number'])) {
$requirements[] = sprintf('contain at least %s numbers.', // @translate
$requirements[] = sprintf($translator->translate('contain at least %s numbers.'),
$config['min_number']);
}
if (isset($config['min_symbol']) && is_numeric($config['min_symbol'])
&& isset($config['symbol_list']) && is_string($config['symbol_list'])
&& strlen($config['symbol_list'])
) {
$requirements[] = sprintf('contain at least %1$s symbols: %2$s', // @translate
$requirements[] = sprintf($translator->translate('contain at least %1$s symbols: %2$s'),
$config['min_symbol'], $config['symbol_list']);
}

$requirementsHtml = 'Password must:'; // @translate
$requirementsHtml = $translator->translate('Password must:');
$requirementsHtml .= '<ul>';
foreach ($requirements as $requirement) {
$requirementsHtml .= '<li>' . $requirement . '</li>';
Expand Down Expand Up @@ -227,4 +229,14 @@ public function getPasswordConfig()
{
return $this->passwordConfig;
}

public function setTranslator(TranslatorInterface $translator)
{
$this->translator = $translator;
}

public function getTranslator()
{
return $this->translator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function __invoke(ContainerInterface $services, $requestedName, array $op
$passwordConfig = isset($config['password']) ? $config['password'] : [];
$fieldset = new PasswordConfirm;
$fieldset->setPasswordConfig($passwordConfig);
$fieldset->setTranslator($services->get('MvcTranslator'));
return $fieldset;
}
}

0 comments on commit c1993e3

Please sign in to comment.