Skip to content

Commit

Permalink
Added a functionality to pass options to po2json
Browse files Browse the repository at this point in the history
  • Loading branch information
dundalek committed Dec 3, 2014
1 parent a8498dd commit 7fdf253
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -5,9 +5,20 @@
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)

``` javascript
// Use it explicitly
var messages = require("json!po!./locale/en_US/LC_MESSAGES/messages.po");

// Or add a loader into your webpack.config.js
loaders: [
{test: /\.po$/, loader: 'json!po'}
]

// And then require it like this
var messages = require("./locale/en_US/LC_MESSAGES/messages.po");
```

See [po2json](https://github.com/mikeedwards/po2json) for a list of possible options. Use the `format` option to change the output format, e.g. `json!po?format=jed`.

Locale module code:

``` coffeescript
Expand Down Expand Up @@ -41,7 +52,7 @@ module.exports =
# Try to load the locale specified by the browser. Webpack will throw an exception
# if it does not exist since it has been required with a regex. Then if the
# locale has both both parts then try to load the base language without a territory
# code (ex. 'es', 'en'). If this fails then load the default language (ex.
# code (ex. 'es', 'en'). If this fails then load the default language (ex.
# 'en_US'). If the locale is not multipart then just fallback to the default
# language. This allows for a single base language to be used without territories
# or with incomplete coverage for all territories.
Expand Down
10 changes: 9 additions & 1 deletion index.js
Expand Up @@ -3,11 +3,19 @@
Author David Schissler @dschissler
*/
var po2json = require('po2json');
var loaderUtils = require('loader-utils');

module.exports = function(source) {
this.cacheable();

jsonData = po2json.parse(source, {stringify:true});
var options = loaderUtils.parseQuery(this.query);

// default option
if (!('stringify' in options)) {
options.stringify = true;
}

jsonData = po2json.parse(source, options);

return jsonData;
}
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -19,10 +19,13 @@
}
],
"readme": "",
"readmeFilename": "README.md",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/dschissler/po-loader/issues"
},
"_id": "po-loader@0.1.0",
"_from": "po-loader@~0.1.0"
"_from": "po-loader@~0.1.0",
"dependencies": {
"loader-utils": "^0.2.5"
}
}

0 comments on commit 7fdf253

Please sign in to comment.