1
1
<h1 align =" center " >Laravel localization Loader</h1 >
2
- <p align =" center " >Laravel localization Loader for webpack . Convert Laravel Translation strings to JavaScript Objects.</p >
2
+ <p align =" center " >Laravel localization Loader for Webpack . Convert Laravel Translation files (php or json) to JavaScript Objects.</p >
3
3
4
4
## Installation
5
5
6
6
``` shell
7
7
npm install laravel-localization-loader
8
8
```
9
9
10
- ### Usage
10
+ ##Configuration
11
11
12
- #### Webpack 2
12
+ ### Webpack 2
13
13
14
14
``` js
15
15
// webpack.config.js
@@ -19,16 +19,39 @@ module.exports = {
19
19
rules: [
20
20
{
21
21
// Matches all PHP files in `resources/lang` directory.
22
- test: / resources\/ lang. + \. php$ / ,
22
+ test: / resources\/ lang. + \. ( php| json) $ / ,
23
23
loader: ' laravel-localization-loader' ,
24
24
}
25
25
]
26
26
},
27
27
// ...
28
28
}
29
29
```
30
+
31
+ ## Usage with Lang.js
32
+
33
+ ``` js
34
+ // messages.js
35
+ export default {
36
+ // The key format should be: 'locale.filename'.
37
+ ' en.messages' : require (' ../../resources/lang/en/messages.php' ),
38
+ ' es.messages' : require (' ../../resources/lang/es/messages.php' ),
39
+ ' en.auth' : require (' ../../resources/lang/en/auth.php' ),
40
+ ' es.auth' : require (' ../../resources/lang/es/auth.php' ),
41
+ }
42
+ ```
43
+
44
+ ``` js
45
+ // page.js
46
+ import Lang from ' lang.js'
47
+ import messages from ' ./messages'
48
+
49
+ const lang = new Lang ({ messages })
50
+ lang .get (' messages.hello' )
51
+ ```
52
+
30
53
## Test
31
54
32
55
``` shell
33
- npm run test
56
+ yarn test
34
57
```
0 commit comments