Back to list
fusengine

laravel-i18n

by fusengine

Redefining development through cognitive automation and collaborative agent systems.

0🍴 0📅 Jan 25, 2026

SKILL.md


name: laravel-i18n description: Laravel localization - __(), trans_choice(), lang files, JSON translations, pluralization. Use when implementing translations in Laravel apps. user-invocable: false

Laravel Internationalization

Setup

php artisan lang:publish

Creates lang/ directory with default language files.


File Structure

lang/
├── en/
│   ├── messages.php      # Short keys
│   └── validation.php
├── fr/
│   ├── messages.php
│   └── validation.php
├── en.json               # Full text keys
└── fr.json

Configuration

// config/app.php
'locale' => env('APP_LOCALE', 'en'),
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),

Translation Helpers

// Basic translation
__('messages.welcome')

// With replacement
__('Hello :name', ['name' => 'John'])

// JSON approach (full text as key)
__('Welcome to our application')

// Alias
trans('messages.welcome')

PHP Translation Files

// lang/en/messages.php
return [
    'welcome' => 'Welcome to our application',
    'hello' => 'Hello :name',
    'goodbye' => 'Goodbye :name, see you :time',
];

JSON Translation Files

// lang/fr.json
{
    "Welcome to our application": "Bienvenue sur notre application",
    "Hello :name": "Bonjour :name"
}

Pluralization

// lang/en/messages.php
'apples' => '{0} No apples|{1} One apple|[2,*] :count apples',
trans_choice('messages.apples', 0);  // "No apples"
trans_choice('messages.apples', 1);  // "One apple"
trans_choice('messages.apples', 5);  // "5 apples"

Runtime Locale

use Illuminate\Support\Facades\App;

// Set locale
App::setLocale('fr');

// Get current locale
$locale = App::currentLocale();

// Check locale
if (App::isLocale('fr')) {
    // ...
}

Middleware Example

// app/Http/Middleware/SetLocale.php
public function handle(Request $request, Closure $next): Response
{
    $locale = $request->segment(1);

    if (in_array($locale, ['en', 'fr', 'de'])) {
        App::setLocale($locale);
    }

    return $next($request);
}

Blade Usage

{{ __('messages.welcome') }}
@lang('messages.welcome')
{{ trans_choice('messages.apples', 5) }}

Best Practices

  1. Use JSON files for large apps with many strings
  2. PHP files for structured, nested translations
  3. Always use placeholders :name not concatenation
  4. Group by feature in namespaces: auth.login.title

Score

Total Score

60/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon