Laravelは認証機能の諸々のエラーメッセージの文言がデフォルトで英語です。なのでエラーメッセージを日本語化していきます。
手順は以下の通り。
- config / app.phpファイルの修正
- resources / lang / en ディレクトリをコピーして 「ja」にリネーム
- resources / lang / ja ディレクトリにある「auth.php」「pagination.php」「passwords.php」「validation.php」ファイルの修正
サクッと読める目次
日本語化する前のエラーメッセージの確認
以下の画像のような感じでエラーメッセージが英語で出ます。これを日本語にしていきます。

config / app.phpファイルの修正
configディレクトリにあるapp.phpファイルを修正します。
1 2 3 4 5 |
//修正前 'locale' => 'en', //修正後 'locale' => 'ja', |
resources / lang / en ディレクトリをコピーして 「ja」にリネーム
図で解説していきます。
enディレクトリをコピーします。

同じ位置(langディレクトリ内)にペーストします。

コピペしたディレクトリの名前を変更します。

リネームできました。

jaディレクトリには、enディレクトリにあった「auth.php」「pagination.php」「passwords.php」「validation.php」もコピーされているので、これらのファイルを日本語へ修正していきます。
resources / lang / ja ディレクトリにある「auth.php」「pagination.php」「passwords.php」「validation.php」ファイルの修正
修正ファイルは様々な方が、GitHubにアップしてくれています。
Laravel5.5のこちらのURLを参考にしました。GitHubの日本語化修正ファイルURL
英語表記のところを日本語に変えるだけの作業ですので、ファイル自体を差し替えてもらってもいいですし、基本はコピペでOKです。
auth.phpファイルの修正
auth.phpファイルを修正します。ファイル自体をGitHubから差し替えてもいいですし、日本語の文言をコピペしてもらっても大丈夫です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//修正前 return [ 'failed' => 'These credentials do not match our records.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', ]; //修正後 return [ 'failed' => '認証情報が記録と一致しません。'', 'throttle' => 'ログイン試行が規定回数を超えました。:seconds秒後に再開できます。', ]; |
pagination.phpファイルの修正
pagination.phpファイルの修正をしましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//修正前 return [ 'previous' => '« Previous', 'next' => 'Next »', ]; //修正後 return [ 'previous' => '« 前へ', 'next' => '次へ »', ]; |
passwords.phpファイルの修正
passwords.phpファイルの修正をします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
//修正前 return [ 'password' => 'Passwords must be at least six characters and match the confirmation.', 'reset' => 'Your password has been reset!', 'sent' => 'We have e-mailed your password reset link!', 'token' => 'This password reset token is invalid.', 'user' => "We can't find a user with that e-mail address.", ]; //修正後 return [ 'password' => 'パスワードは6文字以上にして、確認用入力欄と一致させてください。', 'reset' => 'パスワードは再設定されました!', 'sent' => 'パスワード再設定用のURLをメールで送りました。', 'token' => 'パスワード再設定用のトークンが不正です。', 'user' => "メールアドレスに一致するユーザーが存在しません。", ]; |
validation.phpファイルの修正
validation.phpファイルを修正します。
修正前が以下です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
//修正前 return [ 'accepted' => 'The :attribute must be accepted.', 'active_url' => 'The :attribute is not a valid URL.', 'after' => 'The :attribute must be a date after :date.', 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 'alpha' => 'The :attribute may only contain letters.', 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 'alpha_num' => 'The :attribute may only contain letters and numbers.', 'array' => 'The :attribute must be an array.', 'before' => 'The :attribute must be a date before :date.', 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 'between' => [ 'numeric' => 'The :attribute must be between :min and :max.', 'file' => 'The :attribute must be between :min and :max kilobytes.', 'string' => 'The :attribute must be between :min and :max characters.', 'array' => 'The :attribute must have between :min and :max items.', ], 'boolean' => 'The :attribute field must be true or false.', 'confirmed' => 'The :attribute confirmation does not match.', 'date' => 'The :attribute is not a valid date.', 'date_format' => 'The :attribute does not match the format :format.', 'different' => 'The :attribute and :other must be different.', 'digits' => 'The :attribute must be :digits digits.', 'digits_between' => 'The :attribute must be between :min and :max digits.', 'dimensions' => 'The :attribute has invalid image dimensions.', 'distinct' => 'The :attribute field has a duplicate value.', 'email' => 'The :attribute must be a valid email address.', 'exists' => 'The selected :attribute is invalid.', 'file' => 'The :attribute must be a file.', 'filled' => 'The :attribute field must have a value.', 'gt' => [ 'numeric' => 'The :attribute must be greater than :value.', 'file' => 'The :attribute must be greater than :value kilobytes.', 'string' => 'The :attribute must be greater than :value characters.', 'array' => 'The :attribute must have more than :value items.', ], 'gte' => [ 'numeric' => 'The :attribute must be greater than or equal :value.', 'file' => 'The :attribute must be greater than or equal :value kilobytes.', 'string' => 'The :attribute must be greater than or equal :value characters.', 'array' => 'The :attribute must have :value items or more.', ], 'image' => 'The :attribute must be an image.', 'in' => 'The selected :attribute is invalid.', 'in_array' => 'The :attribute field does not exist in :other.', 'integer' => 'The :attribute must be an integer.', 'ip' => 'The :attribute must be a valid IP address.', 'ipv4' => 'The :attribute must be a valid IPv4 address.', 'ipv6' => 'The :attribute must be a valid IPv6 address.', 'json' => 'The :attribute must be a valid JSON string.', 'lt' => [ 'numeric' => 'The :attribute must be less than :value.', 'file' => 'The :attribute must be less than :value kilobytes.', 'string' => 'The :attribute must be less than :value characters.', 'array' => 'The :attribute must have less than :value items.', ], 'lte' => [ 'numeric' => 'The :attribute must be less than or equal :value.', 'file' => 'The :attribute must be less than or equal :value kilobytes.', 'string' => 'The :attribute must be less than or equal :value characters.', 'array' => 'The :attribute must not have more than :value items.', ], 'max' => [ 'numeric' => 'The :attribute may not be greater than :max.', 'file' => 'The :attribute may not be greater than :max kilobytes.', 'string' => 'The :attribute may not be greater than :max characters.', 'array' => 'The :attribute may not have more than :max items.', ], 'mimes' => 'The :attribute must be a file of type: :values.', 'mimetypes' => 'The :attribute must be a file of type: :values.', 'min' => [ 'numeric' => 'The :attribute must be at least :min.', 'file' => 'The :attribute must be at least :min kilobytes.', 'string' => 'The :attribute must be at least :min characters.', 'array' => 'The :attribute must have at least :min items.', ], 'not_in' => 'The selected :attribute is invalid.', 'not_regex' => 'The :attribute format is invalid.', 'numeric' => 'The :attribute must be a number.', 'present' => 'The :attribute field must be present.', 'regex' => 'The :attribute format is invalid.', 'required' => 'The :attribute field is required.', 'required_if' => 'The :attribute field is required when :other is :value.', 'required_unless' => 'The :attribute field is required unless :other is in :values.', 'required_with' => 'The :attribute field is required when :values is present.', 'required_with_all' => 'The :attribute field is required when :values is present.', 'required_without' => 'The :attribute field is required when :values is not present.', 'required_without_all' => 'The :attribute field is required when none of :values are present.', 'same' => 'The :attribute and :other must match.', 'size' => [ 'numeric' => 'The :attribute must be :size.', 'file' => 'The :attribute must be :size kilobytes.', 'string' => 'The :attribute must be :size characters.', 'array' => 'The :attribute must contain :size items.', ], 'string' => 'The :attribute must be a string.', 'timezone' => 'The :attribute must be a valid zone.', 'unique' => 'The :attribute has already been taken.', 'uploaded' => 'The :attribute failed to upload.', 'url' => 'The :attribute format is invalid.', 'custom' => [ 'attribute-name' => [ 'rule-name' => 'custom-message', ], ], 'attributes' => [], ]; |
修正後が以下です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
//修正後 return [ '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には空でない値を指定してください。', 'image' => ':attributeには画像ファイルを指定してください。', 'in' => ':attributeには:valuesのうちいずれかの値を指定してください。', 'in_array' => ':attributeが:otherに含まれていません。', 'integer' => ':attributeには整数を指定してください。', 'ip' => ':attributeには正しい形式のIPアドレスを指定してください。', 'ipv4' => ':attributeには正しい形式のIPv4アドレスを指定してください。', 'ipv6' => ':attributeには正しい形式のIPv6アドレスを指定してください。', 'json' => ':attributeには正しい形式のJSON文字列を指定してください。', '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には:valuesのうちいずれとも異なる値を指定してください。', '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 KBのファイルを指定してください。', 'string' => ':attributeには:size文字の文字列を指定してください。', 'array' => ':attributeには:size個の要素を持つ配列を指定してください。', ], 'string' => ':attributeには文字列を指定してください。', 'timezone' => ':attributeには正しい形式のタイムゾーンを指定してください。', 'unique' => 'その:attributeはすでに使われています。', 'uploaded' => ':attributeのアップロードに失敗しました。', 'url' => ':attributeには正しい形式のURLを指定してください。', 'custom' => [ 'attribute-name' => [ 'rule-name' => 'custom-message', ], ], 'attributes' => [], ]; |
以上を修正すると下の画像のようになります。「email」と「password」がまだ英語になっているので、カタカナにします。

validation.phpのattributesを修正
先ほど修正したvalidation.phpのattributesを修正します。
1 2 3 4 5 6 7 8 |
//修正前 'attributes' => [], //修正後 'attributes' => [ 'email' => 'メールアドレス', 'password' => 'パスワード', ], |
日本語化した後のエラーメッセージの確認
修正後の画面を確認します。以下のように出ていれば、OKです。

コメントを残す