Provides translations for an Inertia Based Project
codecng/laravel-inertia-translations is a Laravel package for provides translations for an inertia based project.
It currently has 4 GitHub stars and 525 downloads on Packagist (latest version 1.2.1).
Install it with composer require codecng/laravel-inertia-translations.
Discover more Laravel packages by codecng
or browse all Laravel packages to compare alternatives.
Last updated
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!
composer require codecng/laravel-inertia-translations
That's it! No additional configuration needed.
Whenever you add or modify translations in your Laravel application, simply run:
php artisan translate
This command will:
resources/js/lang/lang/ directoryresources/js/
├── lang/
│ ├── en.json
│ ├── es.json
│ └── fr.json
└── lib/
└── translations.(js|ts|jsx|tsx) # Based on your stack
import { __ } from '@/lib/translations'
function Welcome() {
return (
<div>
<h1>{__('welcome.title')}</h1>
<p>{__('welcome.message')}</p>
<p>{__('Users')}</p>
</div>
)
}
<script setup>
import { __ } from '@/lib/translations'
</script>
<template>
<div>
<h1>{{ __('welcome.title') }}</h1>
<p>{{ __('welcome.message') }}</p>
</div>
</template>
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(),
]);
}
When using TypeScript, you get full type support for your translation keys:
// The __ function is fully typed
__('welcome.title') // ✓ Valid
__('invalid.key') // ✗ TypeScript error
The MIT License (MIT). Please see License File for more information.