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 and React 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 or React.__() 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>
);
}Choose the package you want to install first.
composer require erag/laravel-lang-sync-inertia
php artisan lang:publish
php artisan erag:install-langnpm install @erag/lang-sync-inertiaLaravel Lang Sync Inertia connects Laravel translation files to your Inertia frontend without manually passing props in every response.
This package is useful when: