11# @devwizard/laravel-localizer-vue
22
3- 🌍 Vue 3 integration for Laravel Localizer with Vite plugin, ` useTranslation ` composable, and automatic TypeScript generation.
3+ 🌍 Vue 3 integration for Laravel Localizer with Vite plugin, ` useLocalizer ` composable, and automatic TypeScript generation.
44
55## Features
66
77- ✅ ** Automatic Generation** : Vite plugin watches for language file changes and regenerates TypeScript files
88- ✅ ** Type-Safe** : Full TypeScript support with auto-generated types
9- - ✅ ** Vue 3 Composition API** : Intuitive ` useTranslation ` composable for Vue components
9+ - ✅ ** Vue 3 Composition API** : Intuitive ` useLocalizer ` composable for Vue components
10+ - ✅ ** Customizable Path** : By default reads from ` @/lang ` folder, customizable via options
1011- ✅ ** Laravel-Compatible** : Matches Laravel's translation API (` __ ` , ` trans ` , ` choice ` )
1112- ✅ ** Inertia.js Integration** : Seamlessly works with Inertia.js page props
1213- ✅ ** RTL Support** : Built-in right-to-left language support
@@ -26,12 +27,42 @@ yarn add @devwizard/laravel-localizer-vue
2627
2728``` bash
2829composer require devwizardhq/laravel-localizer
29- php artisan localizer:install --framework=vue
30+ php artisan localizer:install
3031```
3132
33+ The install command will:
34+ - ✅ Publish configuration files
35+ - ✅ Create default locale files
36+ - ✅ Install npm package (optional)
37+ - ✅ Generate initial TypeScript files
38+
39+ ** Note:** You'll need to manually add the bootstrap setup (see step 1 below).
40+
3241## Setup
3342
34- ### 1. Add Vite Plugin
43+ ### 1. Initialize Translations in Bootstrap
44+
45+ Add this to your ` resources/js/bootstrap.ts ` :
46+
47+ ``` typescript
48+ import { translations } from ' @/lang' ;
49+
50+ declare global {
51+ interface Window {
52+ localizer? : {
53+ translations: Record <string , Record <string , string >>;
54+ };
55+ }
56+ }
57+
58+ window .localizer = {
59+ translations ,
60+ };
61+ ```
62+
63+ This makes translations available globally and synchronously.
64+
65+ ### 2. Add Vite Plugin
3566
3667Update your ` vite.config.ts ` :
3768
@@ -47,10 +78,15 @@ export default defineConfig({
4778 debug: true , // Enable debug logging (optional)
4879 }),
4980 ],
81+ resolve: {
82+ alias: {
83+ ' @' : ' /resources/js' ,
84+ },
85+ },
5086});
5187```
5288
53- ### 2 . Generate Translation Files
89+ ### 3 . Generate Translation Files
5490
5591``` bash
5692php artisan localizer:generate --all
@@ -64,9 +100,9 @@ This creates TypeScript files in `resources/js/lang/` directory.
64100
65101``` vue
66102<script setup lang="ts">
67- import { useTranslation } from '@devwizard/laravel-localizer-vue';
103+ import { useLocalizer } from '@devwizard/laravel-localizer-vue';
68104
69- const { __ } = useTranslation ();
105+ const { __ } = useLocalizer ();
70106</script>
71107
72108<template>
@@ -81,9 +117,9 @@ const { __ } = useTranslation();
81117
82118``` vue
83119<script setup lang="ts">
84- import { useTranslation } from '@devwizard/laravel-localizer-vue';
120+ import { useLocalizer } from '@devwizard/laravel-localizer-vue';
85121
86- const { __ } = useTranslation ();
122+ const { __ } = useLocalizer ();
87123const userName = 'John';
88124</script>
89125
@@ -99,9 +135,9 @@ const userName = 'John';
99135
100136``` vue
101137<script setup lang="ts">
102- import { useTranslation } from '@devwizard/laravel-localizer-vue';
138+ import { useLocalizer } from '@devwizard/laravel-localizer-vue';
103139
104- const { choice } = useTranslation ();
140+ const { choice } = useLocalizer ();
105141const itemCount = ref(5);
106142</script>
107143
@@ -114,9 +150,9 @@ const itemCount = ref(5);
114150
115151``` vue
116152<script setup lang="ts">
117- import { useTranslation } from '@devwizard/laravel-localizer-vue';
153+ import { useLocalizer } from '@devwizard/laravel-localizer-vue';
118154
119- const { dir, locale } = useTranslation ();
155+ const { dir, locale } = useLocalizer ();
120156</script>
121157
122158<template>
@@ -130,9 +166,9 @@ const { dir, locale } = useTranslation();
130166
131167``` vue
132168<script setup lang="ts">
133- import { useTranslation } from '@devwizard/laravel-localizer-vue';
169+ import { useLocalizer } from '@devwizard/laravel-localizer-vue';
134170
135- const { __, has } = useTranslation ();
171+ const { __, has } = useLocalizer ();
136172</script>
137173
138174<template>
@@ -146,9 +182,9 @@ const { __, has } = useTranslation();
146182
147183``` vue
148184<script setup lang="ts">
149- import { useTranslation } from '@devwizard/laravel-localizer-vue';
185+ import { useLocalizer } from '@devwizard/laravel-localizer-vue';
150186
151- const { translations, locale } = useTranslation ();
187+ const { translations, locale } = useLocalizer ();
152188
153189// translations and locale are reactive ComputedRefs
154190// They automatically update when the locale changes
@@ -164,7 +200,7 @@ const { translations, locale } = useTranslation();
164200
165201## API Reference
166202
167- ### ` useTranslation ()`
203+ ### ` useLocalizer ()`
168204
169205Returns an object with the following properties and methods:
170206
@@ -185,17 +221,14 @@ Returns an object with the following properties and methods:
185221
186222``` typescript
187223laravelLocalizer ({
224+ // Watch patterns for language file changes (relative to project root)
225+ patterns: [' lang/**' , ' resources/lang/**' ],
226+
188227 // Command to run when lang files change
189228 command: ' php artisan localizer:generate --all' ,
190229
191- // Watch paths for changes
192- watch: [' lang/**' , ' resources/lang/**' ],
193-
194230 // Enable debug logging
195231 debug: false ,
196-
197- // Debounce delay in milliseconds
198- debounce: 300 ,
199232});
200233```
201234
0 commit comments