Skip to content

Laravel Lang Sync InertiaLaravel translations for your Inertia frontend

Effortlessly synchronize server-side Laravel translations directly to Vue, React, and Svelte — with zero custom API endpoints, dynamic locale switching, and native SSR support.

Laravel Lang Sync Inertia
php
<?php

return [
    'name' => 'Laravel Lang Sync Inertia',
    'description' => 'Effortlessly synchronize server-side Laravel language files with Inertia frontend components.',
    'features' => 'Zero API endpoints, dynamic locale switching, and full SSR hydration.',

    'welcome' => 'Welcome to :app, :name!',
    'languages' => 'Supporting 1 language|Supporting :count languages',
];
php
<?php
namespace App\Http\Controllers;

use Inertia\Inertia;
use Inertia\Response;

class DashboardController extends Controller
{
    public function index(): Response
    {
        // Sync package translations for the active locale
        syncLangFiles('app');

        return Inertia::render('Dashboard');
    }
}
vue
<script setup>
import { vueLang } from '@erag/lang-sync-inertia';

const { trans, __, transChoice } = vueLang();
</script>

<template>
    <section class="package-preview">
        <h1>{{ __('app.name') }}</h1>
        <p>{{ __('app.description') }}</p>
        <p>{{ trans('app.welcome', { app: 'Laravel', name: 'Developer' }) }}</p>
        <p>{{ transChoice('app.languages', 12) }}</p>
    </section>
</template>
tsx
import { reactLang } from '@erag/lang-sync-inertia';

export default function Dashboard() {
    const { trans, __, transChoice } = reactLang();

    return (
        <section className="package-preview">
            <h1>{__('app.name')}</h1>
            <p>{__('app.description')}</p>
            <p>{trans('app.welcome', { app: 'Laravel', name: 'Developer' })}</p>
            <p>{transChoice('app.languages', 12)}</p>
        </section>
    );
}
svelte
<script module lang="ts">
import { svelteLang } from '@erag/lang-sync-inertia';

const { trans, __, transChoice } = svelteLang();
</script>

<section class="package-preview">
    <h1>{__('app.name')}</h1>
    <p>{__('app.description')}</p>
    <p>{trans('app.welcome', { app: 'Laravel', name: 'Developer' })}</p>
    <p>{transChoice('app.languages', 12)}</p>
</section>
text
Laravel Lang Sync Inertia
Effortlessly synchronize server-side Laravel language files with Inertia frontend components.
Welcome to Laravel, Developer!
Supporting 12 languages
Features

Elevate Laravel translations with Inertia

Use server-side language files in Vue, React, and Svelte pages without custom JSON endpoints or repeated prop wiring.

100%Laravel native
12Core features
3Frontend helpers
0Custom endpoints
CORE SYNC

Laravel sync

Load selected Laravel language files for a page and make them available to the frontend through Inertia.

VUE REACT SVELTE

Vue, React and Svelte

Use dedicated Vue, React, and Svelte helpers from the package root with consistent behavior.

:NAME VALUES

Key replacement

Replace dynamic values in translated strings using the same placeholder style your Laravel app already uses.

OLD SYNTAX

Legacy placeholders

Keep older placeholder formats working while gradually moving translation lines to the Laravel convention.

COUNT RULES

Pluralization

Render the right translation for zero, singular, and plural counts using Laravel-style interval rules.

SAFE FALLBACK

Missing key fallback

Show the original text when a translation key is unavailable, so pages fail gracefully during development.

APP LOCALE

Locale aware

Read translations from the active Laravel locale so frontend pages follow the same language as the backend.

DOT PATHS

Nested directories

Organize large translation sets in nested Laravel language directories and resolve them from frontend helpers.

FILE GROUPS

Multiple files

Share several language files together when a page needs copy from multiple translation groups.

PAGE PROPS

Shared lang prop

Expose translations on the shared Inertia page data so nested components can read them without prop drilling.

