PHPackages                             erag/laravel-lang-sync-inertia - 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. erag/laravel-lang-sync-inertia

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

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.

v2.1.0(2mo ago)3812.2k—2.1%4MITPHPPHP &gt;=8.1.0CI passing

Since May 7Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/eramitgupta/laravel-lang-sync-inertia)[ Packagist](https://packagist.org/packages/erag/laravel-lang-sync-inertia)[ Fund](https://www.paypal.com/paypalme/teamdevgeek)[ GitHub Sponsors](https://github.com/eramitgupta)[ RSS](/packages/erag-laravel-lang-sync-inertia/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (13)Used By (0)

🌐 Laravel Easy Translation Sync with Inertia (Vue.js / React)
=============================================================

[](#-laravel-easy-translation-sync-with-inertia-vuejs--react)

 [![Screenshot](https://private-user-images.githubusercontent.com/72160684/441412485-bbefb4c4-e435-45ab-954a-17eafa1405ee.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ2ODA5NjUsIm5iZiI6MTc3NDY4MDY2NSwicGF0aCI6Ii83MjE2MDY4NC80NDE0MTI0ODUtYmJlZmI0YzQtZTQzNS00NWFiLTk1NGEtMTdlYWZhMTQwNWVlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVN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qLz96z1ZgyfAaymlGBIaVljLGCjJuKwJA)[![Packagist License](https://camo.githubusercontent.com/e60623f508586f049d48cfb8396ee411b0c9bc3be174381a1893c37462a3c1e5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e63652d4d49542d626c7565)](https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/61be229914f5504f8a53faa42e71de529a499622c5989fcf9f5e416c711f137e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f657261672f6c61726176656c2d6c616e672d73796e632d696e65727469613f6c6162656c3d537461626c65)](https://packagist.org/packages/erag/laravel-lang-sync-inertia)[![Total Downloads](https://camo.githubusercontent.com/daed751b17ed1d2ff24be063229b936e32816da1e723233e1cd95e2122cd81f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f657261672f6c61726176656c2d6c616e672d73796e632d696e65727469612e7376673f6c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/erag/laravel-lang-sync-inertia)

**Laravel Lang Sync Inertia** helps you add different languages to your Laravel app with Vue or React. It makes translations easy!

✨ Features
----------

[](#-features)

- ⚙️ Inertia.js integration with automatic sharing
- 📂 Load single or multiple language files
- 🔄 Dynamic replacement support in translations
- 🧩 Supports both Vue.js and React
- 🧵 Built-in middleware for automatic sharing
- 🛠️ Helper functions like `trans()` and `__()` for frontend usage
- 🌍 Automatically switches language folder based on current Laravel locale
- 🆕 Generate frontend-ready JSON language files via Artisan command

---

📦 Installation
--------------

[](#-installation)

To install the package, run the following command via Composer:

```
composer require erag/laravel-lang-sync-inertia
```

---

🛠️ Publish Configuration &amp; Composables
------------------------------------------

[](#️-publish-configuration--composables)

To publish the configuration and composables, run:

```
php artisan erag:install-lang
```

---

⚠️ Required for Frontend (Vue/React)
====================================

[](#️-required-for-frontend-vuereact)

To use translations on your frontend, **📦 you must install the NPM companion package**:

```
npm install @erag/lang-sync-inertia
```

📘 Full frontend documentation: ➡

---

🚀 Usage Guide: `syncLangFiles()`
--------------------------------

[](#-usage-guide-synclangfiles)

The `syncLangFiles()` function is a Laravel helper provided by this package. Use it inside your **controller methods** to load translation files and automatically **share them with your Vue or React frontend via Inertia.js**.

> ✅ Think of `syncLangFiles()` as a bridge between Laravel’s backend translations and your Inertia-powered frontend.

---

### 🧠 How to Use

[](#-how-to-use)

```
// Load and sync a single translation file
syncLangFiles('auth');

// Load and sync multiple translation files
syncLangFiles(['auth', 'validation', 'pagination']);
```

---

### ✅ Supported Inputs

[](#-supported-inputs)

The `syncLangFiles()` function supports:

- A **string**: For a single translation file → `syncLangFiles('auth')`
- An **array of strings**: For multiple translation files → `syncLangFiles(['auth', 'validation'])`

---

### 🧪 How It Works

[](#-how-it-works)

Suppose you have the following language file:

📁 **`resources/lang/en/auth.php`**

```
return [
    'welcome' => 'Welcome, {name}!',
    'greeting' => 'Hello!',
];
```

Now, you want to show `auth.welcome` and `auth.greeting` on the frontend using Vue or React.

---

### 🔁 Step-by-Step Example

[](#-step-by-step-example)

#### 🔹 1. Load Translations in Controller

[](#-1-load-translations-in-controller)

```
use Inertia\Inertia;

public function login()
{
    // Load the auth.php language file
    syncLangFiles('auth');

    return Inertia::render('Login');
}
```

🧠 This loads the file `resources/lang/en/auth.php` based on the current Laravel locale and shares its content with Inertia.

---

### 💡 Frontend Usage

[](#-frontend-usage)

#### ✅ Vue Example

[](#-vue-example)

```

        {{ __('auth.greeting') }}
        {{ trans('auth.welcome', { name: 'John' }) }}

import { vueLang } from '@erag/lang-sync-inertia'

const { trans, __ } = vueLang()

```

#### ✅ React Example

[](#-react-example)

```
import React from 'react'
import { reactLang } from '@erag/lang-sync-inertia'

export default function Login() {
    const { trans, __ } = reactLang()

    return (

            {__('auth.greeting')}
            {trans('auth.welcome', { name: 'John' })}

    )
}
```

---

### 📤 Output on Page

[](#-output-on-page)

When the above code is rendered, this will be the output:

```
Hello!
Welcome, John!

```

---

### 🧠 Notes on `trans()` vs `__()`

[](#-notes-on-trans-vs-__)

FunctionUse CaseDescription`trans()`AdvancedUse when you need to pass dynamic placeholders like `{name}``__()`SimpleShortcut for quick access to translated strings✅ You can use them interchangeably for basic translations. ✅ Both support placeholder replacement.

---

### 🛠 Example with Plain String

[](#-example-with-plain-string)

Sometimes, you might want to append something without a key:

```
__('auth.welcome', 'Vue Developer')
// Output: "Welcome, {name}! Vue Developer" (if placeholder is not used)
```

But recommended usage is always with an object:

```
trans('auth.welcome', { name: 'Amit' })
// Output: "Welcome, Amit!"
```

---

📡 Access Inertia Shared Props
-----------------------------

[](#-access-inertia-shared-props)

**Vue:**

```
import { usePage } from '@inertiajs/vue3'

const { lang } = usePage().props
```

**React:**

```
import { usePage } from '@inertiajs/react'

const { lang } = usePage().props
```

You can directly access the full language object shared by Inertia.

---

🗂️ Translation File Location
----------------------------

[](#️-translation-file-location)

Language files are loaded based on the current Laravel locale. By default, Laravel uses `resources/lang/{locale}` structure:

```
resources/lang/
├── en/
│   └── auth.php
├── hi/
│   └── auth.php

```

When calling:

```
syncLangFiles('auth');
```

It dynamically loads `resources/lang/{locale}/auth.php`.

---

⚙️ Configuration
----------------

[](#️-configuration)

You can customize the language directory by modifying `config/inertia-lang.php`:

```
return [

    /*
       |--------------------------------------------------------------------------
       | Language Files Base Path
       |--------------------------------------------------------------------------
       |
       | Specifies the base directory where language files are stored.
       | By default, it points to the "lang" folder in the project root
       | using Laravel's base_path() helper.
       |
       */

    'lang_path' => base_path('lang'),

    /*
    |--------------------------------------------------------------------------
    | Output Path (Exported Files)
    |--------------------------------------------------------------------------
    |
    | Where the package will write generated files
    | like JSON for frontend tooling.
    |
    */

    'output_lang' => resource_path('js/lang'),
];
```

---

🆕 JSON File Support — Command
-----------------------------

[](#-json-file-support--command)

This Artisan command scans all locale folders in your `lang_path` and converts every `.php` translation file into a `.json` file — ready for direct frontend consumption without needing Inertia shared props.

### Run the Command

[](#run-the-command)

```
php artisan erag:generate-lang
```

### Example

[](#example)

**Input:** `resources/lang/en/auth.php`

```
return [
    'welcome'  => 'Welcome, {name}!',
    'greeting' => 'Hello!',
];
```

**Output:** `resources/js/lang/en/auth.json`

```
{
    "welcome": "Welcome, {name}!",
    "greeting": "Hello!"
}
```

### Generated Output Structure

[](#generated-output-structure)

```
resources/js/lang/
├── en/
│   ├── auth.json
│   ├── validation.json
│   └── pagination.json
├── hi/
│   ├── auth.json
│   └── validation.json

```

---

🧩 Through:
----------

[](#-through)

- `vueLang()` — Vue 3
- `reactLang()` — React

---

📄 License
---------

[](#-license)

This package is licensed under the [MIT License](https://opensource.org/licenses/MIT).

---

🤝 Contributing
--------------

[](#-contributing)

Pull requests and issues are welcome! Let’s work together to improve localization in Laravel! 💬

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance89

Actively maintained with recent releases

Popularity38

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.8% 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 ~34 days

Total

10

Last Release

61d ago

Major Versions

v1.8.0 → v2.0.02026-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8bf46883c00ee2ed8799a2b9a538a9ddf41c8a2eeda0ce69c04a0562de101f5?d=identicon)[eramitgupta](/maintainers/eramitgupta)

---

Top Contributors

[![eramitgupta](https://avatars.githubusercontent.com/u/72160684?v=4)](https://github.com/eramitgupta "eramitgupta (45 commits)")[![medchelios](https://avatars.githubusercontent.com/u/11645845?v=4)](https://github.com/medchelios "medchelios (1 commits)")

---

Tags

inertiajslaravellocalizationlocalization-managementmulti-languagereactjstranslationsvuejslaravellocalizationi18ntranslationsinertiainertiajsmulti-languagevue-i18nlaravel-i18nlaravel-inertialang-managerlang-syncdynamic-translationslanguage-synctranslation-syncinertia-langlanguage-managerlaravel-l10nreact i18ntranslation-helper

### Embed Badge

![Health badge](/badges/erag-laravel-lang-sync-inertia/health.svg)

```
[![Health](https://phpackages.com/badges/erag-laravel-lang-sync-inertia/health.svg)](https://phpackages.com/packages/erag-laravel-lang-sync-inertia)
```

###  Alternatives

[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)[mariuzzo/laravel-js-localization

Laravel Localization in JavaScript

6073.9M3](/packages/mariuzzo-laravel-js-localization)[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/packages/kkomelin-laravel-translatable-string-exporter)

PHPackages © 2026

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