Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding jsxgettext, Created extract-pot and removed extract-po.sh

extract-pot is more general and doesn't require the developer
to hack on their own shell script.
  • Loading branch information...
commit a4ead63363770928fd3e9fa4a9940deeea0a2058 1 parent a4bbbb9
@ozten ozten authored
View
9 README.md
@@ -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"
View
23 bin/extract-po.sh
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-# syntax:
-# extract-po.sh
-
-# No -j on first line, to clear out .pot file (Issue#1170)
-
-# messages.po is server side strings
-xgettext --keyword=_ -L Perl --output-dir=locale/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot\
- `find server -name '*.js' | grep -v 'i18n.js'`
-sed -e 's/charset=CHARSET/charset=UTF-8/g' < locale/templates/LC_MESSAGES/messages.pot > messages.pot.tmp
-mv messages.pot.tmp locale/templates/LC_MESSAGES/messages.pot
-xgettext -j -L PHP --keyword=_ --output-dir=locale/templates/LC_MESSAGES --output=messages.pot `find server -name '*.ejs'`
-
-# i18n-abide supports client-side gettext too. Usually you won't need this, unless your doing some
-# fancy new fangled webapp.
-#
-# client.po, assuming you have gettext strings in your client files (.js, .ejs)
-# js
-# xgettext -L Perl --output-dir=locale/templates/LC_MESSAGES --from-code=utf-8 --output=client.pot\
-# `find client -name '*.js' | grep -v 'gettext.js'`
-# ejs
-# xgettext -j -L PHP --keyword=_ --output-dir=locale/templates/LC_MESSAGES --output=client.pot `find client -name '*.ejs'`
View
85 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);
+ }
+});
View
22 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
@@ -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.
@@ -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/
View
7 package.json
@@ -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",
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.