mcpField
L
laravel-i18n

laravel-i18n

github.com/fusengineDevelopment3456 installsUpdated 2w ago
Repository

About laravel-i18n

A Laravel localization skill for developers implementing multilingual applications. It covers translation files, locale handling, formatting, and package translations, including locale propagation into queued jobs in Laravel 13.

Key features

  1. 01PHP and JSON translation-file guidance
  2. 02Pluralization and Blade translation helpers
  3. 03Locale-detection middleware patterns
  4. 04Date, number, and currency formatting
  5. 05Queue-safe locale propagation in Laravel 13

Use cases

  1. 01Set up translations for a Laravel application
  2. 02Handle plural strings and dynamic placeholders
  3. 03Detect and validate the requested locale
  4. 04Preserve locale settings in queued jobs

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/fusengine/agents --skill laravel-i18n

After installing, type/laravel-i18nin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
best-practices.md
blade-translations.md
formatting.md
localization.md
middleware.md
packages.md
pluralization.md
references/templates/
lang-files.md
LocaleRoutes.php.md
LocaleServiceProvider.php.md
SetLocaleMiddleware.php.md

Details

From the project README
Covers Laravel localization: PHP vs JSON translation files, pluralization rules, Blade translation helpers, locale-detection middleware, date/number/ currency formatting, vendor package translations, and organizing translations for large apps. Includes queue-safe locale propagation via Context::add() in Laravel 13.

Laravel Internationalization

Agent Workflow (MANDATORY)

Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:

  1. fuse-ai-pilot:explore-codebase - Check existing translation patterns
  2. fuse-ai-pilot:research-expert - Verify Laravel i18n best practices via Context7
  3. mcp__context7__query-docs - Check Laravel localization documentation

After implementation, run fuse-ai-pilot:sniper for validation.


Overview

FeaturePHP FilesJSON Files
KeysShort (messages.welcome)Full text
NestingSupportedFlat only
Best forStructured translationsLarge apps

Critical Rules

  1. Never concatenate strings - Use :placeholder replacements
  2. Always handle zero in pluralization
  3. Group by feature - auth.login.title, auth.login.button
  4. Extract strings early - No hardcoded text in views
  5. Validate locales - Use enum or whitelist

Decision Guide

Translation task?
├── Basic string → __('key')
├── With variables → __('key', ['name' => $value])
├── Pluralization → trans_choice('key', $count)
├── In Blade → @lang('key') or {{ __('key') }}
├── Locale detection → Middleware
├── Format date/money → LocalizationService
└── Package strings → trans('package::key')

Reference Guide

Concepts (WHY & Architecture)
TopicReferenceWhen to Consult
Setuplocalization.mdInitial configuration
Pluralizationpluralization.mdCount-based translations
Bladeblade-translations.mdView translations
Middlewaremiddleware.mdLocale detection
Formattingformatting.mdDate/number/currency
Packagespackages.mdVendor translations
Best Practicesbest-practices.mdLarge app organization
Templates (Complete Code)
TemplateWhen to Use
SetLocaleMiddleware.php.mdURL/session locale detection
lang-files.mdTranslation file examples
LocaleServiceProvider.php.mdCentralized localization service
LocaleRoutes.php.mdURL prefix locale routing

Quick Reference

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

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

// Pluralization
trans_choice('messages.items', $count)

// Runtime locale
App::setLocale('es');
App::currentLocale();  // 'es'

Best Practices

DO
  • Use :placeholder for dynamic values
  • Handle zero case in pluralization
  • Group keys by feature module
  • Use Locale enum for type safety
  • Set Carbon locale in middleware
DON'T
  • Concatenate translated strings
  • Hardcode text in views
  • Accept any locale without validation
  • Create DB-based translations (use files)

Laravel 13 Notes

The localization API (__(), trans_choice(), App::setLocale()) is unchanged in Laravel 13. Specific points:

  • Context::add('locale', $locale) propagates the locale into queued jobs (fixes the L12 bug where the locale was lost in ShouldQueue jobs)
  • cache.serializable_classes (default false in L13): list your Locale objects if you cache them
  • SetLocale middleware: compatible with the new PreventRequestForgery middleware from [[laravel-auth]]
// app/Jobs/SendNotification.php
public function handle(): void
{
    App::setLocale(Context::get('locale', 'en'));
    Notification::send($this->user, new OrderShipped());
}

Comments

Markdown supported