Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Adding jsxgettext, Created extract-pot and removed extract-po.sh
Browse files Browse the repository at this point in the history
extract-pot is more general and doesn't require the developer
to hack on their own shell script.
  • Loading branch information
ozten committed Jul 31, 2012
1 parent a4bbbb9 commit a4ead63
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 41 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -59,14 +59,15 @@ i18n-abide provides ``lib/gettext.js`` and you can do the same in ``.js`` and ``
## Setup Gettext

$ mkdir -p locale/templates/LC_MESSAGES
# Get a local copy of extract-po.sh, and edit to to match your source code layout
$ cp node_modules/i18n-abide/bin/extract-po.sh bin/
$ emacs bin/extract-po.sh (or vim or whatever)
$ ./bin/extract-po.sh
$ ./node_modules/.bin/extract-pot --locale locale ./server

If you look in ``locale/templates/LC_MESSAGES/messages.pot`` you will see your strings have been extracted.
Edit this file and make sure ``charset`` is set to ``UTF-8``.

If there are certain files or directories you want to exclude, use `--exclude` one or more times. Example:

$ extract-pot --locale locale ./server --exclude tests --exclude examples

Example messages.pot:

"Content-Type: text/plain; charset=UTF-8\n"
Expand Down
23 changes: 0 additions & 23 deletions bin/extract-po.sh

This file was deleted.

85 changes: 85 additions & 0 deletions bin/extract-pot
@@ -0,0 +1,85 @@
#!/usr/bin/env node
var async = require('async'),
exec = require('child_process').exec,
path = require('path'),
util = require('util');

// ./scripts/extract-pot --locale locale server static
// Given a locale directory to write out pot files and
// 1 or more directories to find sources in, run
// .js and .ejs files through jsxgettext

var argv = require('optimist').demand(['l'])
.usage('Extract gettext strings from codebase. Usage: $0 --locale=DIRECTORY INPUT_DIR [INPUT_DIR]*')
.alias('h', 'help')
.describe('h', 'display this usage message')
.alias('l', 'locale')
.describe('l', 'locale directory where pot and po files will be written')
//.alias('e', 'exclude')
.describe('exclude', 'directory or filename pattern to exclude from jsxgettext\n\t\tmay be used multiple times')
.check(function (argv) {
// We have atleast one directory of source code to process
return argv._.length >= 1;
})
.argv;

var localeDir = path.resolve(process.cwd(), argv.locale);

var sourceDirs = [];

argv._.forEach(function (dir) {
sourceDirs.push(path.resolve(process.cwd(), dir));
});

// top of repo is our current working directory
process.chdir(path.dirname(__dirname));

var jsCmd = './node_modules/.bin/jsxgettext %s --keyword=_ -L JS ' +
'--output-dir=%s/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot ' +
'`find %s -name \'*.js\' | grep -v node_modules | grep -v .git';

var ejsCmd = './node_modules/.bin/jsxgettext %s --keyword=_ -L EJS ' +
'--output-dir=%s/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot ' +
'`find %s -name \'*.ejs\' | grep -v node_modules | grep -v .git';

if (argv.exclude) {
var excludes = argv.exclude;
if ('string' === typeof argv.exclude) {
excludes = [argv.exclude];
}
excludes.forEach(function (exclude) {
jsCmd += ' | grep -v ' + exclude;
ejsCmd += ' | grep -v ' + exclude;
});
}
// Close out `find ...` backtick
jsCmd += '`';
ejsCmd += '`';

// Create a new .pot file
var dashJ = '';

// Run commands
async.forEachSeries(sourceDirs, function (dir) {
exec(util.format(jsCmd, dashJ, localeDir, dir), function (err, stdout, stderr) {
// Join existing pot file
dashJ = '--join-existing=true';

if (err) {
console.error(err);
} else {
exec(util.format(ejsCmd, dashJ, localeDir, dir), function (err, stdout, stderr) {
if (err) {
console.log(util.format(ejsCmd, dashJ, localeDir, dir));
console.error(err);
}

});
}
});
}, function (err) {
console.log('===========');
if (err) {
console.error(err);
}
});
22 changes: 10 additions & 12 deletions docs/L10n_README.md
@@ -1,9 +1,12 @@
These po files are scripts are for the BrowserID project and work along
with scripts from the browserid github repo under the scripts directory.
This directory contains .po files and scripts for working with those files.

scripts/extract-po.sh - Creates template POT file
To extract .pot template files, use [i18n-abide extract-pot command](https://github.com/mozilla/i18n-abide)

This script examines EJS and JavaScript files for strings, extracts them, and puts them into POT files.
node_modules/.bin/extract-pot - Creates template POT file

That command examines EJS and JavaScript files for strings, extracts them, and puts them into POT files.

Once you have done this, you can use the following shell scripts:

scripts/merge-po.sh - Takes new or changed strings and updates PO files

Expand All @@ -12,20 +15,15 @@ Additionally, if possible, generates a db_LB language translation.
locale/compile-mo.sh - Compiles PO to MO files
locale/compile-json.sh - Compiles PO to JSON files

# Installation:

git clone git://github.com/mozilla/browserid.git
cd browserid
svn co https://svn.mozilla.org/projects/l10n-misc/trunk/browserid/locale

BrowserID has one unique differnce than a typical Mozilla website, the
For some of our apps the
PO files are also converted into JSON files using po2json.js.

po2json.js depends on Node.js. To install Node, see node.js.org

po2json.js is compatible with po2json.pl if you'd rather use that Perl based tool.

If you don't have xgettext, msginit, or msgmerge, please install gettext also.
If you don't have msginit, or msgmerge, please install gettext also.

There is a debugging locale db-LB (David Bowie Labyrinth) which gets updated
via podebug. Optionally Install translate-toolkit to update this locale.
Expand All @@ -36,7 +34,7 @@ You should now have a complete environment for working with strings.

git fetch upstream
git checkout train-YYYY.MM.DD
./scripts/extract-po.sh
./node_modules/.bin/extract-pot -l locale --exclude tests ./server
./scripts/merge-po.sh locale/

./locale/compile-json.sh locale/ resources/static/i18n/
Expand Down
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Austin King <shout@ozten.com> (http://ozten.com)",
"name": "i18n-abide",
"description": "Express/connect module for Node i18n and l10n support",
"version": "0.0.5",
"version": "0.0.4",
"homepage": "https://github.com/mozilla/i18n-abide",
"repository": {
"type": "git",
Expand All @@ -16,7 +16,10 @@
"node": ">= 0.6.2"
},
"dependencies": {
"node-gettext": "0.2.7"
"async": "0.1.22",
"jsxgettext": "0.0.4",
"node-gettext": "0.1.2",
"optimist": "0.3.4"
},
"devDependencies": {
"vows": "0.5.13"
Expand Down

0 comments on commit a4ead63

Please sign in to comment.