BUILD READY

JSON export

Generate frontend-ready JSON files from PHP lang files, then load the exported JSON automatically.

TYPED HELPERS

TypeScript ready

Typed Vue and React helpers give autocomplete for common translation calls.

Workflow

From Laravel lang files to
Inertia pages

The backend chooses the translation files for the current route, Inertia shares them with the page, and the frontend helpers resolve text for Vue, React, or Svelte components.

1

Pick language files

Keep translations in Laravel and select only the groups a page needs.

2

Share through Inertia

The package places translated data into the page payload using Laravel's active locale.

3

Render in components

Frontend helpers read the shared data and handle replacements, pluralization, and fallbacks.

Translation Syncing Made Simple

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.

Frequently Asked Questions

Find answers to common questions about Laravel Lang Sync Inertia, performance, SSR, and frontend integrations.

Why use this package over manual prop sharing in HandleInertiaRequests?

While you can manually pass translation objects through Inertia middleware, sharing entire language files bloats every Inertia page payload and slows down initial page loads. Laravel Lang Sync Inertia selectively loads only the files required for the current route, automatically detects the active locale, resolves nested directories, and provides zero-overhead frontend helpers for Vue 3, React, and Svelte.

Does it support Server-Side Rendering (SSR)?

Yes, full Inertia SSR support is built-in. Translations are resolved and injected into shared Inertia page props on the Laravel server before the frontend SSR bundle executes. This ensures your server-rendered HTML contains the correct translated strings and hydrates seamlessly in the browser with zero flash of untranslated content (FOUC).

How does runtime locale switching work?

The package automatically detects Laravel's dynamic runtime locale (configured via App::setLocale() or your custom locale middleware). When a user updates their language, Inertia reloads the page props with the new locale's translation keys, and frontend hooks update the UI reactively.

Does it support parameter replacements and pluralization (transChoice)?

Yes. It mirrors Laravel's native translation engine completely across Vue, React, and Svelte:

  • Replacements: Supports dynamic placeholder substitution, like trans('auth.welcome', { name: 'John' }).
  • Pluralization: Supports pipe-separated count rules and interval ranges via transChoice('cart.items', count).
Can I bundle or pre-compile translations for production?

Yes. The package includes an Artisan export command (php artisan lang:sync-export) that pre-compiles PHP translation files into static JSON assets, eliminating disk I/O and reducing server memory usage under high traffic.

Can I organize translations into nested folders and subdirectories?

Yes. You can structure language files in subdirectories (such as lang/en/admin/settings.php). You can sync them by path (e.g. syncLangFiles('admin/settings')) and reference them seamlessly using dot notation (e.g. __('admin.settings.title')).

Is TypeScript supported with autocompletion?

Yes. The frontend package @erag/lang-sync-inertia is written in TypeScript and provides complete type definitions. Helpers like vueLang(), reactLang(), and svelteLang() offer typed signatures for translation keys, replacement parameters, and plural counts.

What happens if a translation key is missing?

The package implements a safe two-tier fallback strategy:

  1. Checks for the key in the currently active locale.
  2. Falls back to the configured fallback locale (e.g., 'en' in config/app.php).
  3. If still not found, it gracefully returns the key string itself (e.g., 'messages.welcome') rather than throwing an exception.
Does it support both PHP array files and JSON translation files?

Yes. Laravel Lang Sync Inertia natively parses both standard PHP array translation files (lang/{locale}/*.php) and root JSON localization files (lang/{locale}.json) frequently used in modern Laravel projects.

How do I install and get started?

Installation takes less than two minutes via Composer and npm:

Backendcomposer require eramitgupta/laravel-lang-sync-inertia
Frontendnpm install @erag/lang-sync-inertia

Then call syncLangFiles('auth') in your controller and use vueLang(), reactLang(), or svelteLang() in your frontend components.

MIT License © Er Amit Gupta