Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b072f8c

Browse files
Added usage doc and test case.
1 parent d5fc380 commit b072f8c

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

‎README.md‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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
77
npm 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
```

‎tests/loader.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function runWebpack(config) {
2525
module: {
2626
rules: [
2727
{
28-
test: /resources\/lang.+\.php$/,
28+
test: /resources\/lang.+\.(php|json)$/,
2929
loader: 'laravel-localization-loader',
3030
}
3131
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /