Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
handlebars-xgettext
Advanced tools
Extract strings from Handlebars source.
xgettext(1)
replacement for Handlebars templates.
tl;dr Get translatable strings from templates into Poedit.
When creating Handlebars templates that require translatable strings, you probably set up a helper similar to this:
Handlebars.registerHelper('_', function(msgid) {
return i18n.gettext(msgid);
});
What this i18n object refers to is up to you. For server-side templates it is best to use a gettext implementation that reads binary gettext sources (MO files, see below). node-gettext is a good option in that case.
For client-side templates you probably need to read from JSON data, Jed can do that.
Independent from the gettext implementation, your templates can contain translatable strings like so:
<button>{{_ "Sign in"}}</button>
<!-- and a simple plural example: -->
<p>{{count}} {{ngettext "country" "countries" count}}</p>
Now, you need to get these strings into a translation application. This is where handlebars-xgettext comes in. It generates gettext (PO) files by parsing these strings out of your templates. It are these PO files that are read by translation applications. The most common of them: Poedit.
These applications should both generate PO and binary MO files as the end result. These files are then typically passed to your i18n library.
Install handlebars-xgettext globally:
$ npm install -g handlebars-xgettext
Configure Poedit under File - Preferences... by adding a new parser in the Parsers tab with these settings:
Please note that in this Windows example you have to use handlebars-xgettext.cmd
, while the extension should of course not be there on *nix platforms.
You can of course use handlebars-xgettext independent from a translation application.
$ handlebars-xgettext [OPTION] [INPUTFILE]...
-D|--directory
add directory to list for input files search.-o|--output
write output to specified file (default stdout).--from-code
encoding of input files (default ascii
).-k|--keyword
additional keyword to be looked for (default _,gettext,ngettext:1,2
).--force-po
write PO file even if empty (default false
).--no-location
don't add file and line references (default false
).npm test
or grunt
to run tests.grunt watch
to watch for file changes and run tests.Pull requests and issues are greatly appreciated ;-)
handlebars-xgettext initial development was founded by Dijiwan.
Copyright (c) 2012 Guillaume Marty
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Extract strings from Handlebars source
We found that handlebars-xgettext demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.