npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@erag/lang-sync-inertia

v3.1.0

Published

Laravel Inertia.js translation and localization package for Vue 3, React, and Svelte with reactive language switching, translation helpers, nested keys, placeholders, pluralization, and TypeScript support

Downloads

2,522

Readme

@erag/lang-sync-inertia

Sync Laravel translations with Inertia.js for Vue 3, React, and Svelte.

A lightweight frontend companion to eramitgupta/laravel-lang-sync-inertia. It reads translations shared through Inertia's page.props.lang and provides consistent, type-safe helpers for lookups, nested keys, placeholders, pluralization, and locale-aware updates.


Features

  • 🔄 Laravel sync with syncLangFiles() to share selected language files through Inertia
  • 🧩 Vue 3, React 18/19, and Svelte 5 helpers from one package root
  • 🌍 Locale-aware loading from Laravel's active lang/{locale} directory
  • 📁 Single, multiple, and nested files with dot notation such as admin.auth
  • Shared translations available through Inertia's reactive page.props.lang
  • 🛠️ Translation helpers: __(), trans(), transChoice(), and trans_choice()
  • 📝 Laravel placeholders with both :name and legacy {name} syntax
  • 🔢 Pluralization with exact values and Laravel intervals such as {0}, {1}, and [2,*]
  • ↩️ Direct string keys with fallback to the original key when a translation is missing
  • 📦 JSON export from PHP language files for frontend-ready static translations
  • TypeScript support with typed helpers and a lightweight runtime

Requirements

This package requires the Laravel backend package to share translations with the frontend:

composer require erag/laravel-lang-sync-inertia

Installation

npm install @erag/lang-sync-inertia

Usage

Vue 3

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

const { trans, __, transChoice } = vueLang()

Component example:

<script setup lang="ts">
import { vueLang } from '@erag/lang-sync-inertia'

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

<template>
  <h1>{{ __('auth.greeting') }}</h1>
  <p>{{ trans('auth.welcome', { name: 'Amit' }) }}</p>
  <p>{{ transChoice('auth.apples', 3) }}</p>
</template>

React

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

const { trans, __, transChoice } = reactLang()

Component example:

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

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

  return (
    <div>
      <h1>{__('auth.greeting')}</h1>
      <p>{trans('auth.welcome', { name: 'Amit' })}</p>
      <p>{transChoice('auth.apples', 3)}</p>
    </div>
  )
}

Svelte

Requires @inertiajs/svelte v3 (Svelte 5).

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

const { trans, __, transChoice } = svelteLang()

Component example:

<script module lang="ts">
import { svelteLang } from '@erag/lang-sync-inertia'

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

<h1>{__('auth.greeting')}</h1>
<p>{trans('auth.welcome', { name: 'Amit' })}</p>
<p>{transChoice('auth.apples', 3)}</p>

API Reference

__(key, replaces?)

Translates a key, with optional placeholder replacement.

__('auth.login')
// → "Login"

__('auth.welcome', { name: 'Amit' })
// → "Welcome, Amit!"

__('messages.greeting.welcome_with_message', {
  name: 'Amit',
  message: 'Good to see you'
})
// lang/en/messages.php → ['greeting' => ['welcome_with_message' => 'Welcome, :name. :message']]
// → "Welcome, Amit. Good to see you"

If no matching translation key is found, the original key is returned unchanged:

__('I love programming.')
// → "I love programming."

Laravel key example:

return [
    'greeting' => [
        'name' => 'Welcome, :name',
        'welcome_with_message' => 'Welcome, :name. :message',
        'legacy_welcome' => 'Welcome, {name}',
    ],
];
__('messages.greeting.name', { name: 'dayle' })
// → "Welcome, dayle"

trans('messages.greeting.welcome_with_message', {
  name: 'dayle',
  message: 'Good to see you'
})
// → "Welcome, dayle. Good to see you"

Keys containing literal dots — such as English sentences used as translation keys — are supported. A direct lookup is attempted before dot-notation traversal, so they resolve correctly:

// lang/en/messages.php → ['Please proceed with caution, this cannot be undone.' => '...']
__('Please proceed with caution, this cannot be undone.')
// → "..."

trans(key, replaces)

Alias of __() with explicit replacement object — preferred when placeholders are always present.

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

transChoice(key, count, replaces?)

Translates a pluralized key using Laravel-style pluralization strings. The trans_choice() alias is also available.

transChoice('auth.apples', 1)
// → "There is one apple"

transChoice('auth.apples', 5)
// → "There are 5 apples"

trans_choice('auth.notifications', 0)
// → "No notifications"

trans_choice('auth.notifications', 3)
// → "3 notifications"

Laravel language file example:

return [
    'apples' => 'There is one apple|There are :count apples',
    'notifications' => '{0} No notifications|{1} One notification|[2,*] :count notifications',
];

Laravel Integration

Controller

syncLangFiles(['auth', 'dashboard']);
return Inertia::render('Dashboard');

Nested language directories can be referenced from Laravel with dot notation:

syncLangFiles('admin.users');

return Inertia::render('Admin/Users/Index');

For a file like lang/en/admin/users.php, use the full nested key path on the frontend:

__('admin.users.name')

Language file — resources/lang/en/auth.php

return [
    'greeting' => 'Hello!',
    'welcome'  => 'Welcome, :name',
    'apples'   => 'There is one apple|There are :count apples',
];

The package reads from page.props.lang automatically — no extra setup needed on the frontend.


TypeScript Types

type Replaces = Record<string, string | number>
type LangValue = string | { [key: string]: string | LangValue }
type LangObject = Record<string, LangValue>

API Entry Points

Use the framework-specific helper from the package root:

// Vue
import { vueLang } from '@erag/lang-sync-inertia'
const { trans, __ } = vueLang()

// React
import { reactLang } from '@erag/lang-sync-inertia'
const { trans, __ } = reactLang()

// Svelte
import { svelteLang } from '@erag/lang-sync-inertia'
const { trans, __ } = svelteLang()

The legacy lang() imports from the framework-specific paths (/vue, /react, or /svelte) remain supported for backward compatibility.


Package Structure

src/
├── vue/
├── react/
├── svelte/
├── types/
└── index.ts

Code of Conduct · Contributing · Security Policy


License

MIT © Amit Gupta