Skip to content

Commit b954f03

Browse files
committed
update: README.md
1 parent e2a30e9 commit b954f03

File tree

1 file changed

+60
-13
lines changed

1 file changed

+60
-13
lines changed

README.md

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
LaravelLangSyncInertia is the perfect solution for Laravel developers using Inertia.js with Vue or React. It helps you:
1010

11-
✅ Easily manage language files
12-
✅ Dynamically sync translations with Inertia.js
13-
✅ Reduce boilerplate for loading translations
14-
✅ Automatically share translations with all pages
15-
✅ Improve performance with smart caching
11+
✅ Easily manage language files
12+
✅ Dynamically sync translations with Inertia.js
13+
✅ Reduce boilerplate for loading translations
14+
✅ Automatically share translations with all pages
15+
✅ Improve performance with smart caching
1616

1717
---
1818

@@ -33,7 +33,7 @@ Install the package via Composer:
3333

3434
```bash
3535
composer require erag/laravel-lang-sync-inertia
36-
````
36+
```
3737

3838
---
3939

@@ -54,25 +54,74 @@ This publishes:
5454

5555
## 🚀 Usage
5656

57+
### 🔟 Where to Use `lang_file_load()`?
58+
59+
Call `lang_file_load()` **inside your controller method** **before returning an Inertia view**. This ensures the necessary language files are loaded and shared with the frontend.
60+
61+
---
62+
5763
### 1️⃣ Load a Single File
5864

65+
📍 **Example in Controller:**
66+
5967
```php
60-
lang_file_load('auth');
68+
use Inertia\Inertia;
69+
70+
public function index()
71+
{
72+
lang_file_load('auth'); // Load a single language file
73+
74+
return Inertia::render('Dashboard');
75+
}
6176
```
6277

78+
✅ This loads `resources/lang/{locale}/auth.php` and makes the translations available to your Vue or React component.
79+
80+
---
81+
6382
### 2️⃣ Load Multiple Files
6483

84+
📍 **Example in Controller:**
85+
86+
```php
87+
use Inertia\Inertia;
88+
89+
public function profile()
90+
{
91+
lang_file_load(['auth', 'profile']); // Load multiple files
92+
93+
return Inertia::render('Profile');
94+
}
95+
```
96+
97+
✅ This loads both `auth.php` and `profile.php` based on the active locale.
98+
99+
---
100+
101+
### 3️⃣ Load Based on Condition
102+
65103
```php
66-
lang_file_load(['auth', 'login']);
104+
use Inertia\Inertia;
105+
106+
public function show($type)
107+
{
108+
if ($type === 'admin') {
109+
lang_file_load(['admin', 'auth']);
110+
} else {
111+
lang_file_load(['user', 'auth']);
112+
}
113+
114+
return Inertia::render('UserTypePage');
115+
}
67116
```
68117

69-
These functions load translation files dynamically based on the current locale.
118+
✅ Useful when different views or modules require different translation files.
70119

71120
---
72121

73-
## 🖥️ Access in Vue/React Components
122+
## 💡 Vue/React Component Usage
74123

75-
#### ✅ Vue Example:
124+
### ✅ Vue Example:
76125

77126
```vue
78127
<template>
@@ -185,5 +234,3 @@ Licensed under the [MIT License](https://opensource.org/licenses/MIT).
185234

186235
Pull requests and issues are welcome!
187236
Let’s make localization in Laravel even better 💬
188-
189-
---

0 commit comments

Comments
 (0)