PHPackages                             devwizardhq/laravel-localizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. devwizardhq/laravel-localizer

ActiveLibrary[Localization &amp; i18n](/categories/localization)

devwizardhq/laravel-localizer
=============================

Laravel Localizer bridges Laravel translations to your SPA frontend (React/Vue/Inertia) and provides generated language assets, type-safe usage, and global translation helpers.

v1.1.0(2mo ago)71.4k↓35%[2 PRs](https://github.com/DevWizardHQ/laravel-localizer/pulls)MITPHPPHP ^8.3CI passing

Since Nov 10Pushed 2mo agoCompare

[ Source](https://github.com/DevWizardHQ/laravel-localizer)[ Packagist](https://packagist.org/packages/devwizardhq/laravel-localizer)[ Docs](https://github.com/devwizardhq/laravel-localizer)[ GitHub Sponsors](https://github.com/DevWizard)[ RSS](/packages/devwizardhq-laravel-localizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (26)Versions (6)Used By (0)

Laravel Localizer
=================

[](#laravel-localizer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7142815ba7ffc377831a8e01d4b5fd01f457ffb5458967a5b4601fd29562b5b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657677697a61726468712f6c61726176656c2d6c6f63616c697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devwizardhq/laravel-localizer)[![Total Downloads](https://camo.githubusercontent.com/29956b61cbece3c2a286b9e05d8df5f042ed80e30af9707ea3d8160a3ee015be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657677697a61726468712f6c61726176656c2d6c6f63616c697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/devwizardhq/laravel-localizer)

Seamlessly bridge Laravel translations to your SPA frontend (React/Vue) with automatic TypeScript generation, type-safe usage, and powerful localization features.

Features
--------

[](#features)

- 🔍 **Auto-scan translations** - Automatically discover translation keys from your codebase
- 🌐 **Auto-translate** - Use Google Translate to automatically translate missing keys
- 📦 **TypeScript generation** - Export translations as TypeScript files for frontend use
- 🎯 **Type-safe** - Full IDE support with PHPDoc annotations
- ⚡ **Performance** - In-memory caching and build-time generation
- 🔄 **Vendor support** - Automatically includes translations from vendor packages
- 🌍 **RTL support** - Built-in right-to-left language support
- 🎨 **Framework agnostic** - Works with React, Vue, and vanilla JavaScript

Installation
------------

[](#installation)

Install via Composer:

```
composer require devwizardhq/laravel-localizer
```

Run the installation command:

```
php artisan localizer:install
```

This interactive installer will:

- ✅ Publish configuration file
- ✅ Create default locale files
- ✅ Publish and register middleware
- ✅ Setup TypeScript output directory
- ✅ Generate initial translation files

### Manual Setup

[](#manual-setup)

If you prefer manual configuration:

```
# Publish config
php artisan vendor:publish --tag="laravel-localizer-config"

# Publish middleware
php artisan vendor:publish --tag="laravel-localizer-middleware"
```

Register the middleware in `bootstrap/app.php`:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
        \App\Http\Middleware\LocalizerMiddleware::class,
    ]);
})
```

Quick Start
-----------

[](#quick-start)

### 1. Configure Available Locales

[](#1-configure-available-locales)

Edit `config/localizer.php`:

```
return [
    'default' => 'en',
    'fallback' => 'en',

    'available' => [
        'en' => ['label' => 'English', 'flag' => '🇬🇧', 'dir' => 'ltr'],
        'fr' => ['label' => 'Français', 'flag' => '🇫🇷', 'dir' => 'ltr'],
        'ar' => ['label' => 'العربية', 'flag' => '🇸🇦', 'dir' => 'rtl'],
    ],

    'path' => lang_path(),
    'typescript_output_path' => resource_path('js/lang'),
];
```

### 2. Sync Translation Keys

[](#2-sync-translation-keys)

Scan your codebase for translation keys:

```
php artisan localizer:sync --all
```

This finds all `__()`, `trans()`, and `lang()` calls and adds missing keys to your language files.

### 3. Generate TypeScript Files

[](#3-generate-typescript-files)

Export translations for your frontend:

```
php artisan localizer:generate --all
```

Generates TypeScript files in `resources/js/lang/`:

```
// resources/js/lang/en.ts
export const en = {
  "welcome": "Welcome",
  "validation.required": "This field is required"
} as const;
```

### 4. Use in Frontend

[](#4-use-in-frontend)

Install the corresponding frontend package:

```
# For React
npm install @devwizard/laravel-localizer-react

# For Vue
npm install @devwizard/laravel-localizer-vue
```

See the [React package README](https://www.npmjs.com/package/@devwizard/laravel-localizer-react) or [Vue package README](https://www.npmjs.com/package/@devwizard/laravel-localizer-vue) for frontend integration details.

Usage
-----

[](#usage)

### Commands

[](#commands)

#### Sync Translation Keys

[](#sync-translation-keys)

```
# Sync all locales
php artisan localizer:sync --all

# Sync specific locales
php artisan localizer:sync --locales=en,fr

# Interactive selection
php artisan localizer:sync
```

#### Auto-translate

[](#auto-translate)

Automatically translate from one locale to another using Google Translate:

```
# With options
php artisan localizer:translate --source=en --target=fr

# Interactive selection
php artisan localizer:translate
```

**Note:** Requires `stichoza/google-translate-php`:

```
composer require stichoza/google-translate-php
```

#### Generate TypeScript Files

[](#generate-typescript-files)

```
# Generate all locales
php artisan localizer:generate --all

# Generate specific locales
php artisan localizer:generate --locales=en,fr

# Interactive selection
php artisan localizer:generate
```

### Programmatic API

[](#programmatic-api)

```
use DevWizard\Localizer\Facades\Localizer;

// Create a new locale
Localizer::create('fr', fromLocale: 'en');

// Get all translations (JSON + PHP combined)
$translations = Localizer::get('en');

// Get JSON translations only
$jsonTranslations = Localizer::getJson('en');

// Set a JSON translation
Localizer::set('welcome', 'Welcome!', 'en');

// Set nested PHP translation
Localizer::setPhp('validation.required', 'Field is required', 'en');

// Bulk operations
Localizer::bulkSet([
    'hello' => 'Hello',
    'goodbye' => 'Goodbye',
], 'en');

// Check if translation exists
if (Localizer::has('welcome', 'en')) {
    // ...
}

// Get available locales
$locales = Localizer::availableLocales(); // ['en', 'fr', 'ar']

// Delete a locale
Localizer::delete('fr');

// Rename a locale
Localizer::rename('en', 'en-US');
```

### Middleware

[](#middleware)

The `LocalizerMiddleware` automatically:

- Detects user's preferred locale
- Sets the application locale
- Shares locale data with Inertia.js

**Locale Detection Priority:**

1. Query parameter: `?locale=fr`
2. Request header: `X-Locale: fr`
3. Session: stored from previous requests
4. User model: `$user->getLocale()` (if method exists)
5. Browser: `Accept-Language` header
6. Default: `config('localizer.default')`

**Shared Inertia Props:**

```
{
  locale: {
    current: 'en',
    dir: 'ltr',
    available: {
      en: { label: 'English', flag: '🇬🇧', dir: 'ltr' },
      fr: { label: 'Français', flag: '🇫🇷', dir: 'ltr' },
      ar: { label: 'العربية', flag: '🇸🇦', dir: 'rtl' }
    }
  }
}
```

Translation Organization
------------------------

[](#translation-organization)

The package uses dot notation to organize translations:

- **JSON keys** (no dots): `welcome`, `hello world` → stored in `{locale}.json`
- **PHP keys** (with dots): `validation.required`, `auth.failed` → stored in `{locale}/{file}.php`

Example structure:

```
lang/
├── en.json                 # Simple translations
├── en/
│   ├── validation.php      # Validation messages
│   └── auth.php           # Auth messages
├── fr.json
└── fr/
    ├── validation.php
    └── auth.php

```

Deployment
----------

[](#deployment)

### Generated Files

[](#generated-files)

The installer automatically adds generated TypeScript files to `.gitignore`. In your deployment process, regenerate them:

```
# After composer install
php artisan localizer:generate --all

# Then build frontend
npm run build
```

### Example CI/CD

[](#example-cicd)

```
#!/bin/bash

composer install --no-dev --optimize-autoloader
npm ci

# Generate translations before building
php artisan localizer:generate --all

npm run build
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

Frontend Packages
-----------------

[](#frontend-packages)

- **React**: [@devwizard/laravel-localizer-react](https://www.npmjs.com/package/@devwizard/laravel-localizer-react)
- **Vue**: [@devwizard/laravel-localizer-vue](https://www.npmjs.com/package/@devwizard/laravel-localizer-vue)

Both packages provide:

- Hooks/composables for translations
- Vite plugin for automatic regeneration
- Full TypeScript support
- Inertia.js integration
- Placeholder replacement
- Pluralization support

Configuration
-------------

[](#configuration)

The `config/localizer.php` file provides extensive customization options:

```
return [
    // Default and fallback locales
    'default' => env('APP_LOCALE', 'en'),
    'fallback' => env('APP_FALLBACK_LOCALE', 'en'),

    // Available locales with metadata
    'available' => [
        'en' => ['label' => 'English', 'flag' => '🇬🇧', 'dir' => 'ltr'],
    ],

    // Paths
    'path' => lang_path(),
    'typescript_output_path' => resource_path('js/lang'),

    // Scanning configuration
    'scan' => [
        'include' => [app_path(), resource_path(), base_path('routes')],
        'exclude' => [base_path('vendor'), base_path('node_modules')],
        'extensions' => ['php', 'blade.php', 'js', 'jsx', 'ts', 'tsx', 'vue'],
    ],
];
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [IQBAL HASAN](https://github.com/iqbalhasandev)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance87

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Total

3

Last Release

69d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39612205?v=4)[IQBAL HASAN](/maintainers/iqbalhasandev)[@iqbalhasandev](https://github.com/iqbalhasandev)

---

Top Contributors

[![iqbalhasandev](https://avatars.githubusercontent.com/u/39612205?v=4)](https://github.com/iqbalhasandev "iqbalhasandev (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

composer-packagelaravel-inertiajslaravel-packagelaravel-reactlaravel-vuephplaravellocalizationinternationalizationi18ntranslationslanguagel10nmultilinguallaravel-packagetypescriptinertiareactfrontendinertiajsvueSPAlaravel-localizerDevWizard

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/devwizardhq-laravel-localizer/health.svg)

```
[![Health](https://phpackages.com/badges/devwizardhq-laravel-localizer/health.svg)](https://phpackages.com/packages/devwizardhq-laravel-localizer)
```

###  Alternatives

[gettext/languages

gettext languages with plural rules

7530.3M11](/packages/gettext-languages)[outhebox/laravel-translations

Manage your Laravel translations with a beautiful UI. Add, edit, delete, import, and export translations with ease.

80687.6k](/packages/outhebox-laravel-translations)[punic/punic

PHP-Unicode CLDR

1542.9M29](/packages/punic-punic)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

3812.2k](/packages/erag-laravel-lang-sync-inertia)[jayesh/laravel-gemini-translator

An interactive command to extract and generate Laravel translations using Gemini AI.

691.7k1](/packages/jayesh-laravel-gemini-translator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
