Search by

abetwothree / lang-export

abetwothree

Export your Laravel translation files as JSON for Vue, React, & Svelte with @tolki/lang

Package info

github.com/abetwothree/laravel-lang-export

Homepage

pkg:composer/abetwothree/lang-export

Fund package maintenance!

AbeTwoThree

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-10-29 04:41 UTC

This package is auto-updated.

Last update: 2026-10-29 13:14:23 UTC


README

Latest Version on Packagist Laravel Compatibility PHP Compatibility GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package writes your Laravel translations to one JSON file per locale. It reads every file through Laravel's own translation loader, so the JSON holds the same lines __() returns.

It is the Laravel side of @tolki/lang, a JavaScript port of Laravel's translator from Tolki. @tolki/lang does not read lang files itself. It takes the JSON this package writes.

Installation

composer require abetwothree/lang-export
npm install @tolki/lang

Optionally publish the config file:

php artisan vendor:publish --tag="lang-export-config"

Exporting

php artisan lang:export

This writes resources/js/lang/{locale}.json for each locale, plus a manifest.json that lists the locales and the lang directories they came from. PHP groups become nested objects, JSON lines stay at the top level, and a package's groups sit under namespace::group keys:

{
    "Welcome": "Welcome",
    "auth": {
        "failed": "These credentials do not match our records."
    },
    "courier::mail": {
        "sent": "Your message was sent."
    }
}

Pass --locale, --only, --except or --output to narrow a run, or set them in config/lang-export.php.

Re-exporting one file

php artisan lang:export --source=lang/en/auth.php

--source re-exports one changed lang file and updates its locale's JSON file. File watchers call it on every save.

Vite plugin

The Vite plugin in @tolki/lang runs the export for you. It exports when vite dev starts and before vite build, re-exports each lang file you save, and serves the locales as the virtual:tolki-lang module.

// vite.config.ts
import laravelLangExport from "@tolki/lang/vite-laravel";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [laravelLangExport()],
});
import { createLang } from "@tolki/lang";
import { load } from "virtual:tolki-lang";

const lang = createLang({ locale: "en", fallback: "en", load });
await lang.ready;

lang.__("auth.failed");
// => "These credentials do not match our records."

Vue, React and Svelte plugins

@tolki/lang has a native plugin for each framework. Each one hands the lang to your components and re-renders them when the locale changes. All three work with Inertia, server-side rendering included.

  • @tolki/lang/vue installs into a Vue 3.5 app. Templates get __, trans and transChoice, and useLang() gives a locale you can bind with v-model.
  • @tolki/lang/react gives React 19 a <LangProvider> and a useLang() hook.
  • @tolki/lang/svelte passes the lang to Svelte 5.7 components through context, with setLang() and getLang().

Key capabilities

  • Package namespaces and lang/vendor overrides, resolved as Laravel resolves them
  • Extra lang paths, JSON paths and namespaces for modular apps
  • Locale filtering, plus allow and deny patterns for groups
  • Single-file re-export with --source for file watchers
  • Laravel's own validation, auth, pagination and password lines included
  • Skips rewriting locale files whose lines did not change
  • Overlapping runs wait for each other instead of overwriting each other's files

Documentation

The Tolki localization docs cover usage in depth:

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.