laravelでのメール周り?の英文を日本語に直すメモ
やりたいこと
Email VerificationやPassword Resetの時のメール文や送信しました!などの英語部分を日本語にする。
環境
MacOS 10.14.3
VisualStudio
laravel 5.7
メール内容
viewsで日本語かしても下のようにまだ英語が残っているので、その部分を日本語化します。
Notificationのレイアウトを編集する
php artisan vendor:publish
と打つと、下記のようなリストが表示されます。
laravel-notifications
が書いてある番号を入力してEnter。
(上のリストだと"11")
環境によって番号は変わります。
resources/views/vendor/notifications/email.blade.phpが生成されるので編集します。
@component('mail::message')
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level === 'error')
# @lang('Whoops!')
@else
+# こんにちは
@endif
@endif
{{-- Intro Lines --}}
@foreach ($introLines as $line)
{{ $line }}
@endforeach
{{-- Action Button --}}
@isset($actionText)
<?php
switch ($level) {
case 'success':
case 'error':
$color = $level;
break;
default:
$color = 'primary';
}
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
{{ $actionText }}
@endcomponent
@endisset
{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{{ $line }}
@endforeach
{{-- Salutation --}}
@if (! empty($salutation))
{{ $salutation }}
@else
+{{ config('app.name') }}より
@endif
{{-- Subcopy --}}
@isset($actionText)
@slot('subcopy')
+もし、「{{ $actionText }}ボタン」がうまく機能しない場合、以下のURLをコピー&ペーストして直接ブラウザからアクセスしてください。
+ [{{ $actionUrl }}]({{ $actionUrl }})
@endslot
@endisset
@endcomponent
動作確認
再度、メールを送ってみて下のように日本語になっていたらOK。
Password Resetの文
config/app.php
変更箇所
- timezone:タイムゾーン
- locale:言語
- fallback_local:該当言語が見つからない場合の言語
'timezone' => 'Asia/Tokyo',
'locale' => 'ja',
'fallback_locale' => 'ja',
app.phpのデフォルト言語で指定してある"en"は、
resources/lang/enから表示をしています。
その中に、下記4つのファイルがあるかと思います。
- auth.php
- pagination.php
- password.php
- validation.php
これを日本語に編集します。
1. enファイルをコピペして"ja"にリネーム。
2. ここから日本語訳をコピーして日本語に編集
今回はパスワードリセット部分を日本語化にしたいので、password.phpだけ編集します。
<?php
return [
/*
|--------------------------------------------------------------------------
| Password Reset Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are the default lines which match reasons
| that are given by the password broker for a password update attempt
| has failed, such as for an invalid token or invalid new password.
|
*/
'password' => 'パスワードは6文字以上にして、確認用入力欄と一致させてください。',
'reset' => 'パスワードは再設定されました!',
'sent' => 'パスワード再設定用のURLをメールで送りました。',
'token' => 'パスワード再設定用のトークンが不正です。',
'user' => "メールアドレスに一致するユーザーが存在しません。",
];
動作確認
http://127.0.0.1:8000
ログイン画面のPassword Resetリンクにとんで、メールアドレスをいれて送信してみてください。
日本語になっていればOK。
おまけ
その他3つのファイルは日本語にするとこんな感じになります。
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| messages that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/
'failed' => '認証情報が記録と一致しません。',
'throttle' => 'ログイン試行が規定回数を超えました。:seconds秒後に再開できます。',
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Pagination Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used by the paginator library to build
| the simple pagination links. You are free to change them to anything
| you want to customize your views to better match your application.
|
*/
'previous' => '« 前へ',
'next' => '次へ »',
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Validation Language Lines
|--------------------------------------------------------------------------
|
| The following language lines contain the default error messages used by
| the validator class. Some of these rules have multiple versions such
| as the size rules. Feel free to tweak each of these messages here.
|
*/
'accepted' => ':attributeを承認してください。',
'active_url' => ':attributeには有効なURLを指定してください。',
'after' => ':attributeには:date以降の日付を指定してください。',
'after_or_equal' => ':attributeには:dateかそれ以降の日付を指定してください。',
'alpha' => ':attributeには英字のみからなる文字列を指定してください。',
'alpha_dash' => ':attributeには英数字・ハイフン・アンダースコアのみからなる文字列を指定してください。',
'alpha_num' => ':attributeには英数字のみからなる文字列を指定してください。',
'array' => ':attributeには配列を指定してください。',
'before' => ':attributeには:date以前の日付を指定してください。',
'before_or_equal' => ':attributeには:dateかそれ以前の日付を指定してください。',
'between' => [
'numeric' => ':attributeには:min〜:maxまでの数値を指定してください。',
'file' => ':attributeには:min〜:max KBのファイルを指定してください。',
'string' => ':attributeには:min〜:max文字の文字列を指定してください。',
'array' => ':attributeには:min〜:max個の要素を持つ配列を指定してください。',
],
'boolean' => ':attributeには真偽値を指定してください。',
'confirmed' => ':attributeが確認用の値と一致しません。',
'date' => ':attributeには正しい形式の日付を指定してください。',
'date_format' => '":format"という形式の日付を指定してください。',
'different' => ':attributeには:otherとは異なる値を指定してください。',
'digits' => ':attributeには:digits桁の数値を指定してください。',
'digits_between' => ':attributeには:min〜:max桁の数値を指定してください。',
'dimensions' => ':attributeの画像サイズが不正です。',
'distinct' => '指定された:attributeは既に存在しています。',
'email' => ':attributeには正しい形式のメールアドレスを指定してください。',
'exists' => '指定された:attributeは存在しません。',
'file' => ':attributeにはファイルを指定してください。',
'filled' => ':attributeには空でない値を指定してください。',
'gt' => [
'numeric' => ':attributeには、:valueより大きな値を指定してください。',
'file' => ':attributeには、:value kBより大きなファイルを指定してください。',
'string' => ':attributeは、:value文字より長く指定してください。',
'array' => ':attributeには、:value個より多くのアイテムを指定してください。',
],
'gte' => [
'numeric' => ':attributeには、:value以上の値を指定してください。',
'file' => ':attributeには、:value kB以上のファイルを指定してください。',
'string' => ':attributeは、:value文字以上で指定してください。',
'array' => ':attributeには、:value個以上のアイテムを指定してください。',
],
'image' => ':attributeには画像ファイルを指定してください。',
'in' => '選択された:attributeは正しくありません。',
'in_array' => ':attributeには:otherの値を指定してください。',
'integer' => ':attributeは整数で指定してください。',
'ip' => ':attributeには、有効なIPアドレスを指定してください。',
'ipv4' => ':attributeには、有効なIPv4アドレスを指定してください。',
'ipv6' => ':attributeには、有効なIPv6アドレスを指定してください。',
'json' => ':attributeには、有効なJSON文字列を指定してください。',
'lt' => [
'numeric' => ':attributeには、:valueより小さな値を指定してください。',
'file' => ':attributeには、:value kBより小さなファイルを指定してください。',
'string' => ':attributeは、:value文字より短く指定してください。',
'array' => ':attributeには、:value個より少ないアイテムを指定してください。',
],
'lte' => [
'numeric' => ':attributeには、:value以下の値を指定してください。',
'file' => ':attributeには、:value kB以下のファイルを指定してください。',
'string' => ':attributeは、:value文字以下で指定してください。',
'array' => ':attributeには、:value個以下のアイテムを指定してください。',
],
'max' => [
'numeric' => ':attributeには、:max以下の数字を指定してください。',
'file' => ':attributeには、:max kB以下のファイルを指定してください。',
'string' => ':attributeは、:max文字以下で指定してください。',
'array' => ':attributeは:max個以下指定してください。',
],
'mimes' => ':attributeには:valuesタイプのファイルを指定してください。',
'mimetypes' => ':attributeには:valuesタイプのファイルを指定してください。',
'min' => [
'numeric' => ':attributeには、:min以上の数字を指定してください。',
'file' => ':attributeには、:min kB以上のファイルを指定してください。',
'string' => ':attributeは、:min文字以上で指定してください。',
'array' => ':attributeは:min個以上指定してください。',
],
'not_in' => '選択された:attributeは正しくありません。',
'not_regex' => ':attributeの形式が正しくありません。',
'numeric' => ':attributeには、数字を指定してください。',
'present' => ':attributeが存在していません。',
'regex' => ':attributeに正しい形式を指定してください。',
'required' => ':attributeは必ず指定してください。',
'required_if' => ':otherが:valueの場合、:attributeも指定してください。',
'required_unless' => ':otherが:valuesでない場合、:attributeを指定してください。',
'required_with' => ':valuesを指定する場合は、:attributeも指定してください。',
'required_with_all' => ':valuesを指定する場合は、:attributeも指定してください。',
'required_without' => ':valuesを指定しない場合は、:attributeを指定してください。',
'required_without_all' => ':valuesのどれも指定しない場合は、:attributeを指定してください。',
'same' => ':attributeと:otherには同じ値を指定してください。',
'size' => [
'numeric' => ':attributeは:sizeを指定してください。',
'file' => ':attributeのファイルは、:sizeキロバイトでなくてはなりません。',
'string' => ':attributeは:size文字で指定してください。',
'array' => ':attributeは:size個指定してください。',
],
'starts_with' => ':attributeは:valuesのいずれかで始めてください。',
'string' => ':attributeは文字列を指定してください。',
'timezone' => ':attributeには、有効なゾーンを指定してください。',
'unique' => ':attributeの値は既に存在しています。',
'uploaded' => ':attributeのアップロードに失敗しました。',
'url' => ':attributeに正しい形式を指定してください。',
'uuid' => ':attributeに有効なUUIDを指定してください。',
/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
|--------------------------------------------------------------------------
|
| Here you may specify custom validation messages for attributes using the
| convention "attribute.rule" to name the lines. This makes it quick to
| specify a specific custom language line for a given attribute rule.
|
*/
'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
],
],
/*
|--------------------------------------------------------------------------
| Custom Validation Attributes
|--------------------------------------------------------------------------
|
| The following language lines are used to swap our attribute placeholder
| with something more reader friendly such as "E-Mail Address" instead
| of "email". This simply helps us make our message more expressive.
|
*/
'attributes' => [],
];
ただ、これだけだと下記のようにバリデーションがinputタグのname値が表示されます。
emailは必ず指定してください。
passwordは必ず指定してください。
ここも日本語化したい場合は、
validation.phpの"attributes"で指定します。
'attributes' => [
'email' => 'メールアドレス',
'password' => 'パスワード',
'password_confirmation' => 'パスワード(確認)',
'name' => 'ユーザー名'
],
とりあえず以上です。