【问题标题】:Change Language Message Password Rules [duplicate]更改语言消息密码规则 [重复]
【发布时间】:2021-09-27 18:23:24
【问题描述】:

如果密码不符合规则,我想更改消息的语言。

我使用以下代码检查密码:

'password' => ['required', 'confirmed', Password::min(12)
            ->mixedCase()
            ->letters()
            ->numbers()
            ->symbols()
            ->uncompromised()
        ],

如果密码不符合规则,我会收到一条错误消息,但为英文。我想用德语收到这个。我找到了生成消息的方法。在那里,它们是用英语静态编程的。我该如何更改?

public function passes($attribute, $value)
{
    $validator = Validator::make($this->data, [
        $attribute => 'string|min:'.$this->min,
    ]);

    if ($validator->fails()) {
        return $this->fail($validator->messages()->all());
    }

    $value = (string) $value;

    if ($this->mixedCase && ! preg_match('/(\p{Ll}+.*\p{Lu})|(\p{Lu}+.*\p{Ll})/u', $value)) {
        $this->fail('The :attribute must contain at least one uppercase and one lowercase letter.');
    }

    if ($this->letters && ! preg_match('/\pL/u', $value)) {
        $this->fail('The :attribute must contain at least one letter.');
    }

    if ($this->symbols && ! preg_match('/\p{Z}|\p{S}|\p{P}/u', $value)) {
        $this->fail('The :attribute must contain at least one symbol.');
    }

    if ($this->numbers && ! preg_match('/\pN/u', $value)) {
        $this->fail('The :attribute must contain at least one number.');
    }

    if (! empty($this->messages)) {
        return false;
    }

    if ($this->uncompromised && ! Container::getInstance()->make(UncompromisedVerifier::class)->verify([
        'value' => $value,
        'threshold' => $this->compromisedThreshold,
    ])) {
        return $this->fail(
            'The given :attribute has appeared in a data leak. Please choose a different :attribute.'
        );
    }

    return true;
}

当我尝试更改代码时,PHP-Storm 会警告我不要这样做。有人有建议吗?

【问题讨论】:

标签: php laravel translation


【解决方案1】:

只需将这些字符串作为键添加到 resources/lang/{your_language}.json 中的 js 对象中,并将您的翻译作为值,如下所示:

{
    "The :attribute must contain at least one uppercase and one lowercase letter." : "O campo :attribute deve conter pelo menos uma letra maiúscula e uma minúscula.",
    "The :attribute must contain at least one letter.": "O campo :attribute deve conter pelo menos uma letra",
    "The :attribute must contain at least one symbol." : "O campo :attribute deve conter pelo menos um caractere especial.",
    "The :attribute must contain at least one number." : "O campo :attribute deve conter pelo menos um número."    
}

【讨论】:

    猜你喜欢
    • 2014-01-14
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多