Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a functionality to pass options to po2json #2

Merged
merged 1 commit into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
}
}