File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 11<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 >
33
44## Installation
55
66``` shell
77npm install laravel-localization-loader
88```
99
10- ### Usage
10+ ## Configuration
1111
12- #### Webpack 2
12+ ### Webpack 2
1313
1414``` js
1515// webpack.config.js
@@ -19,16 +19,39 @@ module.exports = {
1919 rules: [
2020 {
2121 // Matches all PHP files in `resources/lang` directory.
22- test: / resources\/ lang. + \. php$ / ,
22+ test: / resources\/ lang. + \. ( php| json) $ / ,
2323 loader: ' laravel-localization-loader' ,
2424 }
2525 ]
2626 },
2727 // ...
2828}
2929```
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+
3053## Test
3154
3255``` shell
33- npm run test
56+ yarn test
3457```
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function runWebpack(config) {
2525 module : {
2626 rules : [
2727 {
28- test : / r e s o u r c e s \/ l a n g .+ \. p h p $ / ,
28+ test : / r e s o u r c e s \/ l a n g .+ \. ( p h p | j s o n ) $ / ,
2929 loader : 'laravel-localization-loader' ,
3030 }
3131 ]
You can’t perform that action at this time.
0 commit comments