Download the PHP package nvl/laravel-typescript-translations without Composer
On this page you can find all versions of the php package nvl/laravel-typescript-translations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nvl/laravel-typescript-translations
More information about nvl/laravel-typescript-translations
Files in nvl/laravel-typescript-translations
Package laravel-typescript-translations
Short Description Generate TypeScript type definitions from Laravel translation files
License MIT
Informations about the package laravel-typescript-translations
Laravel TypeScript Translations
Generate TypeScript types and translation data from Laravel translation files. Load only what you need, when you need it.
Table of Contents
- The Problem This Solves
- Installation
- Quick Start
- Understanding the Two Approaches
- Mode Comparison
- Type Generation
- Translation Export
- Hook Usage
- use-inertia-translations (Backend)
- use-local-translations (Frontend)
- Laravel Integration
- Configuration Options
- Performance
- License
The Problem This Solves
In Laravel + TypeScript apps, you typically have:
- Massive translation bundles - Loading all translations for all languages on every page
- No type safety - Typos in translation keys only discovered at runtime
- Poor performance - Sending unused translations over the wire
This package solves all three by:
- Generating TypeScript types from your Laravel translations
- Exporting translation data in a modular, tree-shakeable format
- Providing hooks for both backend-driven and frontend-driven translations
- Enabling fine-grained control over what translations load where
Installation
Publish the configuration:
Quick Start
Understanding the Two Approaches
This package supports two distinct approaches for handling translations:
1. Backend-Driven (use-inertia-translations)
- Server sends specific translations for current page
- Only current locale
- Smaller payload
- No client-side locale switching
- Type-safe with generated interfaces
2. Frontend-Driven (use-local-translations)
- Client loads translation modules
- All locales available
- Larger initial payload
- Dynamic locale switching
- Tree-shakeable modules
Mode Comparison
Type Generation Modes
| Mode | Output Structure | File Count | Use Case |
|---|---|---|---|
| Single | translations.d.ts |
1 file | Small projects (< 10 translation files) |
| Module | vendors.types.d.ts, tasks.types.d.ts |
1 per source | Recommended - Balanced approach |
| Granular | vendors/actions.types.d.ts, vendors/forms.types.d.ts |
1 per file | Large projects needing maximum control |
Single Mode Structure
Module Mode Structure
Granular Mode Structure
Translation Export Modes
| Mode | Output Structure | Bundle Impact | Use Case |
|---|---|---|---|
| Single | translations.ts |
No tree-shaking | Small projects |
| Module | vendors.translations.ts with multiple exports |
Good tree-shaking | Recommended |
| Granular | vendors/actions.ts, vendors/forms.ts |
Best tree-shaking | Large projects |
Module Mode Exports
Type Generation
Generate TypeScript types from your Laravel translations:
Options
| Option | Values | Description |
|---|---|---|
--mode |
single, module, granular | Output structure |
--locale |
en,bg,de | Specific locales to scan |
--fresh |
- | Clear cache before generation |
--debug |
- | Show detailed output |
Translation Export
Export actual translation data for frontend usage:
Options
| Option | Values | Description |
|---|---|---|
--mode |
single, module, granular | File structure |
--organize-by |
locale-mapped, locale, module | How to organize locales |
--locale |
en,bg,de | Specific locales only |
--format |
typescript, json | Output format |
--output |
path/to/dir | Custom output directory |
Hook Usage
use-inertia-translations (Backend)
For server-driven translations passed via Inertia props:
Pros:
- Minimal payload (only current locale, only needed keys)
- Type-safe with backend contract
- No unused translations sent
Cons:
- No client-side locale switching
- Requires backend changes for new translations
use-local-translations (Frontend)
For client-side translations with locale switching:
Pros:
- Client-side locale switching
- No backend changes needed
- Tree-shakeable (import only needed modules)
Cons:
- Larger bundle (all locales)
- All translations exposed to client
Combining Both Approaches
Use backend translations for initial render, client translations for dynamic features:
Laravel Integration
Middleware (Global Translations)
Only share truly global translations:
Controllers (Page-Specific)
Send only what the page needs:
Configuration Options
Complete Configuration Reference
Environment Variables
Control behavior via .env:
Per-Environment Configuration
Performance
Bundle Size Comparison
| Approach | Initial Load | Locale Switch | Tree-Shaking |
|---|---|---|---|
| Backend (Inertia) | ~5KB per page | Page reload | N/A |
| Frontend (All) | ~200KB | Instant | ❌ |
| Frontend (Modular) | ~20KB per module | Instant | ✅ |
| Frontend (Dynamic) | 0KB | Lazy load | ✅ |
Optimization Strategies
- Development: Use all translations for convenience
- Production: Use backend translations + dynamic imports
- Hybrid: Backend for SSR, frontend for interactive features
Lazy Loading Example
License
MIT. See LICENSE.md for details.
All versions of laravel-typescript-translations with dependencies
illuminate/console Version ^12.0
illuminate/support Version ^12.0
illuminate/filesystem Version ^12.0