Laravel sync
Call `syncLangFiles()` in a controller and share selected Laravel lang files with the Inertia page.
Sync Laravel lang files once, then use clean Vue, React, and Svelte helpers for keys, replacements, pluralization, and direct string fallback.
The backend decides which language files should be available for the page. After that, your frontend can read translations with a very small API.
syncLangFiles() in the controller.lang() in Vue, React, or Svelte.__() or trans().<?php
namespace App\Http\Controllers;
use Inertia\Inertia;
use Inertia\Response;
class DashboardController extends Controller
{
public function index(): Response
{
syncLangFiles('auth');
return Inertia::render('Dashboard');
}
}<?php
return [
'greeting' => 'Welcome back',
'welcome' => 'Welcome, :name',
];<script setup>
import { lang } from '@erag/lang-sync-inertia/vue';
const { __, trans } = lang();
</script>
<template>
<h1>{{ __('auth.greeting') }}</h1>
<p>{{ trans('auth.welcome', { name: 'Amit' }) }}</p>
</template>import { lang } from '@erag/lang-sync-inertia/react';
export default function Dashboard() {
const { __, trans } = lang();
return (
<section>
<h1>{__('auth.greeting')}</h1>
<p>{trans('auth.welcome', { name: 'Amit' })}</p>
</section>
);
}<script module lang="ts">
import { lang } from '@erag/lang-sync-inertia/svelte';
const { __, trans } = lang();
</script>
<section>
<h1>{__('auth.greeting')}</h1>
<p>{trans('auth.welcome', { name: 'Amit' })}</p>
</section>Nested Laravel language directories are also supported:
syncLangFiles('admin.auth');This reads lang/{locale}/admin/auth.php, then your frontend can call:
__('admin.auth.name');Laravel Lang Sync Inertia is an open-source package built to bridge the translation gap in hybrid Inertia.js architectures. Instead of writing custom JSON endpoints or copying translations manually to your frontend directory, it automates localization file syncing. The package loads, parses, and formats your existing server-side PHP array translations into lightweight frontend modules. With ready-to-use helpers for Vue, React, and Svelte, your client-side views stay perfectly synchronized with Laravel's active locale dynamically.
While you can manually pass translation objects through Inertia middleware, doing so for entire language libraries can result in massive payload sizes. This package handles automatic dynamic syncing, locale matching, legacy placeholder fallbacks, and localized frontend hooks efficiently without manual setup.
The package automatically respects Laravel's dynamic runtime locale. When you update the locale via app()->setLocale() on the server, the corresponding lang files will be dynamically loaded and shared with Inertia frontend hooks on the next render cycle.
Yes. The package includes artisan exporter commands to compile PHP translation files into JSON assets, allowing them to be cached in the browser or via Service Workers for offline capabilities.
Absolutely. It implements full pluralization interval support (using transChoice helper rules) and parameter replacement matching standard Laravel behavior in Vue, React, and Svelte.