Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lang Laravel Package

laravel-lang/lang

Community-maintained localization files for Laravel. Install via Composer to add and update translations for Laravel’s core messages across many locales, with curated language packs and ongoing updates from the Laravel Lang project.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require laravel-lang/lang
    

    Publish translations (if needed):

    php artisan vendor:publish --provider="LaravelLang\LangProvider" --tag=lang
    
  2. Configure config/app.php Add the provider to the providers array:

    LaravelLang\LangProvider::class,
    
  3. Set Default Locale Update config/app.php:

    'locale' => 'es', // Example: Spanish
    
  4. Verify Language Availability Check resources/lang/ for newly added language files (e.g., es.json, fr.php).

First Use Case

Replace hardcoded strings in Blade views with translations:

{{ __('messages.welcome') }}  <!-- Uses es.json if locale is 'es' -->

Or in PHP:

__('validation.required', ['attribute' => 'Name']);

Implementation Patterns

Core Workflows

  1. Multi-Language Support

    • Dynamically switch locales via middleware:
      public function handle($request, Closure $next)
      {
          app()->setLocale($request->header('Accept-Language') ?? config('app.locale'));
          return $next($request);
      }
      
    • Use Lang::get() for runtime locale retrieval:
      $locale = app()->getLocale();
      
  2. Validation Messages Leverage built-in validation translations (e.g., validation.required):

    $validator = Validator::make($data, $rules);
    $validator->setCustomMessages([
        'required' => __('custom.required', ['attribute' => 'Email']),
    ]);
    
  3. Jetstream/Fortify Localization Override auth/validation strings in resources/lang/{locale}/auth.php or validation.php.

  4. Dynamic Language Switching Add a language selector in Blade:

    <select name="language">
        @foreach (config('lang.supported') as $lang)
            <option value="{{ $lang }}" {{ app()->getLocale() === $lang ? 'selected' : '' }}>
                {{ __('languages.' . $lang) }}
            </option>
        @endforeach
    </select>
    

Integration Tips

  • Custom Language Files Extend existing translations by copying files from vendor/laravel-lang/lang/resources/lang/{locale} to resources/lang/{locale}.

  • Fallback Mechanism Configure fallback locales in config/app.php:

    'fallback_locale' => 'en',
    
  • Testing Mock translations in tests:

    $this->app->setLocale('es');
    $this->withoutExceptionHandling();
    

Gotchas and Tips

Pitfalls

  1. Missing Translations

    • Some languages (e.g., sr_Latn_ME, zh_CN) have gaps. Check status.md for specifics.
    • Fix: Override missing keys in resources/lang/{locale}/messages.php.
  2. Locale-Specific Files

    • Files like de_AT.php (German-Austria) may conflict with de.php. Ensure correct naming conventions.
  3. Caching Issues

    • Clear view/compiled translations after updates:
      php artisan view:clear
      php artisan config:clear
      
  4. Jetstream/Fortify Overrides

    • Custom auth strings in resources/lang/{locale}/auth.php may not auto-update. Re-publish translations if needed:
      php artisan vendor:publish --tag=lang --force
      

Debugging Tips

  • Check Loaded Locale
    dd(app()->getLocale());
    
  • Inspect Translation Files Use php artisan lang:list (if available) or manually verify resources/lang/{locale}.

Extension Points

  1. Add New Languages

  2. Custom Translation Logic Extend the LangServiceProvider:

    public function register()
    {
        $this->app->singleton('translator', function ($app) {
            $loader = new ArrayLoader();
            $loader->loadPaths([...]);
            return new Translator($loader, $app['locale']);
        });
    }
    
  3. Dynamic Language Loading Load translations on-demand:

    $translator->load('custom', $pathToJson);
    

Pro Tips

  • Use trans() for Context Pass arrays for dynamic replacements:
    trans('messages.greet', ['name' => 'John']);
    
  • Locale-Specific URLs Generate locale-aware links:
    route('home', [], false, app()->getLocale());
    
  • Performance Pre-compile translations for production:
    php artisan lang:compile
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope