How can I translate the password reset email in Laravel 5.7?

前端 未结 4 1840
执念已碎
执念已碎 2021-01-18 23:02

I\'m trying to translate the password reset email, which is English by default, in Laravel 5.7.

Normally – for the login, registration, and password reset views – yo

相关标签:
4条回答
  • 2021-01-18 23:34

    Translations should be in json-format for this even in Laravel 6.0. The file is placed here: resources/lang/fr.json

    0 讨论(0)
  • 2021-01-18 23:42

    In the method Illuminate\Auth\Notifications\ResetPassword::toMail() you can see the Lang::getFromJson() method is used to populate the email:

    return (new MailMessage)
        ->subject(Lang::getFromJson('Reset Password Notification'))
        ->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
        ->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', $this->token, false)))
        ->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));
    

    So you should be able to add these translations to the resources/lang/xx.json file as described in the documentation (scroll down to "Using Translation Strings As Keys.")

    This also applies to the email verification message in Illuminate\Auth\Notifications\VerifyEmail.

    For example, this could be the content of resources/lang/fr.json (forgive my high school French from 25 years ago)

    {
        "If you did not request a password reset, no further action is required.": "Si vous ne demandez pas le réinitialisation de votre mot de passe, vous ne pouvez rien faire"
    }
    

    For both classes, the template file Illuminate/Notifications/resources/views/email.blade.php contains additional text that is in standard Blade @lang tags, which can be translated using message files at resources/lang/xx/messages.php

    For example, this could be the content of resources/lang/fr/messages.php:

    <?php
    return [
        "Regards" => "Félicitations",
    ];
    
    0 讨论(0)
  • 2021-01-18 23:43

    Just found out that you can also translate the @lang tags within your json file:

    {
      "Regards": "Met vriendelijke groet",
      "If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)": "Als u problemen ondervindt bij het klikken op de knop \":actionText\" kopieert en plakt u de onderstaande URL in uw webbrowser\n[:actionURL](:actionURL)",
      "All rights reserved.": "Alle rechten voorbehouden."
    }
    

    Look at the repository for all translation files:

    https://github.com/caouecs/Laravel-lang

    0 讨论(0)
  • 2021-01-18 23:51

    There is list ready to use of 75 languages translates for laravel https://github.com/Laravel-Lang/lang May be your language exists in this list.

    0 讨论(0)
提交回复
热议问题