laravel-inertia-translations maintained by codecng
Description
Provides translations for an Inertia Based Project
Author
Last update
2026/07/08 03:13
(dev-main)
License
Downloads
555
Tags
Laravel Inertia Translations
A zero-configuration Laravel package that automatically exports your Laravel translations for use with Inertia.js. Supports both React and Vue, with full TypeScript support!
Installation
composer require codecng/laravel-inertia-translations
That's it! No additional configuration needed.
Usage
Whenever you add or modify translations in your Laravel application, simply run:
php artisan translate
This command will:
- Check if language files exist (if not, it will publish them automatically)
- Process all your translation files (both JSON and PHP)
- Generate JSON translation files in
resources/js/lang/ - Create appropriate utility files based on your stack (React/Vue + TypeScript)
What Gets Processed
- ✅ JSON files in
lang/directory - ✅ PHP files in language subdirectories
- ✅ Automatically merges all translations by locale
Generated Files Structure
resources/js/
├── lang/
│ ├── en.json
│ ├── es.json
│ └── fr.json
└── lib/
└── translations.(js|ts|jsx|tsx) # Based on your stack
Framework Support
React
import { __ } from '@/lib/translations'
function Welcome() {
return (
<div>
<h1>{__('welcome.title')}</h1>
<p>{__('welcome.message')}</p>
<p>{__('Users')}</p>
</div>
)
}
Vue
<script setup>
import { __ } from '@/lib/translations'
</script>
<template>
<div>
<h1>{{ __('welcome.title') }}</h1>
<p>{{ __('welcome.message') }}</p>
</div>
</template>
Inertia Setup
Make sure to include the current language in your Inertia shared props (in your HandleInertiaRequests middleware):
public function share(Request $request): array
{
return array_merge(parent::share($request), [
'language' => request()->user()->language ?? app()->getLocale(),
]);
}
Type Support
When using TypeScript, you get full type support for your translation keys:
// The __ function is fully typed
__('welcome.title') // ✓ Valid
__('invalid.key') // ✗ TypeScript error
Benefits
- 🚀 Zero configuration required
- 🔄 Simple one-command updates
- 🛠 Works with both JSON and PHP translation files
- 💪 Full TypeScript support
- ⚡️ Supports both React and Vue
- 🔍 Automatic type generation for translation keys
Credits
License
The MIT License (MIT). Please see License File for more information.