@@ -82,10 +82,10 @@ export default defineConfig({
8282 laravelLocalizer ({
8383 // Watch patterns for language file changes
8484 patterns: [' lang/**' , ' resources/lang/**' ],
85-
85+
8686 // Command to run when files change
8787 command: ' php artisan localizer:generate --all' ,
88-
88+
8989 // Enable debug logging (optional)
9090 debug: false ,
9191 }),
@@ -94,6 +94,7 @@ export default defineConfig({
9494```
9595
9696** What it does:**
97+
9798- Watches for changes in ` lang/** ` and ` resources/lang/** `
9899- Automatically runs ` php artisan localizer:generate --all ` when files change
99100- Triggers HMR to reload your frontend with updated translations
@@ -210,7 +211,7 @@ const itemCount = 5;
210211 <!-- Supports :placeholder format -->
211212 <p>{{ __('greeting', { name: userName }) }}</p>
212213 <!-- "Hello :name!" → "Hello John!" -->
213-
214+
214215 <!-- Also supports {placeholder} format -->
215216 <p>{{ __('items', { count: itemCount }) }}</p>
216217 <!-- "You have {count} items" → "You have 5 items" -->
@@ -232,12 +233,12 @@ const count = ref(5);
232233 <div>
233234 <!-- Define in your translation file: -->
234235 <!-- "apples": "no apples|one apple|many apples" -->
235-
236+
236237 <p>{{ choice('apples', count) }}</p>
237238 <!-- count = 0: "no apples" -->
238239 <!-- count = 1: "one apple" -->
239240 <!-- count = 5: "many apples" -->
240-
241+
241242 <!-- With replacements -->
242243 <p>{{ choice('apples', count, { count }) }}</p>
243244 <!-- "You have {count} apples" → "You have 5 apples" -->
@@ -257,13 +258,11 @@ const { __, has } = useLocalizer();
257258<template>
258259 <div>
259260 <h1 v-if="has('welcome')">{{ __('welcome') }}</h1>
260-
261+
261262 <p v-if="has('custom.message')">
262263 {{ __('custom.message') }}
263264 </p>
264- <p v-else>
265- Default message
266- </p>
265+ <p v-else>Default message</p>
267266 </div>
268267</template>
269268```
@@ -299,13 +298,9 @@ const { locale, dir, availableLocales } = useLocalizer();
299298 <div :dir="dir">
300299 <p>Current Locale: {{ locale }}</p>
301300 <p>Text Direction: {{ dir }}</p>
302-
301+
303302 <select :value="locale">
304- <option
305- v-for="(meta, code) in availableLocales"
306- :key="code"
307- :value="code"
308- >
303+ <option v-for="(meta, code) in availableLocales" :key="code" :value="code">
309304 {{ meta.flag }} {{ meta.label }}
310305 </option>
311306 </select>
@@ -323,10 +318,7 @@ const { __, dir } = useLocalizer();
323318</script>
324319
325320<template>
326- <div
327- :dir="dir"
328- :class="dir === 'rtl' ? 'text-right' : 'text-left'"
329- >
321+ <div :dir="dir" :class="dir === 'rtl' ? 'text-right' : 'text-left'">
330322 <h1>{{ __('welcome') }}</h1>
331323 <p>{{ __('description') }}</p>
332324 </div>
@@ -356,17 +348,17 @@ const { translations } = useLocalizer();
356348
357349Returns an object with the following properties and methods:
358350
359- | Property | Type | Description |
360- | ----------| ------| -------------|
361- | ` __ ` | ` (key: string, replacements?: Replacements, fallback?: string) => string ` | Main translation function |
362- | ` trans ` | ` (key: string, replacements?: Replacements, fallback?: string) => string ` | Alias for ` __() ` |
363- | ` lang ` | ` (key: string, replacements?: Replacements, fallback?: string) => string ` | Alias for ` __() ` |
364- | ` has ` | ` (key: string) => boolean ` | Check if translation key exists |
365- | ` choice ` | ` (key: string, count: number, replacements?: Replacements) => string ` | Pluralization support |
366- | ` locale ` | ` ComputedRef<string> ` | Reactive current locale code |
367- | ` dir ` | ` ComputedRef<'ltr' \| 'rtl'> ` | Reactive text direction |
368- | ` availableLocales ` | ` ComputedRef<Record<string, LocaleMeta>> ` | Reactive available locales |
369- | ` translations ` | ` ComputedRef<Record<string, string>> ` | Reactive all translations |
351+ | Property | Type | Description |
352+ | ------------------ | ------------------------------------------------------------------------- | ------------------------------- |
353+ | ` __ ` | ` (key: string, replacements?: Replacements, fallback?: string) => string ` | Main translation function |
354+ | ` trans ` | ` (key: string, replacements?: Replacements, fallback?: string) => string ` | Alias for ` __() ` |
355+ | ` lang ` | ` (key: string, replacements?: Replacements, fallback?: string) => string ` | Alias for ` __() ` |
356+ | ` has ` | ` (key: string) => boolean ` | Check if translation key exists |
357+ | ` choice ` | ` (key: string, count: number, replacements?: Replacements) => string ` | Pluralization support |
358+ | ` locale ` | ` ComputedRef<string> ` | Reactive current locale code |
359+ | ` dir ` | ` ComputedRef<'ltr' \| 'rtl'> ` | Reactive text direction |
360+ | ` availableLocales ` | ` ComputedRef<Record<string, LocaleMeta>> ` | Reactive available locales |
361+ | ` translations ` | ` ComputedRef<Record<string, string>> ` | Reactive all translations |
370362
371363** Note:** Unlike React, ` locale ` , ` dir ` , ` availableLocales ` , and ` translations ` are ` ComputedRef ` values, making them fully reactive in Vue.
372364
@@ -375,13 +367,13 @@ Returns an object with the following properties and methods:
375367``` typescript
376368interface LocalizerOptions {
377369 // Watch patterns for language file changes
378- patterns? : string []; // default: ['lang/**', 'resources/lang/**']
379-
370+ patterns? : string []; // default: ['lang/**', 'resources/lang/**']
371+
380372 // Command to run when files change
381- command? : string ; // default: 'php artisan localizer:generate --all'
382-
373+ command? : string ; // default: 'php artisan localizer:generate --all'
374+
383375 // Enable debug logging
384- debug? : boolean ; // default: false
376+ debug? : boolean ; // default: false
385377}
386378```
387379
@@ -390,12 +382,12 @@ interface LocalizerOptions {
390382The package is written in TypeScript and provides full type definitions:
391383
392384``` typescript
393- import {
394- useLocalizer ,
385+ import {
386+ useLocalizer ,
395387 UseLocalizerReturn ,
396388 Replacements ,
397389 LocaleData ,
398- PageProps
390+ PageProps ,
399391} from ' @devwizard/laravel-localizer-vue' ;
400392
401393// All types are available for import
@@ -436,15 +428,8 @@ const changeLocale = (newLocale: string) => {
436428</script>
437429
438430<template>
439- <select
440- :value="locale"
441- @change="changeLocale($event.target.value)"
442- >
443- <option
444- v-for="(meta, code) in availableLocales"
445- :key="code"
446- :value="code"
447- >
431+ <select :value="locale" @change="changeLocale($event.target.value)">
432+ <option v-for="(meta, code) in availableLocales" :key="code" :value="code">
448433 {{ meta.flag }} {{ meta.label }}
449434 </option>
450435 </select>
@@ -479,15 +464,15 @@ const submit = () => {
479464 {{ form.errors.email }}
480465 </span>
481466 </div>
482-
467+
483468 <div>
484469 <label>{{ __('auth.password') }}</label>
485470 <input v-model="form.password" type="password" required />
486471 <span v-if="form.errors.password" class="error">
487472 {{ form.errors.password }}
488473 </span>
489474 </div>
490-
475+
491476 <button type="submit" :disabled="form.processing">
492477 {{ __('auth.login') }}
493478 </button>
@@ -650,11 +635,7 @@ const switchLocale = (newLocale: string) => {
650635 @change="switchLocale(($event.target as HTMLSelectElement).value)"
651636 class="block w-full px-3 py-2 border border-gray-300 rounded-md"
652637 >
653- <option
654- v-for="(meta, code) in availableLocales"
655- :key="code"
656- :value="code"
657- >
638+ <option v-for="(meta, code) in availableLocales" :key="code" :value="code">
658639 {{ meta.flag }} {{ meta.label }}
659640 </option>
660641 </select>
@@ -663,14 +644,13 @@ const switchLocale = (newLocale: string) => {
663644```
664645
665646** What happens:**
647+
6666481 . User changes locale in dropdown
6676492 . Page reloads with ` ?locale=fr ` parameter
6686503 . Laravel middleware detects locale and updates session
6696514 . Vue components re-render with new translations
6706525 . Text direction automatically adjusts for RTL languages
671653
672-
673-
674654## Development
675655
676656``` bash
0 commit comments