Skip to content
This repository was archived by the owner on Jan 3, 2019. It is now read-only.

Commit 5729112

Browse files
committed
Fix JSON loading
1 parent 1883e97 commit 5729112

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
npm install messageformat-loader
1111
```
1212

13+
You'll also need another loader (like [json-loader](https://github.com/webpack/json-loader)) to actually load the JSON strings
14+
15+
```
16+
npm install json-loader
17+
```
18+
1319
## Usage
1420

1521
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
@@ -31,7 +37,7 @@ npm install messageformat-loader
3137
### example.js
3238

3339
``` javascript
34-
var messages = require('messageformat!./messages.json');
40+
var messages = require('messageformat!json!./messages.json');
3541
messages['ordinal-example']({ N: 1 });
3642
// => 'The 1st message.'
3743
```

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
var loaderUtils = require('loader-utils');
22
var MessageFormat = require('messageformat');
33

4-
module.exports = function(source) {
4+
module.exports = function(content) {
55
var query = loaderUtils.parseQuery(this.query);
6-
var output = new MessageFormat(query.locale).compile(source).toString('module.exports');
7-
return output;
6+
var locale = query.locale || 'en';
7+
var messages = this.exec(content);
8+
var messageFunctions = new MessageFormat(locale).compile(messages).toString('module.exports');
9+
return messageFunctions;
810
};

0 commit comments

Comments
 (0)