0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Laravel translation

Last updated at Posted at 2025-12-11

Laraavel translation

translation機能はアプリケーションを複数の言語に対応させるための国際化、地域化の機能

基本的な使い方

言語の設定
アプリケーションが現在どの言語を使用するかLaravelに伝える

デェフォルトロケール
アプリケーション全体で標準的に使用する言語は設定ファイルで指定する

  • ファイル:config/app.php
  • 項目:'locate'
'locale' => 'ja', // デフォルトを日本語に設定
// 'locale' => 'en', // デフォルトを英語に設定

実行時のロケール変更
リクエストごとに動的に言語を変更

use Illuminate\Support\Facades\App;

// 現在のリクエストのロケールを英語に変更する
App::setLocale('en');

翻訳ファイルの作成
resources/long内に作成(resources/lang/jp/messages 、resources/lam/en/messagesなど)

ヘルパー関数の使用

BladeテンプレートやPHPコード内で取得
Blade

<button>{{ __('messages.login') }}</button>

変数の埋め込み
Blade

<h1>
    {{ __('messages.welcome', ['name' => $user->name]) }}
</h1>                                                                                
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?