From a725d667e4ce537404006037d1d72a7c5fd6a1d7 Mon Sep 17 00:00:00 2001
From: Austin King <shout@ozten.com>
Date: Tue, 10 Jan 2012 11:01:07 -0800
Subject: [PATCH] Bug#706572 Adding i18n support to BrowserID

Adding i18n to wsapi. Split strings into client.po and messages.po.

Switched email from mustache to EJS templates.

Created fake locale db-LB for development and debugging.

Updated scripts.
See http://viewvc.svn.mozilla.org/vc?view=revision&revision=99911
---
 bin/browserid                                 |    8 +
 bin/dbwriter                                  |    7 +
 docs/I18N.md                                  |   63 +
 docs/ORGANIZATION.md                          |    6 +-
 docs/TESTING.md                               |    5 +
 lib/browserid/prove_template.ejs              |   10 +
 lib/browserid/prove_template.txt              |    9 -
 lib/browserid/views.js                        |   12 +
 lib/configuration.js                          |   11 +-
 lib/email.js                                  |   26 +-
 lib/http_forward.js                           |    7 +-
 lib/i18n.js                                   |  236 +++
 lib/wsapi/stage_email.js                      |    9 +-
 lib/wsapi/stage_user.js                       |   13 +-
 .../static/dialog/views/authenticate.ejs      |   38 +-
 .../static/dialog/views/confirm_email.ejs     |   14 +-
 resources/static/dialog/views/pick_email.ejs  |   10 +-
 resources/static/i18n/db_LB/client.json       |  124 ++
 resources/static/i18n/db_LB/messages.json     |  140 ++
 resources/static/i18n/en_US/client.json       |  125 ++
 resources/static/i18n/en_US/messages.json     |  140 ++
 resources/static/i18n/pl/messages.json        |  188 +++
 resources/static/include.js                   |    2 +-
 resources/static/shared/gettext.js            | 1265 +++++++++++++++++
 resources/static/shared/renderer.js           |   13 +-
 resources/views/add_email_address.ejs         |   36 +-
 resources/views/dialog.ejs                    |    4 +-
 resources/views/dialog_layout.ejs             |   10 +-
 .../test/index.html => views/test.ejs}        |    0
 resources/views/verify_email_address.ejs      |   44 +-
 scripts/compile_mo.sh                         |   19 +
 scripts/compress.sh                           |   12 +-
 scripts/extract_po.sh                         |   23 +
 scripts/merge_po.sh                           |   32 +
 scripts/production_locales                    |   18 +
 35 files changed, 2564 insertions(+), 115 deletions(-)
 create mode 100644 docs/I18N.md
 create mode 100644 docs/TESTING.md
 create mode 100644 lib/browserid/prove_template.ejs
 delete mode 100644 lib/browserid/prove_template.txt
 create mode 100644 lib/i18n.js
 create mode 100644 resources/static/i18n/db_LB/client.json
 create mode 100644 resources/static/i18n/db_LB/messages.json
 create mode 100644 resources/static/i18n/en_US/client.json
 create mode 100644 resources/static/i18n/en_US/messages.json
 create mode 100644 resources/static/i18n/pl/messages.json
 create mode 100644 resources/static/shared/gettext.js
 rename resources/{static/test/index.html => views/test.ejs} (100%)
 create mode 100755 scripts/compile_mo.sh
 create mode 100755 scripts/extract_po.sh
 create mode 100755 scripts/merge_po.sh
 create mode 100755 scripts/production_locales

diff --git a/bin/browserid b/bin/browserid
index 324ef9c03..c2eb01539 100755
--- a/bin/browserid
+++ b/bin/browserid
@@ -13,6 +13,7 @@ urlparse = require('urlparse'),
 express = require('express');
 
 const
+i18n = require('../lib/i18n.js'),
 wsapi = require('../lib/wsapi.js'),
 httputils = require('../lib/httputils.js'),
 secrets = require('../lib/secrets.js'),
@@ -60,6 +61,13 @@ app.use(express.logger({
   }
 }));
 
+// #2.1 - localization
+app.use(i18n.abide({
+  supported_languages: config.get('supported_languages'),
+  default_lang: config.get('default_lang'),
+  locale_directory: config.get('locale_directory')
+}));
+
 // limit all content bodies to 10kb, at which point we'll forcefully
 // close down the connection.
 app.use(express.limit("10kb"));
diff --git a/bin/dbwriter b/bin/dbwriter
index 4d92017b0..ab4933e4d 100755
--- a/bin/dbwriter
+++ b/bin/dbwriter
@@ -15,6 +15,7 @@ express = require('express');
 const
 wsapi = require('../lib/wsapi.js'),
 httputils = require('../lib/httputils.js'),
+i18n = require('../lib/i18n.js'),
 secrets = require('../lib/secrets.js'),
 db = require('../lib/db.js'),
 config = require('../lib/configuration.js'),
@@ -59,6 +60,12 @@ if (statsd_config && statsd_config.enabled) {
   }));
 }
 
+app.use(i18n.abide({
+  supported_languages: config.get('supported_languages'),
+  default_lang: config.get('default_lang'),
+  locale_directory: config.get('locale_directory')
+}));
+
 // Add Strict-Transport-Security headers if we're serving over SSL
 if (config.get('scheme') == 'https') {
   app.use(function(req, resp, next) {
diff --git a/docs/I18N.md b/docs/I18N.md
new file mode 100644
index 000000000..fb3fd88a9
--- /dev/null
+++ b/docs/I18N.md
@@ -0,0 +1,63 @@
+# i18n Support
+
+Working with a localized version of BrowserID is totally optional for
+casual development.
+
+To get started, please [read the l10n locale doc](http://svn.mozilla.org/projects/l10n-misc/trunk/browserid/README).
+
+## Development
+
+Any copy, label, or error message that will be shown to users **should** be wrapped in a gettext function.
+
+These strings must be evaluated in the scope of a request, so we know which locale the user has.
+
+In JavaScript or EJS templates use `gettext` or `ngettext`. If you need to do string interpolation, use the 
+[strargs](http://jsgettext.berlios.de/doc/html/Gettext.html#strargs__string__argument_array_)
+function, which is kind of like node.js' util.format, except crappier.
+
+Using `_` is more idiomatic, but conflicts with `underscore.js` on the client side JS and EJS files.
+
+Technically, you can alias gettext to _ and use util.format, etc in node.js code... but for development consistency, 
+we should keep EJS templates looking similar, regardless of if they are evaluated client or server-side.
+
+## Variables
+
+The request object and the response's template context have the following variables:
+
+ * lang - User's preferred language
+ * lang_dir - rtl or ltr (BIDI language support)
+ * locale - OS level locale code
+ * gettext, ngettext - Gettext functions
+
+## Debugging
+
+If code is evaluated in node.js (server-side) then node-gettext is providing the string
+translation. Strings are from the messages.mo files under the locale directory. MO files
+are binary, compiled from the PO files.
+
+If code is evaluated on the client-side, then resources/static/shared/gettext.js is in
+the house... strings are from resources/static/i18n JSON files.
+
+If code is evaluated in your head, then clearly we are post-singularity. Why are you
+still using gettext?
+
+Use the eo locale for development and debugging. It is auto-translated with:
+for catalog in messages client; do
+  echo "Translating ${catalog}.po"
+  podebug --rewrite=flipped -i locale/templates/LC_MESSAGES/${catalog}.pot -o locale/eo/LC_MESSAGES/${catalog}.po
+done
+
+## New Locales
+
+To add a new language, and thus a new locale to BrowserID, do the following:
+Assuming you want to add eo for Esperanto support...
+
+    mkdir -p locale/eo/LC_MESSAGES
+
+    msginit --input=./locale/templates/LC_MESSAGES/messages.pot \
+            --output-file=./locale/eo/LC_MESSAGES/messages.po \
+            -l eo
+
+    msginit --input=./locale/templates/LC_MESSAGES/client.pot \
+            --output-file=./locale/eo/LC_MESSAGES/client.po \
+            -l eo
\ No newline at end of file
diff --git a/docs/ORGANIZATION.md b/docs/ORGANIZATION.md
index 43b457e35..15c2808f6 100644
--- a/docs/ORGANIZATION.md
+++ b/docs/ORGANIZATION.md
@@ -6,7 +6,7 @@ Several node.js servers are implemented in this repostiory, each is
 implemented on top of the [express](http://expressjs.com) framework
 and they share the following directory structure:
 
-  * `bin` - Contains the BrowserID servers (browserid, 	dbwriter, keysgner, and verifier) and CLI tools.
+  * `bin` - Contains the BrowserID servers (browserid,  dbwriter, keysgner, and verifier) and CLI tools.
     * Each node.js application is the "entry point" for that app and is a typical express app.
 
   * `scripts` - Contains more CLI tools
@@ -34,9 +34,9 @@ and they share the following directory structure:
 
       * `pages` - Client side business logic for dialog
 
-      * `shared` - JavaScript which runs either client or server side
+      * `shared` - JavaScript which is re-used across dialogs
 
-      * `test` - QUnit tests      
+      * `test` - QUnit tests
 
   * `tests/` - Tests written using [vows](http://vowsjs.org)
     * Run via `scripts/run_all_tests.sh`
diff --git a/docs/TESTING.md b/docs/TESTING.md
new file mode 100644
index 000000000..3a8273ad1
--- /dev/null
+++ b/docs/TESTING.md
@@ -0,0 +1,5 @@
+Developer tests should be run before commiting code. There are two test suites.
+
+  # `npm test`
+
+  # Load http://localhost:10002/test/index.html into a world wide web browser
\ No newline at end of file
diff --git a/lib/browserid/prove_template.ejs b/lib/browserid/prove_template.ejs
new file mode 100644
index 000000000..489e30fc5
--- /dev/null
+++ b/lib/browserid/prove_template.ejs
@@ -0,0 +1,10 @@
+<%= gettext(
+      strargs('Thanks for verifying your email address.  This message is being sent to you to complete your sign-in to %1.', site)) %>
+ 
+<%= gettext('Finish registration by clicking this link:') %> <%= link %>
+ 
+<%= gettext('If you are NOT trying to sign into this site, just ignore this email.') %>
+ 
+<%= gettext('Thanks,') %>
+<%= gettext('BrowserID') %>
+<%= gettext('(A better way to sign in)') %>
diff --git a/lib/browserid/prove_template.txt b/lib/browserid/prove_template.txt
deleted file mode 100644
index d2a4cccab..000000000
--- a/lib/browserid/prove_template.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-Thanks for verifying your email address.  This message is being sent to you to complete your sign-in to {{site}}.
- 
-Finish registration by clicking this link: {{link}}
- 
-If you are NOT trying to sign into this site, just ignore this email.
- 
-Thanks,
-BrowserID
-(A better way to sign in)
diff --git a/lib/browserid/views.js b/lib/browserid/views.js
index 362ec942e..13e925237 100644
--- a/lib/browserid/views.js
+++ b/lib/browserid/views.js
@@ -94,6 +94,18 @@ exports.setup = function(app) {
     res.render('add_email_address.ejs', {title: 'Verify Email Address', fullpage: false});
   });
 
+  /**
+   * 
+   * XXX benadida or lloyd, I tried to use straight up regexp to do this, but.
+   * is there a better way to do this?
+   */
+  function QUnit(req, res) {
+    res.render('test.ejs', {title: 'BrowserID QUnit Test', layout: false});
+  }
+
+  app.get("/test", QUnit);
+  app.get("/test/index.html", QUnit);
+
   // REDIRECTS
   REDIRECTS = {
     "/manage": "/",
diff --git a/lib/configuration.js b/lib/configuration.js
index b91ac9758..fbd390ecc 100644
--- a/lib/configuration.js
+++ b/lib/configuration.js
@@ -109,7 +109,11 @@ g_configs.production = {
   max_compute_processes: undefined,
   // return a 503 if a compute process would take over 10s to complete
   max_compute_duration: 10,
-  disable_primary_support: true
+  disable_primary_support: true,
+  default_lang: ['en-US'],
+  supported_languages: ['en-US'],
+  // Contains po files
+  locale_directory: 'locale'
 };
 
 
@@ -129,7 +133,10 @@ g_configs.local =  {
   min_time_between_emails_ms: g_configs.production.min_time_between_emails_ms,
   max_compute_processes: undefined,
   max_compute_duration: 10,
-  disable_primary_support: false
+  disable_primary_support: false,
+  default_lang: g_configs.production.default_lang,
+  supported_languages: ['eo', 'en-US', 'db-LB'],
+  locale_directory: g_configs.production.locale_directory
 };
 
 // test environments are variations on local
diff --git a/lib/email.js b/lib/email.js
index ee72c089a..99fb83061 100644
--- a/lib/email.js
+++ b/lib/email.js
@@ -37,7 +37,7 @@ const
 emailer = require('nodemailer'),
 fs = require('fs'),
 path = require('path'),
-mustache = require('mustache'),
+ejs = require('ejs'),
 config = require('./configuration.js'),
 logger = require('./logging.js').logger;
 
@@ -55,7 +55,8 @@ if (smtp_params && smtp_params.host) {
   }
 }
 
-const template = fs.readFileSync(path.join(__dirname, "browserid", "prove_template.txt")).toString();
+const template = ejs.compile(
+    fs.readFileSync(path.join(__dirname, "browserid", "prove_template.ejs")).toString());
 
 var interceptor = undefined;
 
@@ -74,8 +75,11 @@ exports.setInterceptor = function(callback) {
   interceptor = callback;
 };
 
-function doSend(landing_page, email, site, secret) {
-  var url = config.get('URL') + "/" + landing_page + "?token=" + encodeURIComponent(secret);
+//TODO send in localeContext
+function doSend(landing_page, email, site, secret, langContext) {
+  var url = config.get('URL') + "/" + landing_page + "?token=" + encodeURIComponent(secret),
+      _ = langContext.gettext,
+      strargs = langContext.strargs;
 
   if (interceptor) {
     interceptor(email, site, secret);
@@ -83,11 +87,13 @@ function doSend(landing_page, email, site, secret) {
     // log verification email to console separated by whitespace.
     console.log("\nVERIFICATION URL:\n" + url + "\n");
   } else {
+    // TODO(aok) extract_po.sh isn't seeing this string if it's below in object literal
+    var subject = strargs(_("Complete Login to %1 using BrowserID"), site);
     emailer.send_mail({
       sender: "BrowserID@browserid.org",
       to: email,
-      subject : "Complete Login to " + site + " using BrowserID",
-      body: mustache.to_html(template, { email: email, link: url, site: site })
+      subject: subject,
+      body: template({ link: url, site: site, gettext: _, strargs: strargs })
     }, function(err, success){
       if(!success) {
         logger.error("error sending email: " + err);
@@ -97,10 +103,10 @@ function doSend(landing_page, email, site, secret) {
   };
 };
 
-exports.sendNewUserEmail = function(email, site, secret) {
-  doSend('verify_email_address', email, site, secret);
+exports.sendNewUserEmail = function(email, site, secret, langContext) {
+  doSend('verify_email_address', email, site, secret, langContext);
 };
 
-exports.sendAddAddressEmail = function(email, site, secret) {
-  doSend('add_email_address', email, site, secret);
+exports.sendAddAddressEmail = function(email, site, secret, langContext) {
+  doSend('add_email_address', email, site, secret, langContext);
 };
diff --git a/lib/http_forward.js b/lib/http_forward.js
index 16b757703..ca2651df2 100644
--- a/lib/http_forward.js
+++ b/lib/http_forward.js
@@ -56,10 +56,15 @@ module.exports = function(dest, req, res, cb) {
   }
 
   // forward cookies
-  if(req.headers['cookie']) {
+  if (req.headers['cookie']) {
     preq.setHeader('Cookie', req.headers['cookie']);
   }
 
+  // forward header
+  if (req.headers['accept-language']) {
+      preq.setHeader('Accept-Language', req.headers['accept-language']);
+  }
+
   // if the body has already been parsed, we'll write it
   if (req.body) {
     var data = querystring.stringify(req.body);
diff --git a/lib/i18n.js b/lib/i18n.js
new file mode 100644
index 000000000..4c880dd42
--- /dev/null
+++ b/lib/i18n.js
@@ -0,0 +1,236 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * i18n-abide
+ * 
+ * This module abides by the user's language preferences and makes it
+ * available throughout the app.
+ * 
+ * This module abides by the Mozilla L10n way of doing things.
+ * 
+ * The module abides.
+ * 
+ * See docs/I18N.md for details.
+ */
+
+var logger = require('./logging.js').logger,
+    Gettext = require('node-gettext'),
+    path = require('path'),
+    util = require('util');
+
+const BIDI_RTL_LANGS = ['ar', 'eo', 'fa', 'he'];
+
+/**
+ * Connect middleware which is i18n aware.
+ * 
+ * Usage:
+  app.use(i18n.abide({
+    supported_languages: ['en-US', 'fr', 'pl'],
+    default_lang: 'en-US',
+    locale_directory: 'locale'
+  }));
+ *
+ * Other valid options: gettext_alias, ngettext_alias
+ */
+exports.abide = function (options) {
+
+  if (! options.gettext_alias)       options.gettext_alias = 'gettext';
+  if (! options.ngettext_alias)      options.ngettext_alias = 'ngettext';
+  if (! options.supported_languages) options.supported_languages = ['en-US'];
+  if (! options.default_lang)        options.default_lang = 'en-US';
+  if (! options.locale_directory)    options.locale_directory = 'locale';
+
+  return function(req, resp, next) {
+    var langs = parseAcceptLanguage(req.headers['accept-language']),
+        lang_dir,
+        lang = bestLanguage(langs, options.supported_languages, 
+                            options.default_lang),
+        locale;
+
+    // TODO(aok): Check if we're not in production mode before switching eo to db-LB
+    // Must fix before Esperanto could ship.
+    if (lang == 'eo') {
+        lang = 'db-LB'; // What? http://www.youtube.com/watch?v=rJLnGjhPT1Q
+    }
+
+    resp.local('lang', lang);
+
+    logger.info('Setting lang=' + lang + ' for this request');
+
+    // BIDI support, which direction does text flow?
+    lang_dir = BIDI_RTL_LANGS.indexOf(lang) >= 0 ? 'rtl' : 'ltr';
+    resp.local('lang_dir', lang_dir);
+    req.lang = lang;
+
+    locale = localeFrom(lang);
+    resp.local('locale', locale);
+    req.locale = locale;
+
+    // Thread saftey, app startup or per request?
+    gt = new Gettext();
+
+    // app startup ???
+    mo_path = path.join(__dirname, '..', options.locale_directory, locale, 
+                        'LC_MESSAGES', 'messages.mo');
+
+    resp.local('strargs', strargs);
+    req.strargs = strargs;
+
+    if (path.existsSync(mo_path)) {
+      gt.addTextdomain(locale, fs.readFileSync(mo_path));
+
+      // Per request ???
+      gt.textdomain(locale);
+      console.info("Putting " + options.gettext_alias);
+      resp.local(options.gettext_alias, gt.gettext.bind(gt));
+      req.gettext = gt.gettext.bind(gt);
+      resp.local(options.ngettext_alias, gt.ngettext.bind(gt));
+      req.ngettext = gt.ngettext.bind(gt);
+   } else {
+      // TODO if in development mode, warn... production error
+      logger.error('Bad language=' + lang + ' or locale=' + locale + 
+                   ' mo file does not exist. [' + mo_path + ']');
+      var identity = function (a, b) { return a; };
+      resp.local(options.gettext_alias, identity);
+      req.gettext = identity;
+      resp.local(options.ngettext_alias, identity);
+      req.ngettext = identity;
+    }
+    next();
+  };
+};
+function qualityCmp(a, b) {
+  if (a.quality == b.quality) {
+    return 0;
+  } else if (a.quality < b.quality) {
+    return 1;
+  } else {
+    return -1;
+  }
+};
+
+/**
+ * Parses the HTTP accept-language header and returns a
+ * sorted array of objects. Example object:
+ * {
+ *   lang: 'pl', quality: 0.7
+ * }
+ */
+exports.parseAcceptLanguage = parseAcceptLanguage = function (header) {
+    // pl,fr-FR;q=0.3,en-US;q=0.1
+    if (! header || ! header.split) {
+      return [];
+    }
+    var raw_langs = header.split(',');
+    var langs = raw_langs.map(function (raw_lang) {
+      var parts = raw_lang.split(';');
+      var q = 1;
+      if (parts.length > 1 && parts[1].indexOf('q=') == 0) {
+          qval = parseFloat(parts[1].split('=')[1]);
+          if (isNaN(qval) === false) {
+            q = qval;
+          }
+      }
+      return { lang: parts[0].trim(), quality: q };
+    });
+    langs.sort(qualityCmp);
+    return langs;
+};
+
+
+ // Given the user's prefered languages and a list of currently
+ // supported languages, returns the best match or a default language.
+ // 
+ // languages must be a sorted list, the first match is returned.
+function bestLanguage(languages, supported_languages, defaultLanguage) {
+  var lower = supported_languages.map(function (l) { return l.toLowerCase(); });
+  for(var i=0; i < languages.length; i++) {
+    var lq = languages[i];
+    if (lower.indexOf(lq.lang.toLowerCase()) !== -1) {
+      return lq.lang;
+    }
+  }
+  return defaultLanguage;
+};
+
+/**
+ * Given a language code, return a locale code the OS understands.
+ *
+ * language: en-US
+ * locale:   en_US
+ */
+exports.localeFrom = localeFrom = function (language) {
+  if (! language || ! language.split) {
+      return "";
+  }
+  var parts = language.split('-');
+  if (parts.length === 1) {
+    return parts[0].toLowerCase();
+  } else if (parts.length === 2) {
+    return util.format('%s_%s', parts[0].toLowerCase(), parts[1].toUpperCase());
+  } else if (parts.length === 3) {
+    // sr-Cyrl-RS should be sr_RS
+    return util.format('%s_%s', parts[0].toLowerCase(), parts[2].toUpperCase());
+  } else {
+    logger.error(util.format("Unable to map a local from language code [%s]", language));
+    return language;
+  }
+};
+
+/**
+ * Copied from `resources/static/shared/gettext.js`, so we can use the
+ * same method name on node.js and client-side.
+ */
+exports.strargs = strargs = function (str, args) {
+    // make sure args is an array
+    if ( null == args ||
+         'undefined' == typeof(args) ) {
+        args = [];
+    } else if (args.constructor != Array) {
+        args = [args];
+    }
+
+    // NOTE: javascript lacks support for zero length negative look-behind
+    // in regex, so we must step through w/ index.
+    // The perl equiv would simply be:
+    //    $string =~ s/(?<!\%)\%([0-9]+)/$args[$1]/g;
+    //    $string =~ s/\%\%/\%/g; # restore escaped percent signs
+
+    var newstr = "";
+    while (true) {
+        var i = str.indexOf('%');
+        var match_n;
+
+        // no more found. Append whatever remains
+        if (i == -1) {
+            newstr += str;
+            break;
+        }
+
+        // we found it, append everything up to that
+        newstr += str.substr(0, i);
+
+        // check for escpaed %%
+        if (str.substr(i, 2) == '%%') {
+            newstr += '%';
+            str = str.substr((i+2));
+
+        // % followed by number
+        } else if ( match_n = str.substr(i).match(/^%(\d+)/) ) {
+            var arg_n = parseInt(match_n[1]);
+            var length_n = match_n[1].length;
+            if ( arg_n > 0 && args[arg_n -1] != null && typeof(args[arg_n -1]) != 'undefined' )
+                newstr += args[arg_n -1];
+            str = str.substr( (i + 1 + length_n) );
+
+        // % followed by some other garbage - just remove the %
+        } else {
+            newstr += '%';
+            str = str.substr((i+1));
+        }
+    }
+
+    return newstr;
+};
\ No newline at end of file
diff --git a/lib/wsapi/stage_email.js b/lib/wsapi/stage_email.js
index 81d2f2c3e..6b388cafe 100644
--- a/lib/wsapi/stage_email.js
+++ b/lib/wsapi/stage_email.js
@@ -27,14 +27,19 @@ exports.process = function(req, res) {
     try {
       // on failure stageEmail may throw
       db.stageEmail(req.session.userid, req.body.email, function(secret) {
-
+        var langContext = {
+            lang: req.lang,
+            locale: req.locale,
+            gettext: req.gettext,
+            ngettext: req.ngettext
+        };
         // store the email being added in session data
         req.session.pendingAddition = secret;
 
         res.json({ success: true });
 
         // let's now kick out a verification email!
-        email.sendAddAddressEmail(req.body.email, req.body.site, secret);
+        email.sendAddAddressEmail(req.body.email, req.body.site, secret, langContext);
       });
     } catch(e) {
       // we should differentiate tween' 400 and 500 here.
diff --git a/lib/wsapi/stage_user.js b/lib/wsapi/stage_user.js
index 7830bb840..f7dddf190 100644
--- a/lib/wsapi/stage_user.js
+++ b/lib/wsapi/stage_user.js
@@ -17,6 +17,13 @@ exports.authed = false;
 exports.args = ['email','site'];
 
 exports.process = function(req, resp) {
+  var langContext = {
+            gettext: req.gettext,
+            lang: req.lang,
+            locale: req.locale,
+            ngettext: req.ngettext,
+            strargs: req.strargs
+        };
   // staging a user logs you out.
   wsapi.clearAuthenticatedUser(req.session);
 
@@ -30,7 +37,7 @@ exports.process = function(req, resp) {
     try {
       // upon success, stage_user returns a secret (that'll get baked into a url
       // and given to the user), on failure it throws
-      db.stageUser(req.body.email, function(secret) {
+      db.stageUser(req.body.email, function(secret) {        
         // store the email being registered in the session data
         if (!req.session) req.session = {};
 
@@ -41,8 +48,8 @@ exports.process = function(req, resp) {
 
         resp.json({ success: true });
 
-        // let's now kick out a verification email!
-        email.sendNewUserEmail(req.body.email, req.body.site, secret);
+        // let's now kick out a verification email!        
+        email.sendNewUserEmail(req.body.email, req.body.site, secret, langContext);
       });
     } catch(e) {
       // we should differentiate tween' 400 and 500 here.
diff --git a/resources/static/dialog/views/authenticate.ejs b/resources/static/dialog/views/authenticate.ejs
index 3343e3664..c81ebd344 100644
--- a/resources/static/dialog/views/authenticate.ejs
+++ b/resources/static/dialog/views/authenticate.ejs
@@ -1,25 +1,24 @@
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-
-  <strong>Sign in using</strong>
+<% /* This Source Code Form is subject to the terms of the Mozilla Public
+      License, v. 2.0. If a copy of the MPL was not distributed with this
+      file, You can obtain one at http://mozilla.org/MPL/2.0/. */ %>
+  <strong><%= gettext('Sign in using') %></strong>
   <div class="form_section">
       <ul class="inputs">
 
           <li>
-              <label for="email" class="serif">Email</label>
+              <label for="email" class="serif"><%= gettext('Email') %></label>
               <input id="email" class="sans" type="email" autocapitalize="off" autocorrect="off" value="<%= email %>" maxlength="254" tabindex="1"/>
 
               <div id="email_format" class="tooltip" for="email">
-                This field must be an email address.
+                <%= gettext('This field must be an email address.') %>
               </div>
 
               <div id="email_required" class="tooltip" for="email">
-                The email field is required.
+                <%= gettext('The email field is required.') %>
               </div>
 
               <div id="could_not_add" class="tooltip" for="email">
-                We just sent an email to that address!  If you really want to send another, wait a minute or two and try again.
+                <%= gettext('We just sent an email to that address!  If you really want to send another, wait a minute or two and try again.') %>
               </div>
 
               <div id="already_registered" class="tooltip" for="email">
@@ -28,37 +27,38 @@
           </li>
 
           <li id="hint_section" class="start">
-              <p>Enter your email address to sign in to <strong><%= sitename %></strong></p>
+              <p><%= strargs(gettext('Enter your email address to sign in to <strong>%1</strong>'),
+                             [sitename]) %></p>
           </li>
 
           <li id="create_text_section" class="newuser">
-              <p><strong>Welcome to BrowserID!</strong></p>
-              <p>This email looks new, so let&apos;s get you set up.</p>
+              <p><strong><%= gettext('Welcome to BrowserID!') %></strong></p>
+              <p><%= gettext('This email looks new, so let&apos;s get you set up.') %></p>
           </li>
 
           <li class="returning">
 
-              <label for="password" class="half serif">Password</label>
+              <label for="password" class="half serif"><%= gettext('Password') %></label>
               <div class="half right">
-                  <a id="forgotPassword" href="#" tabindex="4">forgot your password?</a>
+                  <a id="forgotPassword" href="#" tabindex="4"><%= gettext('forgot your password?') %></a>
               </div>
               <input id="password" class="sans" type="password" maxlength="80" tabindex="2" />
 
               <div id="password_required" class="tooltip" for="password">
-                The password field is required.
+                <%= gettext('The password field is required.') %>
               </div>
 
               <div id="cannot_authenticate" class="tooltip" for="password">
-                The account cannot be logged in with this username and password.
+                <%= gettext('The account cannot be logged in with this username and password.') %>
               </div>
           </li>
 
       </ul>
 
       <div class="submit cf">
-          <button class="start" tabindex="3">next</button>
-          <button class="newuser" tabindex="3">verify email</button>
+          <button class="start" tabindex="3"><%= gettext('next') %></button>
+          <button class="newuser" tabindex="3"><%= gettext('verify email') %></button>
 
-          <button class="returning" tabindex="3">select email</button>
+          <button class="returning" tabindex="3"><%= gettext('select email') %></button>
       </div>
   </div>
diff --git a/resources/static/dialog/views/confirm_email.ejs b/resources/static/dialog/views/confirm_email.ejs
index 31c147616..16b7934ea 100644
--- a/resources/static/dialog/views/confirm_email.ejs
+++ b/resources/static/dialog/views/confirm_email.ejs
@@ -1,9 +1,9 @@
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+<% /* This Source Code Form is subject to the terms of the Mozilla Public
+      License, v. 2.0. If a copy of the MPL was not distributed with this
+      file, You can obtain one at http://mozilla.org/MPL/2.0/. */ %>
 
-    <h2>Check your email!</h2>
-    <p>We sent a confirmation email to <strong><%= email %></strong></p>
-    <p>To finish signing in just click the verify link we sent to your email address.</p><br />
-    <p>If this is a mistake, just ignore the sent email and <a href="#" class="cancelVerify" id="back">use another email address</a>.</p>
+    <h2><%= gettext('Check your email!') %></h2>
+    <p><%= strargs(gettext('We sent a confirmation email to <strong>%1</strong>'), email) %></p>
+    <p><% gettext('To finish signing in just click the verify link we sent to your email address.') %></p><br />
+    <p><% gettext('If this is a mistake, just ignore the sent email and <a href="#" class="cancelVerify" id="back">use another email address</a>.') %></p>
 
diff --git a/resources/static/dialog/views/pick_email.ejs b/resources/static/dialog/views/pick_email.ejs
index 895326d42..af5571028 100644
--- a/resources/static/dialog/views/pick_email.ejs
+++ b/resources/static/dialog/views/pick_email.ejs
@@ -2,8 +2,8 @@
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
-  <a id="thisIsNotMe" href="#">This is not me...</a>
-  <strong>Sign in using</strong>
+  <a id="thisIsNotMe" href="#"><%= gettext('This is not me...') %></a>
+  <strong><%= gettext('Sign in using') %></strong>
 
   <div id="selectEmail" class="form_section">
       <ul class="inputs">
@@ -19,18 +19,18 @@
               </li>
           <% }); %>
       </ul>
-      <a id="useNewEmail" href="#">Use a different email</a>
+      <a id="useNewEmail" href="#"><%= gettext('Use a different email') %></a>
 
       <div class="submit add cf">
 
           <% if (allow_persistent) { %>
             <label for="remember" class="selectable">
               <input type="checkbox" id="remember" name="remember" <% if (remember) { %> checked="checked" <% } %> />
-              Always sign in using this email
+              <%= gettext('Always sign in using this email') %>
             </label>
           <% } %>
 
-          <button id="signInButton">sign in</button>
+          <button id="signInButton"><%= gettext('sign in') %></button>
 
           <p>
           </p>
diff --git a/resources/static/i18n/db_LB/client.json b/resources/static/i18n/db_LB/client.json
new file mode 100644
index 000000000..7e05ff223
--- /dev/null
+++ b/resources/static/i18n/db_LB/client.json
@@ -0,0 +1,124 @@
+var json_locale_data = {
+   "client" : {
+      "" : {
+         "MIME-Version" : " 1.0",
+         "POT-Creation-Date" : " 2012-01-11 16:41-0800",
+         "Last-Translator" : " FULL NAME <EMAIL@ADDRESS>",
+         "Content-Type" : " text/plain; charset=UTF-8",
+         "PO-Revision-Date" : " YEAR-MO-DA HO:MI+ZONE",
+         "Language-Team" : " LANGUAGE <LL@li.org>",
+         "Content-Transfer-Encoding" : " 8bit",
+         "Project-Id-Version" : " PACKAGE VERSION",
+         "Report-Msgid-Bugs-To" : " "
+      },
+      "Always sign in using this email" : [
+         null,
+         "‮∀ʅʍɐʎs sıƃu ıu nsıuƃ ʇɥıs ǝɯɐıʅ"
+      ],
+      "next" : [
+         null,
+         "‮uǝxʇ"
+      ],
+      "add" : [
+         null,
+         ""
+      ],
+      "This email looks new, so let&apos;s get you set up." : [
+         null,
+         "‮⊥ɥıs ǝɯɐıʅ ʅooʞs uǝʍ´ so ʅǝʇ&apos;‮s ƃǝʇ ʎon sǝʇ nd·"
+      ],
+      "The email field is required." : [
+         null,
+         "‮⊥ɥǝ ǝɯɐıʅ ɟıǝʅp ıs ɹǝbnıɹǝp·"
+      ],
+      "New email address" : [
+         null,
+         ""
+      ],
+      "verify email" : [
+         null,
+         "‮ʌǝɹıɟʎ ǝɯɐıʅ"
+      ],
+      "Sign in using" : [
+         null,
+         "‮Sıƃu ıu nsıuƃ"
+      ],
+      "Password" : [
+         null,
+         "‮Ԁɐssʍoɹp"
+      ],
+      "You already own that address!" : [
+         null,
+         ""
+      ],
+      "To finish signing in just click the verify link we sent to your email address." : [
+         null,
+         "‮⊥o ɟıuısɥ sıƃuıuƃ ıu ɾnsʇ ɔʅıɔʞ ʇɥǝ ʌǝɹıɟʎ ʅıuʞ ʍǝ sǝuʇ ʇo ʎonɹ ǝɯɐıʅ ɐppɹǝss·"
+      ],
+      "forgot your password?" : [
+         null,
+         "‮ɟoɹƃoʇ ʎonɹ dɐssʍoɹp?"
+      ],
+      "This field must be an email address." : [
+         null,
+         "‮⊥ɥıs ɟıǝʅp ɯnsʇ qǝ ɐu ǝɯɐıʅ ɐppɹǝss·"
+      ],
+      "Email" : [
+         null,
+         "‮Ǝɯɐıʅ"
+      ],
+      "We sent a confirmation email to <strong>%1</strong>" : [
+         null,
+         "‮Mǝ sǝuʇ ɐ ɔouɟıɹɯɐʇıou ǝɯɐıʅ ʇo <strong>%1</strong>"
+      ],
+      "sign in" : [
+         null,
+         "‮sıƃu ıu"
+      ],
+      "The account cannot be logged in with this username and password." : [
+         null,
+         "‮⊥ɥǝ ɐɔɔonuʇ ɔɐuuoʇ qǝ ʅoƃƃǝp ıu ʍıʇɥ ʇɥıs nsǝɹuɐɯǝ ɐup dɐssʍoɹp·"
+      ],
+      "select email" : [
+         null,
+         "‮sǝʅǝɔʇ ǝɯɐıʅ"
+      ],
+      "This is not me..." : [
+         null,
+         "‮⊥ɥıs ıs uoʇ ɯǝ···"
+      ],
+      "Welcome to BrowserID!" : [
+         null,
+         "‮Mǝʅɔoɯǝ ʇo ԐɹoʍsǝɹIᗡ¡"
+      ],
+      "If this is a mistake, just ignore the sent email and <a href=\"#\" class=\"cancelVerify\" id=\"back\">use another email address</a>." : [
+         null,
+         "‮Iɟ ʇɥıs ıs ɐ ɯısʇɐʞǝ´ ɾnsʇ ıƃuoɹǝ ʇɥǝ sǝuʇ ǝɯɐıʅ ɐup <a href=\"#\" class=\"cancelVerify\" id=\"back\">‮nsǝ ɐuoʇɥǝɹ ǝɯɐıʅ ɐppɹǝss</a>‮·"
+      ],
+      "We just sent an email to that address!  If you really want to send another, wait a minute or two and try again." : [
+         null,
+         "‮Mǝ ɾnsʇ sǝuʇ ɐu ǝɯɐıʅ ʇo ʇɥɐʇ ɐppɹǝss¡  Iɟ ʎon ɹǝɐʅʅʎ ʍɐuʇ ʇo sǝup ɐuoʇɥǝɹ´ ʍɐıʇ ɐ ɯıunʇǝ oɹ ʇʍo ɐup ʇɹʎ ɐƃɐıu·"
+      ],
+      "Check your email!" : [
+         null,
+         "‮Ↄɥǝɔʞ ʎonɹ ǝɯɐıʅ¡"
+      ],
+      "Enter your email address to sign in to <strong>%1</strong>" : [
+         null,
+         "‮Ǝuʇǝɹ ʎonɹ ǝɯɐıʅ ɐppɹǝss ʇo sıƃu ıu ʇo <strong>%1</strong>"
+      ],
+      "cancel" : [
+         null,
+         ""
+      ],
+      "The password field is required." : [
+         null,
+         "‮⊥ɥǝ dɐssʍoɹp ɟıǝʅp ıs ɹǝbnıɹǝp·"
+      ],
+      "Use a different email" : [
+         null,
+         "‮∩sǝ ɐ pıɟɟǝɹǝuʇ ǝɯɐıʅ"
+      ]
+   }
+}
+;
diff --git a/resources/static/i18n/db_LB/messages.json b/resources/static/i18n/db_LB/messages.json
new file mode 100644
index 000000000..ab47005a8
--- /dev/null
+++ b/resources/static/i18n/db_LB/messages.json
@@ -0,0 +1,140 @@
+var json_locale_data = {
+   "messages" : {
+      "Error encountered trying to complete registration." : [
+         null,
+         "‮Ǝɹɹoɹ ǝuɔonuʇǝɹǝp ʇɹʎıuƃ ʇo ɔoɯdʅǝʇǝ ɹǝƃısʇɹɐʇıou·"
+      ],
+      "" : {
+         "MIME-Version" : " 1.0",
+         "POT-Creation-Date" : " 2012-01-11 16:41-0800",
+         "Last-Translator" : " FULL NAME <EMAIL@ADDRESS>",
+         "Content-Type" : " text/plain; charset=UTF-8",
+         "PO-Revision-Date" : " YEAR-MO-DA HO:MI+ZONE",
+         "Language-Team" : " LANGUAGE <LL@li.org>",
+         "Content-Transfer-Encoding" : " 8bit",
+         "Project-Id-Version" : " PACKAGE VERSION",
+         "Report-Msgid-Bugs-To" : " "
+      },
+      "Verification password is required." : [
+         null,
+         "‮Ʌǝɹıɟıɔɐʇıou dɐssʍoɹp ıs ɹǝbnıɹǝp·"
+      ],
+      "BrowserID" : [
+         null,
+         "‮ԐɹoʍsǝɹIᗡ"
+      ],
+      "Finish signing into: " : [
+         null,
+         "‮Ⅎıuısɥ sıƃuıuƃ ıuʇo: "
+      ],
+      "Your Email" : [
+         null,
+         "‮⅄onɹ Ǝɯɐıʅ"
+      ],
+      "Error comunicating with server." : [
+         null,
+         "‮Ǝɹɹoɹ ɔoɯnuıɔɐʇıuƃ ʍıʇɥ sǝɹʌǝɹ·"
+      ],
+      "Last step!" : [
+         null,
+         "‮⅂ɐsʇ sʇǝd¡"
+      ],
+      "BrowserID is the fast and secure way to sign in &mdash; <a target=\"_blank\" href=\"/about\">learn more</a>" : [
+         null,
+         "‮ԐɹoʍsǝɹIᗡ ıs ʇɥǝ ɟɐsʇ ɐup sǝɔnɹǝ ʍɐʎ ʇo sıƃu ıu &mdash;‮ <a target=\"_blank\" href=\"/about\">‮ʅǝɐɹu ɯoɹǝ</a>"
+      ],
+      "Your new address is set up and you should now be signed in. You may now close this window and go back to" : [
+         null,
+         "‮⅄onɹ uǝʍ ɐppɹǝss ıs sǝʇ nd ɐup ʎon sɥonʅp uoʍ qǝ sıƃuǝp ıu· ⅄on ɯɐʎ uoʍ ɔʅosǝ ʇɥıs ʍıupoʍ ɐup ƃo qɐɔʞ ʇo"
+      ],
+      "Verify Password" : [
+         null,
+         "‮Ʌǝɹıɟʎ Ԁɐssʍoɹp"
+      ],
+      "Password must be between 8 and 80 characters long." : [
+         null,
+         "‮Ԁɐssʍoɹp ɯnsʇ qǝ qǝʇʍǝǝu 8‮ ɐup 80‮ ɔɥɐɹɐɔʇǝɹs ʅouƃ·"
+      ],
+      "Complete Login to %1 using BrowserID" : [
+         null,
+         "‮Ↄoɯdʅǝʇǝ ⅂oƃıu ʇo %1‮ nsıuƃ ԐɹoʍsǝɹIᗡ"
+      ],
+      "(A better way to sign in)" : [
+         null,
+         "‮(∀ qǝʇʇǝɹ ʍɐʎ ʇo sıƃu ıu)"
+      ],
+      "Finish registration by clicking this link:" : [
+         null,
+         "‮Ⅎıuısɥ ɹǝƃısʇɹɐʇıou qʎ ɔʅıɔʞıuƃ ʇɥıs ʅıuʞ:"
+      ],
+      "Thanks," : [
+         null,
+         "‮⊥ɥɐuʞs´"
+      ],
+      "Communicating with server" : [
+         null,
+         "‮Ↄoɯɯnuıɔɐʇıuƃ ʍıʇɥ sǝɹʌǝɹ"
+      ],
+      "Enter a Password" : [
+         null,
+         "‮Ǝuʇǝɹ ɐ Ԁɐssʍoɹp"
+      ],
+      "Error encountered while attempting to confirm your address. Have you previously verified this address?" : [
+         null,
+         "‮Ǝɹɹoɹ ǝuɔonuʇǝɹǝp ʍɥıʅǝ ɐʇʇǝɯdʇıuƃ ʇo ɔouɟıɹɯ ʎonɹ ɐppɹǝss· Hɐʌǝ ʎon dɹǝʌıonsʅʎ ʌǝɹıɟıǝp ʇɥıs ɐppɹǝss?"
+      ],
+      "Thank you for signing up with <strong>BrowserID</strong>. You can now use your <strong>BrowserID</strong> account to <em>Sign In</em> or <em>Sign Up</em> to websites all across the web!" : [
+         null,
+         "‮⊥ɥɐuʞ ʎon ɟoɹ sıƃuıuƃ nd ʍıʇɥ <strong>‮ԐɹoʍsǝɹIᗡ</strong>‮· ⅄on ɔɐu uoʍ nsǝ ʎonɹ <strong>‮ԐɹoʍsǝɹIᗡ</strong>‮ ɐɔɔonuʇ ʇo <em>‮Sıƃu Iu</em>‮ oɹ <em>‮Sıƃu ∩d</em>‮ ʇo ʍǝqsıʇǝs ɐʅʅ ɐɔɹoss ʇɥǝ ʍǝq¡"
+      ],
+      "Email Verification" : [
+         null,
+         "‮Ǝɯɐıʅ Ʌǝɹıɟıɔɐʇıou"
+      ],
+      "<strong class=\"email\">Your address</strong> has been verified!" : [
+         null,
+         "<strong class=\"email\">‮⅄onɹ ɐppɹǝss</strong>‮ ɥɐs qǝǝu ʌǝɹıɟıǝp¡"
+      ],
+      "Browser ID" : [
+         null,
+         "‮Ԑɹoʍsǝɹ Iᗡ"
+      ],
+      "Finish" : [
+         null,
+         "‮Ⅎıuısɥ"
+      ],
+      "There was a problem with your signup link.  Has this address already been registered?" : [
+         null,
+         "‮⊥ɥǝɹǝ ʍɐs ɐ dɹoqʅǝɯ ʍıʇɥ ʎonɹ sıƃund ʅıuʞ·  Hɐs ʇɥıs ɐppɹǝss ɐʅɹǝɐpʎ qǝǝu ɹǝƃısʇǝɹǝp?"
+      ],
+      "Password is required." : [
+         null,
+         "‮Ԁɐssʍoɹp ıs ɹǝbnıɹǝp·"
+      ],
+      "Passwords do not match." : [
+         null,
+         "‮Ԁɐssʍoɹps po uoʇ ɯɐʇɔɥ·"
+      ],
+      "New Password" : [
+         null,
+         "‮Nǝʍ Ԁɐssʍoɹp"
+      ],
+      "Repeat Password" : [
+         null,
+         "‮ᴚǝdǝɐʇ Ԁɐssʍoɹp"
+      ],
+      "Just a moment while we talk with the server." : [
+         null,
+         "‮ſnsʇ ɐ ɯoɯǝuʇ ʍɥıʅǝ ʍǝ ʇɐʅʞ ʍıʇɥ ʇɥǝ sǝɹʌǝɹ·"
+      ],
+      "Email Address" : [
+         null,
+         "‮Ǝɯɐıʅ ∀ppɹǝss"
+      ],
+      "If you are NOT trying to sign into this site, just ignore this email." : [
+         null,
+         "‮Iɟ ʎon ɐɹǝ NO⊥ ʇɹʎıuƃ ʇo sıƃu ıuʇo ʇɥıs sıʇǝ´ ɾnsʇ ıƃuoɹǝ ʇɥıs ǝɯɐıʅ·"
+      ]
+   }
+}
+;
diff --git a/resources/static/i18n/en_US/client.json b/resources/static/i18n/en_US/client.json
new file mode 100644
index 000000000..d6d05dd3a
--- /dev/null
+++ b/resources/static/i18n/en_US/client.json
@@ -0,0 +1,125 @@
+var json_locale_data = {
+   "client" : {
+      "" : {
+         "Plural-Forms" : " nplurals=2; plural=(n != 1);",
+         "MIME-Version" : " 1.0",
+         "POT-Creation-Date" : " 2012-01-11 16:41-0800",
+         "Last-Translator" : " Austin King <ozten@mozilla.com>",
+         "Content-Type" : " text/plain; charset=UTF-8",
+         "PO-Revision-Date" : " 2012-01-10 17:32-0800",
+         "Language-Team" : " English",
+         "Content-Transfer-Encoding" : " 8bit",
+         "Project-Id-Version" : " PACKAGE VERSION",
+         "Report-Msgid-Bugs-To" : " "
+      },
+      "Always sign in using this email" : [
+         null,
+         ""
+      ],
+      "next" : [
+         null,
+         "next"
+      ],
+      "add" : [
+         null,
+         ""
+      ],
+      "This email looks new, so let&apos;s get you set up." : [
+         null,
+         "This email looks new, so let&apos;s get you set up."
+      ],
+      "The email field is required." : [
+         null,
+         "The email field is required."
+      ],
+      "New email address" : [
+         null,
+         ""
+      ],
+      "verify email" : [
+         null,
+         "verify email"
+      ],
+      "Sign in using" : [
+         null,
+         "Sign in using"
+      ],
+      "Password" : [
+         null,
+         "Password"
+      ],
+      "You already own that address!" : [
+         null,
+         ""
+      ],
+      "To finish signing in just click the verify link we sent to your email address." : [
+         null,
+         ""
+      ],
+      "forgot your password?" : [
+         null,
+         "forgot your password?"
+      ],
+      "This field must be an email address." : [
+         null,
+         "This field must be an email address."
+      ],
+      "Email" : [
+         null,
+         "Email"
+      ],
+      "We sent a confirmation email to <strong>%1</strong>" : [
+         null,
+         "Enter your email address to sign in to <strong>%1</strong>"
+      ],
+      "sign in" : [
+         null,
+         "Sign in using"
+      ],
+      "The account cannot be logged in with this username and password." : [
+         null,
+         "The account cannot be logged in with this username and password."
+      ],
+      "select email" : [
+         null,
+         "select email"
+      ],
+      "This is not me..." : [
+         null,
+         ""
+      ],
+      "Welcome to BrowserID!" : [
+         null,
+         "Welcome to BrowserID!"
+      ],
+      "If this is a mistake, just ignore the sent email and <a href=\"#\" class=\"cancelVerify\" id=\"back\">use another email address</a>." : [
+         null,
+         ""
+      ],
+      "We just sent an email to that address!  If you really want to send another, wait a minute or two and try again." : [
+         null,
+         "We just sent an email to that address!  If you really want to send another, wait a minute or two and try again."
+      ],
+      "Check your email!" : [
+         null,
+         ""
+      ],
+      "Enter your email address to sign in to <strong>%1</strong>" : [
+         null,
+         "Enter your email address to sign in to <strong>%1</strong>"
+      ],
+      "cancel" : [
+         null,
+         ""
+      ],
+      "The password field is required." : [
+         null,
+         "The password field is required."
+      ],
+      "Use a different email" : [
+         null,
+         "select email"
+      ]
+   }
+}
+;
diff --git a/resources/static/i18n/en_US/messages.json b/resources/static/i18n/en_US/messages.json
new file mode 100644
index 000000000..68d69585c
--- /dev/null
+++ b/resources/static/i18n/en_US/messages.json
@@ -0,0 +1,140 @@
+var json_locale_data = {
+   "messages" : {
+      "Error encountered trying to complete registration." : [
+         null,
+         ""
+      ],
+      "" : {
+         "MIME-Version" : " 1.0",
+         "POT-Creation-Date" : " 2012-01-11 16:41-0800",
+         "Last-Translator" : " FULL NAME <EMAIL@ADDRESS>",
+         "Content-Type" : " text/plain; charset=UTF-8",
+         "PO-Revision-Date" : " YEAR-MO-DA HO:MI+ZONE",
+         "Language-Team" : " LANGUAGE <LL@li.org>",
+         "Content-Transfer-Encoding" : " 8bit",
+         "Project-Id-Version" : " PACKAGE VERSION",
+         "Report-Msgid-Bugs-To" : " "
+      },
+      "Verification password is required." : [
+         null,
+         ""
+      ],
+      "BrowserID" : [
+         null,
+         ""
+      ],
+      "Finish signing into: " : [
+         null,
+         ""
+      ],
+      "Your Email" : [
+         null,
+         ""
+      ],
+      "Error comunicating with server." : [
+         null,
+         ""
+      ],
+      "Last step!" : [
+         null,
+         ""
+      ],
+      "BrowserID is the fast and secure way to sign in &mdash; <a target=\"_blank\" href=\"/about\">learn more</a>" : [
+         null,
+         ""
+      ],
+      "Your new address is set up and you should now be signed in. You may now close this window and go back to" : [
+         null,
+         ""
+      ],
+      "Verify Password" : [
+         null,
+         ""
+      ],
+      "Password must be between 8 and 80 characters long." : [
+         null,
+         ""
+      ],
+      "Complete Login to %1 using BrowserID" : [
+         null,
+         ""
+      ],
+      "(A better way to sign in)" : [
+         null,
+         ""
+      ],
+      "Finish registration by clicking this link:" : [
+         null,
+         ""
+      ],
+      "Thanks," : [
+         null,
+         ""
+      ],
+      "Communicating with server" : [
+         null,
+         ""
+      ],
+      "Enter a Password" : [
+         null,
+         ""
+      ],
+      "Error encountered while attempting to confirm your address. Have you previously verified this address?" : [
+         null,
+         ""
+      ],
+      "Thank you for signing up with <strong>BrowserID</strong>. You can now use your <strong>BrowserID</strong> account to <em>Sign In</em> or <em>Sign Up</em> to websites all across the web!" : [
+         null,
+         ""
+      ],
+      "Email Verification" : [
+         null,
+         ""
+      ],
+      "<strong class=\"email\">Your address</strong> has been verified!" : [
+         null,
+         ""
+      ],
+      "Browser ID" : [
+         null,
+         ""
+      ],
+      "Finish" : [
+         null,
+         ""
+      ],
+      "There was a problem with your signup link.  Has this address already been registered?" : [
+         null,
+         ""
+      ],
+      "Password is required." : [
+         null,
+         ""
+      ],
+      "Passwords do not match." : [
+         null,
+         ""
+      ],
+      "New Password" : [
+         null,
+         ""
+      ],
+      "Repeat Password" : [
+         null,
+         ""
+      ],
+      "Just a moment while we talk with the server." : [
+         null,
+         ""
+      ],
+      "Email Address" : [
+         null,
+         ""
+      ],
+      "If you are NOT trying to sign into this site, just ignore this email." : [
+         null,
+         ""
+      ]
+   }
+}
+;
diff --git a/resources/static/i18n/pl/messages.json b/resources/static/i18n/pl/messages.json
new file mode 100644
index 000000000..abe4b65eb
--- /dev/null
+++ b/resources/static/i18n/pl/messages.json
@@ -0,0 +1,188 @@
+var json_locale_data = {
+   "messages" : {
+      "Error encountered trying to complete registration." : [
+         null,
+         ""
+      ],
+      "" : {
+         "MIME-Version" : " 1.0",
+         "POT-Creation-Date" : " 2012-01-11 15:36-0800",
+         "Last-Translator" : " FULL NAME <EMAIL@ADDRESS>",
+         "Content-Type" : " text/plain; charset=UTF-8",
+         "PO-Revision-Date" : " YEAR-MO-DA HO:MI+ZONE",
+         "Language-Team" : " LANGUAGE <LL@li.org>",
+         "Content-Transfer-Encoding" : " 8bit",
+         "Project-Id-Version" : " PACKAGE VERSION",
+         "Report-Msgid-Bugs-To" : " "
+      },
+      "next" : [
+         null,
+         "następny"
+      ],
+      "Verification password is required." : [
+         null,
+         "Pole jest wymagane hasło."
+      ],
+      "BrowserID" : [
+         null,
+         "ID PrzeglÄ…darka"
+      ],
+      "Finish signing into: " : [
+         null,
+         ""
+      ],
+      "Your Email" : [
+         null,
+         "E-mail"
+      ],
+      "Sign in using" : [
+         null,
+         "Zaloguj siÄ™ za pomocÄ…"
+      ],
+      "forgot your password?" : [
+         null,
+         "zapomniałeś hasła?"
+      ],
+      "Error comunicating with server." : [
+         null,
+         ""
+      ],
+      "This field must be an email address." : [
+         null,
+         "To pole musi być adres e-mail."
+      ],
+      "Last step!" : [
+         null,
+         ""
+      ],
+      "BrowserID is the fast and secure way to sign in &mdash; <a target=\"_blank\" href=\"/about\">learn more</a>" : [
+         null,
+         "ID Przeglądarka jest szybki i bezpieczny sposób, aby się zalogować &mdash <a target=\"_blank\" href=\"/about\">Dowiedz się więcej</a>"
+      ],
+      "select email" : [
+         null,
+         "wybierz e-mail"
+      ],
+      "Your new address is set up and you should now be signed in. You may now close this window and go back to" : [
+         null,
+         ""
+      ],
+      "Verify Password" : [
+         null,
+         "hasło"
+      ],
+      "Password must be between 8 and 80 characters long." : [
+         null,
+         ""
+      ],
+      "Enter your email address to sign in to <strong>%1</strong>" : [
+         null,
+         "Wpisz swój adres e-mail, aby zalogować się do <strong>%1</strong>"
+      ],
+      "Complete Login to %1 using BrowserID" : [
+         null,
+         ""
+      ],
+      "(A better way to sign in)" : [
+         null,
+         ""
+      ],
+      "Finish registration by clicking this link:" : [
+         null,
+         ""
+      ],
+      "Thanks," : [
+         null,
+         ""
+      ],
+      "Communicating with server" : [
+         null,
+         ""
+      ],
+      "The email field is required." : [
+         null,
+         "Pole e-mail jest wymagane."
+      ],
+      "verify email" : [
+         null,
+         "sprawdzić e-mail"
+      ],
+      "Enter a Password" : [
+         null,
+         "hasło"
+      ],
+      "Error encountered while attempting to confirm your address. Have you previously verified this address?" : [
+         null,
+         ""
+      ],
+      "Thank you for signing up with <strong>BrowserID</strong>. You can now use your <strong>BrowserID</strong> account to <em>Sign In</em> or <em>Sign Up</em> to websites all across the web!" : [
+         null,
+         ""
+      ],
+      "Email Verification" : [
+         null,
+         ""
+      ],
+      "<strong class=\"email\">Your address</strong> has been verified!" : [
+         null,
+         ""
+      ],
+      "Browser ID" : [
+         null,
+         "ID PrzeglÄ…darka"
+      ],
+      "Finish" : [
+         null,
+         ""
+      ],
+      "This email looks new, so let's get you set up." : [
+         null,
+         "Ten e-mail wygląda nowy, więc przejdźmy skonfigurować."
+      ],
+      "There was a problem with your signup link.  Has this address already been registered?" : [
+         null,
+         ""
+      ],
+      "The account cannot be logged in with this username and password." : [
+         null,
+         "Konto nie może się zalogować w tym login i hasło."
+      ],
+      "Password is required." : [
+         null,
+         "Pole jest wymagane hasło."
+      ],
+      "Passwords do not match." : [
+         null,
+         ""
+      ],
+      "#~ \"We just sent an email to that address!  If you really want to send \"#~ \"another, wait a minute or two and try again.\"" : [
+         null,
+         "#~ \"Po prostu wysłał e-maila na ten adres! Jeśli naprawdę chcesz wysłać \"#~ \"innym, poczekać minutę lub dwie i spróbuj ponownie\""
+      ],
+      "New Password" : [
+         null,
+         "hasło"
+      ],
+      "Welcome to BrowserID!" : [
+         null,
+         "Witamy BrowserID!"
+      ],
+      "Repeat Password" : [
+         null,
+         "hasło"
+      ],
+      "Just a moment while we talk with the server." : [
+         null,
+         ""
+      ],
+      "Email Address" : [
+         null,
+         ""
+      ],
+      "If you are NOT trying to sign into this site, just ignore this email." : [
+         null,
+         ""
+      ]
+   }
+}
+;
diff --git a/resources/static/include.js b/resources/static/include.js
index a6aff07d3..d96a7e2ee 120000
--- a/resources/static/include.js
+++ b/resources/static/include.js
@@ -1 +1 @@
-include_js/include.js
\ No newline at end of file
+production/include.js
\ No newline at end of file
diff --git a/resources/static/shared/gettext.js b/resources/static/shared/gettext.js
new file mode 100644
index 000000000..8a905e6a1
--- /dev/null
+++ b/resources/static/shared/gettext.js
@@ -0,0 +1,1265 @@
+/*
+Pure Javascript implementation of Uniforum message translation.
+Copyright (C) 2008 Joshua I. Miller <unrtst@cpan.org>, all rights reserved
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU Library General Public License as published
+by the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+USA.
+
+=head1 NAME
+
+Javascript Gettext - Javascript implemenation of GNU Gettext API.
+
+=head1 SYNOPSIS
+
+ // //////////////////////////////////////////////////////////
+ // Optimum caching way
+ <script language="javascript" src="/path/LC_MESSAGES/myDomain.json"></script>
+ <script language="javascript" src="/path/Gettext.js'></script>
+
+ // assuming myDomain.json defines variable json_locale_data
+ var params = {  "domain" : "myDomain",
+                 "locale_data" : json_locale_data
+              };
+ var gt = new Gettext(params);
+ // create a shortcut if you'd like
+ function _ (msgid) { return gt.gettext(msgid); }
+ alert(_("some string"));
+ // or use fully named method
+ alert(gt.gettext("some string"));
+ // change to use a different "domain"
+ gt.textdomain("anotherDomain");
+ alert(gt.gettext("some string"));
+
+
+ // //////////////////////////////////////////////////////////
+ // The other way to load the language lookup is a "link" tag
+ // Downside is that not all browsers cache XMLHttpRequests the
+ // same way, so caching of the language data isn't guarenteed
+ // across page loads.
+ // Upside is that it's easy to specify multiple files
+ <link rel="gettext" href="/path/LC_MESSAGES/myDomain.json" />
+ <script language="javascript" src="/path/Gettext.js'></script>
+
+ var gt = new Gettext({ "domain" : "myDomain" });
+ // rest is the same
+
+
+ // //////////////////////////////////////////////////////////
+ // The reson the shortcuts aren't exported by default is because they'd be
+ // glued to the single domain you created. So, if you're adding i18n support
+ // to some js library, you should use it as so:
+
+ if (typeof(MyNamespace) == 'undefined') MyNamespace = {};
+ MyNamespace.MyClass = function () {
+     var gtParms = { "domain" : 'MyNamespace_MyClass' };
+     this.gt = new Gettext(gtParams);
+     return this;
+ };
+ MyNamespace.MyClass.prototype._ = function (msgid) {
+     return this.gt.gettext(msgid);
+ };
+ MyNamespace.MyClass.prototype.something = function () {
+     var myString = this._("this will get translated");
+ };
+
+ // //////////////////////////////////////////////////////////
+ // Adding the shortcuts to a global scope is easier. If that's
+ // ok in your app, this is certainly easier.
+ var myGettext = new Gettext({ 'domain' : 'myDomain' });
+ function _ (msgid) {
+     return myGettext.gettext(msgid);
+ }
+ alert( _("text") );
+
+ // //////////////////////////////////////////////////////////
+ // Data structure of the json data
+ // NOTE: if you're loading via the <script> tag, you can only
+ // load one file, but it can contain multiple domains.
+ var json_locale_data = {
+     "MyDomain" : {
+         "" : {
+             "header_key" : "header value",
+             "header_key" : "header value",
+         "msgid" : [ "msgid_plural", "msgstr", "msgstr_plural", "msgstr_pluralN" ],
+         "msgctxt\004msgid" : [ null, "msgstr" ],
+         },
+     "AnotherDomain" : {
+         },
+     }
+
+=head1 DESCRIPTION
+
+This is a javascript implementation of GNU Gettext, providing internationalization support for javascript. It differs from existing javascript implementations in that it will support all current Gettext features (ex. plural and context support), and will also support loading language catalogs from .mo, .po, or preprocessed json files (converter included).
+
+The locale initialization differs from that of GNU Gettext / POSIX. Rather than setting the category, domain, and paths, and letting the libs find the right file, you must explicitly load the file at some point. The "domain" will still be honored. Future versions may be expanded to include support for set_locale like features.
+
+
+=head1 INSTALL
+
+To install this module, simply copy the file lib/Gettext.js to a web accessable location, and reference it from your application.
+
+
+=head1 CONFIGURATION
+
+Configure in one of two ways:
+
+=over
+
+=item 1. Optimal. Load language definition from statically defined json data.
+
+    <script language="javascript" src="/path/locale/domain.json"></script>
+
+    // in domain.json
+    json_locale_data = {
+        "mydomain" : {
+            // po header fields
+            "" : {
+                "plural-forms" : "...",
+                "lang" : "en",
+                },
+            // all the msgid strings and translations
+            "msgid" : [ "msgid_plural", "translation", "plural_translation" ],
+        },
+    };
+    // please see the included bin/po2json script for the details on this format
+
+This method also allows you to use unsupported file formats, so long as you can parse them into the above format.
+
+=item 2. Use AJAX to load language file.
+
+Use XMLHttpRequest (actually, SJAX - syncronous) to load an external resource.
+
+Supported external formats are:
+
+=over
+
+=item * Javascript Object Notation (.json)
+
+(see bin/po2json)
+
+    type=application/json
+
+=item * Uniforum Portable Object (.po)
+
+(see GNU Gettext's xgettext)
+
+    type=application/x-po
+
+=item * Machine Object (compiled .po) (.mo)
+
+NOTE: .mo format isn't actually supported just yet, but support is planned.
+
+(see GNU Gettext's msgfmt)
+
+    type=application/x-mo
+
+=back
+
+=back
+
+=head1 METHODS
+
+The following methods are implemented:
+
+  new Gettext(args)
+  textdomain  (domain)
+  gettext     (msgid)
+  dgettext    (domainname, msgid)
+  dcgettext   (domainname, msgid, LC_MESSAGES)
+  ngettext    (msgid, msgid_plural, count)
+  dngettext   (domainname, msgid, msgid_plural, count)
+  dcngettext  (domainname, msgid, msgid_plural, count, LC_MESSAGES)
+  pgettext    (msgctxt, msgid)
+  dpgettext   (domainname, msgctxt, msgid)
+  dcpgettext  (domainname, msgctxt, msgid, LC_MESSAGES)
+  npgettext   (msgctxt, msgid, msgid_plural, count)
+  dnpgettext  (domainname, msgctxt, msgid, msgid_plural, count)
+  dcnpgettext (domainname, msgctxt, msgid, msgid_plural, count, LC_MESSAGES)
+  strargs     (string, args_array)
+
+
+=head2 new Gettext (args)
+
+Several methods of loading locale data are included. You may specify a plugin or alternative method of loading data by passing the data in as the "locale_data" option. For example:
+
+    var get_locale_data = function () {
+        // plugin does whatever to populate locale_data
+        return locale_data;
+    };
+    var gt = new Gettext( 'domain' : 'messages',
+                          'locale_data' : get_locale_data() );
+
+The above can also be used if locale data is specified in a statically included <SCRIPT> tag. Just specify the variable name in the call to new. Ex:
+
+    var gt = new Gettext( 'domain' : 'messages',
+                          'locale_data' : json_locale_data_variable );
+
+Finally, you may load the locale data by referencing it in a <LINK> tag. Simply exclude the 'locale_data' option, and all <LINK rel="gettext" ...> items will be tried. The <LINK> should be specified as:
+
+    <link rel="gettext" type="application/json" href="/path/to/file.json">
+    <link rel="gettext" type="text/javascript"  href="/path/to/file.json">
+    <link rel="gettext" type="application/x-po" href="/path/to/file.po">
+    <link rel="gettext" type="application/x-mo" href="/path/to/file.mo">
+
+args:
+
+=over
+
+=item domain
+
+The Gettext domain, not www.whatev.com. It's usually your applications basename. If the .po file was "myapp.po", this would be "myapp".
+
+=item locale_data
+
+Raw locale data (in json structure). If specified, from_link data will be ignored.
+
+=back
+
+=cut
+
+*/
+
+Gettext = function (args) {
+    this.domain         = 'messages';
+    // locale_data will be populated from <link...> if not specified in args
+    this.locale_data    = undefined;
+
+    // set options
+    var options = [ "domain", "locale_data" ];
+    if (this.isValidObject(args)) {
+        for (var i in args) {
+            for (var j=0; j<options.length; j++) {
+                if (i == options[j]) {
+                    // don't set it if it's null or undefined
+                    if (this.isValidObject(args[i]))
+                        this[i] = args[i];
+                }
+            }
+        }
+    }
+
+
+    // try to load the lang file from somewhere
+    this.try_load_lang();
+
+    return this;
+}
+
+Gettext.context_glue = "\004";
+Gettext._locale_data = {};
+
+Gettext.prototype.try_load_lang = function() {
+    // check to see if language is statically included
+    if (typeof(this.locale_data) != 'undefined') {
+        // we're going to reformat it, and overwrite the variable
+        var locale_copy = this.locale_data;
+        this.locale_data = undefined;
+        this.parse_locale_data(locale_copy);
+
+        if (typeof(Gettext._locale_data[this.domain]) == 'undefined') {
+            throw new Error("Error: Gettext 'locale_data' does not contain the domain '"+this.domain+"'");
+        }
+    }
+
+
+    // try loading from JSON
+    // get lang links
+    var lang_link = this.get_lang_refs();
+
+    if (typeof(lang_link) == 'object' && lang_link.length > 0) {
+        // NOTE: there will be a delay here, as this is async.
+        // So, any i18n calls made right after page load may not
+        // get translated.
+        // XXX: we may want to see if we can "fix" this behavior
+        for (var i=0; i<lang_link.length; i++) {
+            var link = lang_link[i];
+            if (link.type == 'application/json') {
+                if (! this.try_load_lang_json(link.href) ) {
+                    throw new Error("Error: Gettext 'try_load_lang_json' failed. Unable to exec xmlhttprequest for link ["+link.href+"]");
+                }
+            } else if (link.type == 'application/x-po') {
+                if (! this.try_load_lang_po(link.href) ) {
+                    throw new Error("Error: Gettext 'try_load_lang_po' failed. Unable to exec xmlhttprequest for link ["+link.href+"]");
+                }
+            } else {
+                // TODO: implement the other types (.mo)
+                throw new Error("TODO: link type ["+link.type+"] found, and support is planned, but not implemented at this time.");
+            }
+        }
+    }
+};
+
+// This takes the bin/po2json'd data, and moves it into an internal form
+// for use in our lib, and puts it in our object as:
+//  Gettext._locale_data = {
+//      domain : {
+//          head : { headfield : headvalue },
+//          msgs : {
+//              msgid : [ msgid_plural, msgstr, msgstr_plural ],
+//          },
+Gettext.prototype.parse_locale_data = function(locale_data) {
+    if (typeof(Gettext._locale_data) == 'undefined') {
+        Gettext._locale_data = { };
+    }
+
+    // suck in every domain defined in the supplied data
+    for (var domain in locale_data) {
+        // skip empty specs (flexibly)
+        if ((! locale_data.hasOwnProperty(domain)) || (! this.isValidObject(locale_data[domain])))
+            continue;
+        // skip if it has no msgid's
+        var has_msgids = false;
+        for (var msgid in locale_data[domain]) {
+            has_msgids = true;
+            break;
+        }
+        if (! has_msgids) continue;
+
+        // grab shortcut to data
+        var data = locale_data[domain];
+
+        // if they specifcy a blank domain, default to "messages"
+        if (domain == "") domain = "messages";
+        // init the data structure
+        if (! this.isValidObject(Gettext._locale_data[domain]) )
+            Gettext._locale_data[domain] = { };
+        if (! this.isValidObject(Gettext._locale_data[domain].head) )
+            Gettext._locale_data[domain].head = { };
+        if (! this.isValidObject(Gettext._locale_data[domain].msgs) )
+            Gettext._locale_data[domain].msgs = { };
+
+        for (var key in data) {
+            if (key == "") {
+                var header = data[key];
+                for (var head in header) {
+                    var h = head.toLowerCase();
+                    Gettext._locale_data[domain].head[h] = header[head];
+                }
+            } else {
+                Gettext._locale_data[domain].msgs[key] = data[key];
+            }
+        }
+    }
+
+    // build the plural forms function
+    for (var domain in Gettext._locale_data) {
+        if (this.isValidObject(Gettext._locale_data[domain].head['plural-forms']) &&
+            typeof(Gettext._locale_data[domain].head.plural_func) == 'undefined') {
+            // untaint data
+            var plural_forms = Gettext._locale_data[domain].head['plural-forms'];
+            var pf_re = new RegExp('^(\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;a-zA-Z0-9_\(\)])+)', 'm');
+            if (pf_re.test(plural_forms)) {
+                //ex english: "Plural-Forms: nplurals=2; plural=(n != 1);\n"
+                //pf = "nplurals=2; plural=(n != 1);";
+                //ex russian: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10< =4 && (n%100<10 or n%100>=20) ? 1 : 2)
+                //pf = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)";
+
+                var pf = Gettext._locale_data[domain].head['plural-forms'];
+                if (! /;\s*$/.test(pf)) pf = pf.concat(';');
+                /* We used to use eval, but it seems IE has issues with it.
+                 * We now use "new Function", though it carries a slightly
+                 * bigger performance hit.
+                var code = 'function (n) { var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) }; };';
+                Gettext._locale_data[domain].head.plural_func = eval("("+code+")");
+                */
+                var code = 'var plural; var nplurals; '+pf+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) };';
+                Gettext._locale_data[domain].head.plural_func = new Function("n", code);
+            } else {
+                throw new Error("Syntax error in language file. Plural-Forms header is invalid ["+plural_forms+"]");
+            }   
+
+        // default to english plural form
+        } else if (typeof(Gettext._locale_data[domain].head.plural_func) == 'undefined') {
+            Gettext._locale_data[domain].head.plural_func = function (n) {
+                var p = (n != 1) ? 1 : 0;
+                return { 'nplural' : 2, 'plural' : p };
+                };
+        } // else, plural_func already created
+    }
+
+    return;
+};
+
+
+// try_load_lang_po : do an ajaxy call to load in the .po lang defs
+Gettext.prototype.try_load_lang_po = function(uri) {
+    var data = this.sjax(uri);
+    if (! data) return;
+
+    var domain = this.uri_basename(uri);
+    var parsed = this.parse_po(data);
+
+    var rv = {};
+    // munge domain into/outof header
+    if (parsed) {
+        if (! parsed[""]) parsed[""] = {};
+        if (! parsed[""]["domain"]) parsed[""]["domain"] = domain;
+        domain = parsed[""]["domain"];
+        rv[domain] = parsed;
+
+        this.parse_locale_data(rv);
+    }
+
+    return 1;
+};
+
+Gettext.prototype.uri_basename = function(uri) {
+    var rv;
+    if (rv = uri.match(/^(.*\/)?(.*)/)) {
+        var ext_strip;
+        if (ext_strip = rv[2].match(/^(.*)\..+$/))
+            return ext_strip[1];
+        else
+            return rv[2];
+    } else {
+        return "";
+    }
+};
+
+Gettext.prototype.parse_po = function(data) {
+    var rv = {};
+    var buffer = {};
+    var lastbuffer = "";
+    var errors = [];
+    var lines = data.split("\n");
+    for (var i=0; i<lines.length; i++) {
+        // chomp
+        lines[i] = lines[i].replace(/(\n|\r)+$/, '');
+
+        var match;
+
+        // Empty line / End of an entry.
+        if (/^$/.test(lines[i])) {
+            if (typeof(buffer['msgid']) != 'undefined') {
+                var msg_ctxt_id = (typeof(buffer['msgctxt']) != 'undefined' &&
+                                   buffer['msgctxt'].length) ?
+                                  buffer['msgctxt']+Gettext.context_glue+buffer['msgid'] :
+                                  buffer['msgid'];
+                var msgid_plural = (typeof(buffer['msgid_plural']) != 'undefined' &&
+                                    buffer['msgid_plural'].length) ?
+                                   buffer['msgid_plural'] :
+                                   null;
+
+                // find msgstr_* translations and push them on
+                var trans = [];
+                for (var str in buffer) {
+                    var match;
+                    if (match = str.match(/^msgstr_(\d+)/))
+                        trans[parseInt(match[1])] = buffer[str];
+                }
+                trans.unshift(msgid_plural);
+
+                // only add it if we've got a translation
+                // NOTE: this doesn't conform to msgfmt specs
+                if (trans.length > 1) rv[msg_ctxt_id] = trans;
+
+                buffer = {};
+                lastbuffer = "";
+            }
+
+        // comments
+        } else if (/^#/.test(lines[i])) {
+            continue;
+
+        // msgctxt
+        } else if (match = lines[i].match(/^msgctxt\s+(.*)/)) {
+            lastbuffer = 'msgctxt';
+            buffer[lastbuffer] = this.parse_po_dequote(match[1]);
+
+        // msgid
+        } else if (match = lines[i].match(/^msgid\s+(.*)/)) {
+            lastbuffer = 'msgid';
+            buffer[lastbuffer] = this.parse_po_dequote(match[1]);
+
+        // msgid_plural
+        } else if (match = lines[i].match(/^msgid_plural\s+(.*)/)) {
+            lastbuffer = 'msgid_plural';
+            buffer[lastbuffer] = this.parse_po_dequote(match[1]);
+
+        // msgstr
+        } else if (match = lines[i].match(/^msgstr\s+(.*)/)) {
+            lastbuffer = 'msgstr_0';
+            buffer[lastbuffer] = this.parse_po_dequote(match[1]);
+
+        // msgstr[0] (treak like msgstr)
+        } else if (match = lines[i].match(/^msgstr\[0\]\s+(.*)/)) {
+            lastbuffer = 'msgstr_0';
+            buffer[lastbuffer] = this.parse_po_dequote(match[1]);
+
+        // msgstr[n]
+        } else if (match = lines[i].match(/^msgstr\[(\d+)\]\s+(.*)/)) {
+            lastbuffer = 'msgstr_'+match[1];
+            buffer[lastbuffer] = this.parse_po_dequote(match[2]);
+
+        // continued string
+        } else if (/^"/.test(lines[i])) {
+            buffer[lastbuffer] += this.parse_po_dequote(lines[i]);
+
+        // something strange
+        } else {
+            errors.push("Strange line ["+i+"] : "+lines[i]);
+        }
+    }
+
+
+    // handle the final entry
+    if (typeof(buffer['msgid']) != 'undefined') {
+        var msg_ctxt_id = (typeof(buffer['msgctxt']) != 'undefined' &&
+                           buffer['msgctxt'].length) ?
+                          buffer['msgctxt']+Gettext.context_glue+buffer['msgid'] :
+                          buffer['msgid'];
+        var msgid_plural = (typeof(buffer['msgid_plural']) != 'undefined' &&
+                            buffer['msgid_plural'].length) ?
+                           buffer['msgid_plural'] :
+                           null;
+
+        // find msgstr_* translations and push them on
+        var trans = [];
+        for (var str in buffer) {
+            var match;
+            if (match = str.match(/^msgstr_(\d+)/))
+                trans[parseInt(match[1])] = buffer[str];
+        }
+        trans.unshift(msgid_plural);
+
+        // only add it if we've got a translation
+        // NOTE: this doesn't conform to msgfmt specs
+        if (trans.length > 1) rv[msg_ctxt_id] = trans;
+
+        buffer = {};
+        lastbuffer = "";
+    }
+
+
+    // parse out the header
+    if (rv[""] && rv[""][1]) {
+        var cur = {};
+        var hlines = rv[""][1].split(/\\n/);
+        for (var i=0; i<hlines.length; i++) {
+            if (! hlines.length) continue;
+
+            var pos = hlines[i].indexOf(':', 0);
+            if (pos != -1) {
+                var key = hlines[i].substring(0, pos);
+                var val = hlines[i].substring(pos +1);
+                var keylow = key.toLowerCase();
+
+                if (cur[keylow] && cur[keylow].length) {
+                    errors.push("SKIPPING DUPLICATE HEADER LINE: "+hlines[i]);
+                } else if (/#-#-#-#-#/.test(keylow)) {
+                    errors.push("SKIPPING ERROR MARKER IN HEADER: "+hlines[i]);
+                } else {
+                    // remove begining spaces if any
+                    val = val.replace(/^\s+/, '');
+                    cur[keylow] = val;
+                }
+
+            } else {
+                errors.push("PROBLEM LINE IN HEADER: "+hlines[i]);
+                cur[hlines[i]] = '';
+            }
+        }
+
+        // replace header string with assoc array
+        rv[""] = cur;
+    } else {
+        rv[""] = {};
+    }
+
+    // TODO: XXX: if there are errors parsing, what do we want to do?
+    // GNU Gettext silently ignores errors. So will we.
+    // alert( "Errors parsing po file:\n" + errors.join("\n") );
+
+    return rv;
+};
+
+
+Gettext.prototype.parse_po_dequote = function(str) {
+    var match;
+    if (match = str.match(/^"(.*)"/)) {
+        str = match[1];
+    }
+    // unescale all embedded quotes (fixes bug #17504)
+    str = str.replace(/\\"/g, "\"");
+    return str;
+};
+
+
+// try_load_lang_json : do an ajaxy call to load in the lang defs
+Gettext.prototype.try_load_lang_json = function(uri) {
+    var data = this.sjax(uri);
+    if (! data) return;
+
+    var rv = this.JSON(data);
+    this.parse_locale_data(rv);
+
+    return 1;
+};
+
+// this finds all <link> tags, filters out ones that match our
+// specs, and returns a list of hashes of those
+Gettext.prototype.get_lang_refs = function() {
+    var langs = new Array();
+    var links = document.getElementsByTagName("link");
+    // find all <link> tags in dom; filter ours
+    for (var i=0; i<links.length; i++) {
+        if (links[i].rel == 'gettext' && links[i].href) {
+            if (typeof(links[i].type) == 'undefined' ||
+                links[i].type == '') {
+                if (/\.json$/i.test(links[i].href)) {
+                    links[i].type = 'application/json';
+                } else if (/\.js$/i.test(links[i].href)) {
+                    links[i].type = 'application/json';
+                } else if (/\.po$/i.test(links[i].href)) {
+                    links[i].type = 'application/x-po';
+                } else if (/\.mo$/i.test(links[i].href)) {
+                    links[i].type = 'application/x-mo';
+                } else {
+                    throw new Error("LINK tag with rel=gettext found, but the type and extension are unrecognized.");
+                }
+            }
+
+            links[i].type = links[i].type.toLowerCase();
+            if (links[i].type == 'application/json') {
+                links[i].type = 'application/json';
+            } else if (links[i].type == 'text/javascript') {
+                links[i].type = 'application/json';
+            } else if (links[i].type == 'application/x-po') {
+                links[i].type = 'application/x-po';
+            } else if (links[i].type == 'application/x-mo') {
+                links[i].type = 'application/x-mo';
+            } else {
+                throw new Error("LINK tag with rel=gettext found, but the type attribute ["+links[i].type+"] is unrecognized.");
+            }
+
+            langs.push(links[i]);
+        }
+    }
+    return langs;
+};
+
+
+/*
+
+=head2 textdomain( domain )
+
+Set domain for future gettext() calls
+
+A  message  domain  is  a  set of translatable msgid messages. Usually,
+every software package has its own message domain. The domain  name  is
+used to determine the message catalog where a translation is looked up;
+it must be a non-empty string.
+
+The current message domain is used by the gettext, ngettext, pgettext,
+npgettext functions, and by the dgettext, dcgettext, dngettext, dcngettext,
+dpgettext, dcpgettext, dnpgettext and dcnpgettext functions when called
+with a NULL domainname argument.
+
+If domainname is not NULL, the current message domain is set to
+domainname.
+
+If domainname is undefined, null, or empty string, the function returns
+the current message domain.
+
+If  successful,  the  textdomain  function  returns the current message
+domain, after possibly changing it. (ie. if you set a new domain, the 
+value returned will NOT be the previous domain).
+
+=cut
+
+*/
+Gettext.prototype.textdomain = function (domain) {
+    if (domain && domain.length) this.domain = domain;
+    return this.domain;
+}
+
+/*
+
+=head2 gettext( MSGID )
+
+Returns the translation for B<MSGID>.  Example:
+
+    alert( gt.gettext("Hello World!\n") );
+
+If no translation can be found, the unmodified B<MSGID> is returned,
+i. e. the function can I<never> fail, and will I<never> mess up your
+original message.
+
+One common mistake is to interpolate a variable into the string like this:
+
+  var translated = gt.gettext("Hello " + full_name);
+
+The interpolation will happen before it's passed to gettext, and it's 
+unlikely you'll have a translation for every "Hello Tom" and "Hello Dick"
+and "Hellow Harry" that may arise.
+
+Use C<strargs()> (see below) to solve this problem:
+
+  var translated = Gettext.strargs( gt.gettext("Hello %1"), [full_name] );
+
+This is espeically useful when multiple replacements are needed, as they 
+may not appear in the same order within the translation. As an English to
+French example:
+
+  Expected result: "This is the red ball"
+  English: "This is the %1 %2"
+  French:  "C'est le %2 %1"
+  Code: Gettext.strargs( gt.gettext("This is the %1 %2"), ["red", "ball"] );
+
+(The example is stupid because neither color nor thing will get
+translated here ...).
+
+=head2 dgettext( TEXTDOMAIN, MSGID )
+
+Like gettext(), but retrieves the message for the specified 
+B<TEXTDOMAIN> instead of the default domain.  In case you wonder what
+a textdomain is, see above section on the textdomain() call.
+
+=head2 dcgettext( TEXTDOMAIN, MSGID, CATEGORY )
+
+Like dgettext() but retrieves the message from the specified B<CATEGORY>
+instead of the default category C<LC_MESSAGES>.
+
+NOTE: the categories are really useless in javascript context. This is
+here for GNU Gettext API compatability. In practice, you'll never need
+to use this. This applies to all the calls including the B<CATEGORY>.
+
+
+=head2 ngettext( MSGID, MSGID_PLURAL, COUNT )
+
+Retrieves the correct translation for B<COUNT> items.  In legacy software
+you will often find something like:
+
+    alert( count + " file(s) deleted.\n" );
+
+or
+
+    printf(count + " file%s deleted.\n", $count == 1 ? '' : 's');
+
+I<NOTE: javascript lacks a builtin printf, so the above isn't a working example>
+
+The first example looks awkward, the second will only work in English
+and languages with similar plural rules.  Before ngettext() was introduced,
+the best practice for internationalized programs was:
+
+    if (count == 1) {
+        alert( gettext("One file deleted.\n") );
+    } else {
+        printf( gettext("%d files deleted.\n"), count );
+    }
+
+This is a nuisance for the programmer and often still not sufficient
+for an adequate translation.  Many languages have completely different
+ideas on numerals.  Some (French, Italian, ...) treat 0 and 1 alike,
+others make no distinction at all (Japanese, Korean, Chinese, ...),
+others have two or more plural forms (Russian, Latvian, Czech,
+Polish, ...).  The solution is:
+
+    printf( ngettext("One file deleted.\n",
+                     "%d files deleted.\n",
+                     count), // argument to ngettext!
+            count);          // argument to printf!
+
+In English, or if no translation can be found, the first argument
+(B<MSGID>) is picked if C<count> is one, the second one otherwise.
+For other languages, the correct plural form (of 1, 2, 3, 4, ...)
+is automatically picked, too.  You don't have to know anything about
+the plural rules in the target language, ngettext() will take care
+of that.
+
+This is most of the time sufficient but you will have to prove your
+creativity in cases like
+
+    "%d file(s) deleted, and %d file(s) created.\n"
+
+That said, javascript lacks C<printf()> support. Supplied with Gettext.js
+is the C<strargs()> method, which can be used for these cases:
+
+    Gettext.strargs( gt.ngettext( "One file deleted.\n",
+                                  "%d files deleted.\n",
+                                  count), // argument to ngettext!
+                     count); // argument to strargs!
+
+NOTE: the variable replacement isn't done for you, so you must
+do it yourself as in the above.
+
+=head2 dngettext( TEXTDOMAIN, MSGID, MSGID_PLURAL, COUNT )
+
+Like ngettext() but retrieves the translation from the specified
+textdomain instead of the default domain.
+
+=head2 dcngettext( TEXTDOMAIN, MSGID, MSGID_PLURAL, COUNT, CATEGORY )
+
+Like dngettext() but retrieves the translation from the specified
+category, instead of the default category C<LC_MESSAGES>.
+
+
+=head2 pgettext( MSGCTXT, MSGID )
+
+Returns the translation of MSGID, given the context of MSGCTXT.
+
+Both items are used as a unique key into the message catalog.
+
+This allows the translator to have two entries for words that may
+translate to different foreign words based on their context. For
+example, the word "View" may be a noun or a verb, which may be
+used in a menu as File->View or View->Source.
+
+    alert( pgettext( "Verb: To View", "View" ) );
+    alert( pgettext( "Noun: A View", "View"  ) );
+
+The above will both lookup different entries in the message catalog.
+
+In English, or if no translation can be found, the second argument
+(B<MSGID>) is returned.
+
+=head2 dpgettext( TEXTDOMAIN, MSGCTXT, MSGID )
+
+Like pgettext(), but retrieves the message for the specified 
+B<TEXTDOMAIN> instead of the default domain.
+
+=head2 dcpgettext( TEXTDOMAIN, MSGCTXT, MSGID, CATEGORY )
+
+Like dpgettext() but retrieves the message from the specified B<CATEGORY>
+instead of the default category C<LC_MESSAGES>.
+
+
+=head2 npgettext( MSGCTXT, MSGID, MSGID_PLURAL, COUNT )
+
+Like ngettext() with the addition of context as in pgettext().
+
+In English, or if no translation can be found, the second argument
+(MSGID) is picked if B<COUNT> is one, the third one otherwise.
+
+=head2 dnpgettext( TEXTDOMAIN, MSGCTXT, MSGID, MSGID_PLURAL, COUNT )
+
+Like npgettext() but retrieves the translation from the specified
+textdomain instead of the default domain.
+
+=head2 dcnpgettext( TEXTDOMAIN, MSGCTXT, MSGID, MSGID_PLURAL, COUNT, CATEGORY )
+
+Like dnpgettext() but retrieves the translation from the specified
+category, instead of the default category C<LC_MESSAGES>.
+
+=cut
+
+*/
+
+// gettext
+Gettext.prototype.gettext = function (msgid) {
+    var msgctxt;
+    var msgid_plural;
+    var n;
+    var category;
+    return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category);
+};
+
+Gettext.prototype.dgettext = function (domain, msgid) {
+    var msgctxt;
+    var msgid_plural;
+    var n;
+    var category;
+    return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category);
+};
+
+Gettext.prototype.dcgettext = function (domain, msgid, category) {
+    var msgctxt;
+    var msgid_plural;
+    var n;
+    return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category);
+};
+
+// ngettext
+Gettext.prototype.ngettext = function (msgid, msgid_plural, n) {
+    var msgctxt;
+    var category;
+    return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category);
+};
+
+Gettext.prototype.dngettext = function (domain, msgid, msgid_plural, n) {
+    var msgctxt;
+    var category;
+    return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category);
+};
+
+Gettext.prototype.dcngettext = function (domain, msgid, msgid_plural, n, category) {
+    var msgctxt;
+    return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category, category);
+};
+
+// pgettext
+Gettext.prototype.pgettext = function (msgctxt, msgid) {
+    var msgid_plural;
+    var n;
+    var category;
+    return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category);
+};
+
+Gettext.prototype.dpgettext = function (domain, msgctxt, msgid) {
+    var msgid_plural;
+    var n;
+    var category;
+    return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category);
+};
+
+Gettext.prototype.dcpgettext = function (domain, msgctxt, msgid, category) {
+    var msgid_plural;
+    var n;
+    return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category);
+};
+
+// npgettext
+Gettext.prototype.npgettext = function (msgctxt, msgid, msgid_plural, n) {
+    var category;
+    return this.dcnpgettext(null, msgctxt, msgid, msgid_plural, n, category);
+};
+
+Gettext.prototype.dnpgettext = function (domain, msgctxt, msgid, msgid_plural, n) {
+    var category;
+    return this.dcnpgettext(domain, msgctxt, msgid, msgid_plural, n, category);
+};
+
+// this has all the options, so we use it for all of them.
+Gettext.prototype.dcnpgettext = function (domain, msgctxt, msgid, msgid_plural, n, category) {
+    if (! this.isValidObject(msgid)) return '';
+
+    var plural = this.isValidObject(msgid_plural);
+    var msg_ctxt_id = this.isValidObject(msgctxt) ? msgctxt+Gettext.context_glue+msgid : msgid;
+
+    var domainname = this.isValidObject(domain)      ? domain :
+                     this.isValidObject(this.domain) ? this.domain :
+                                                       'messages';
+
+    // category is always LC_MESSAGES. We ignore all else
+    var category_name = 'LC_MESSAGES';
+    var category = 5;
+
+    var locale_data = new Array();
+    if (typeof(Gettext._locale_data) != 'undefined' &&
+        this.isValidObject(Gettext._locale_data[domainname])) {
+        locale_data.push( Gettext._locale_data[domainname] );
+
+    } else if (typeof(Gettext._locale_data) != 'undefined') {
+        // didn't find domain we're looking for. Search all of them.
+        for (var dom in Gettext._locale_data) {
+            locale_data.push( Gettext._locale_data[dom] );
+        }
+    }
+
+    var trans = [];
+    var found = false;
+    var domain_used; // so we can find plural-forms if needed
+    if (locale_data.length) {
+        for (var i=0; i<locale_data.length; i++) {
+            var locale = locale_data[i];
+            if (this.isValidObject(locale.msgs[msg_ctxt_id])) {
+                // make copy of that array (cause we'll be destructive)
+                for (var j=0; j<locale.msgs[msg_ctxt_id].length; j++) {
+                    trans[j] = locale.msgs[msg_ctxt_id][j];
+                }
+                trans.shift(); // throw away the msgid_plural
+                domain_used = locale;
+                found = true;
+                // only break if found translation actually has a translation.
+                if ( trans.length > 0 && trans[0].length != 0 )
+                    break;
+            }
+        }
+    }
+
+    // default to english if we lack a match, or match has zero length
+    if ( trans.length == 0 || trans[0].length == 0 ) {
+        trans = [ msgid, msgid_plural ];
+    }
+
+    var translation = trans[0];
+    if (plural) {
+        var p;
+        if (found && this.isValidObject(domain_used.head.plural_func) ) {
+            var rv = domain_used.head.plural_func(n);
+            if (! rv.plural) rv.plural = 0;
+            if (! rv.nplural) rv.nplural = 0;
+            // if plurals returned is out of bound for total plural forms
+            if (rv.nplural <= rv.plural) rv.plural = 0;
+            p = rv.plural;
+        } else {
+            p = (n != 1) ? 1 : 0;
+        }
+        if (this.isValidObject(trans[p]))
+            translation = trans[p];
+    }
+
+    return translation;
+};
+
+
+/*
+
+=head2 strargs (string, argument_array)
+
+  string : a string that potentially contains formatting characters.
+  argument_array : an array of positional replacement values
+
+This is a utility method to provide some way to support positional parameters within a string, as javascript lacks a printf() method.
+
+The format is similar to printf(), but greatly simplified (ie. fewer features).
+
+Any percent signs followed by numbers are replaced with the corrosponding item from the B<argument_array>.
+
+Example:
+
+    var string = "%2 roses are red, %1 violets are blue";
+    var args   = new Array("10", "15");
+    var result = Gettext.strargs(string, args);
+    // result is "15 roses are red, 10 violets are blue"
+
+The format numbers are 1 based, so the first itme is %1.
+
+A lone percent sign may be escaped by preceeding it with another percent sign.
+
+A percent sign followed by anything other than a number or another percent sign will be passed through as is.
+
+Some more examples should clear up any abmiguity. The following were called with the orig string, and the array as Array("[one]", "[two]") :
+
+  orig string "blah" becomes "blah"
+  orig string "" becomes ""
+  orig string "%%" becomes "%"
+  orig string "%%%" becomes "%%"
+  orig string "%%%%" becomes "%%"
+  orig string "%%%%%" becomes "%%%"
+  orig string "tom%%dick" becomes "tom%dick"
+  orig string "thing%1bob" becomes "thing[one]bob"
+  orig string "thing%1%2bob" becomes "thing[one][two]bob"
+  orig string "thing%1asdf%2asdf" becomes "thing[one]asdf[two]asdf"
+  orig string "%1%2%3" becomes "[one][two]"
+  orig string "tom%1%%2%aDick" becomes "tom[one]%2%aDick"
+
+This is especially useful when using plurals, as the string will nearly always contain the number.
+
+It's also useful in translated strings where the translator may have needed to move the position of the parameters.
+
+For example:
+
+  var count = 14;
+  Gettext.strargs( gt.ngettext('one banana', '%1 bananas', count), [count] );
+
+NOTE: this may be called as an instance method, or as a class method.
+
+  // instance method:
+  var gt = new Gettext(params);
+  gt.strargs(string, args);
+
+  // class method:
+  Gettext.strargs(string, args);
+
+=cut
+
+*/
+/* utility method, since javascript lacks a printf */
+Gettext.strargs = function (str, args) {
+    // make sure args is an array
+    if ( null == args ||
+         'undefined' == typeof(args) ) {
+        args = [];
+    } else if (args.constructor != Array) {
+        args = [args];
+    }
+
+    // NOTE: javascript lacks support for zero length negative look-behind
+    // in regex, so we must step through w/ index.
+    // The perl equiv would simply be:
+    //    $string =~ s/(?<!\%)\%([0-9]+)/$args[$1]/g;
+    //    $string =~ s/\%\%/\%/g; # restore escaped percent signs
+
+    var newstr = "";
+    while (true) {
+        var i = str.indexOf('%');
+        var match_n;
+
+        // no more found. Append whatever remains
+        if (i == -1) {
+            newstr += str;
+            break;
+        }
+
+        // we found it, append everything up to that
+        newstr += str.substr(0, i);
+
+        // check for escpaed %%
+        if (str.substr(i, 2) == '%%') {
+            newstr += '%';
+            str = str.substr((i+2));
+
+        // % followed by number
+        } else if ( match_n = str.substr(i).match(/^%(\d+)/) ) {
+            var arg_n = parseInt(match_n[1]);
+            var length_n = match_n[1].length;
+            if ( arg_n > 0 && args[arg_n -1] != null && typeof(args[arg_n -1]) != 'undefined' )
+                newstr += args[arg_n -1];
+            str = str.substr( (i + 1 + length_n) );
+
+        // % followed by some other garbage - just remove the %
+        } else {
+            newstr += '%';
+            str = str.substr((i+1));
+        }
+    }
+
+    return newstr;
+}
+
+/* instance method wrapper of strargs */
+Gettext.prototype.strargs = function (str, args) {
+    return Gettext.strargs(str, args);
+}
+
+/* verify that something is an array */
+Gettext.prototype.isArray = function (thisObject) {
+    return this.isValidObject(thisObject) && thisObject.constructor == Array;
+};
+
+/* verify that an object exists and is valid */
+Gettext.prototype.isValidObject = function (thisObject) {
+    if (null == thisObject) {
+        return false;
+    } else if ('undefined' == typeof(thisObject) ) {
+        return false;
+    } else {
+        return true;
+    }
+};
+
+Gettext.prototype.sjax = function (uri) {
+    var xmlhttp;
+    if (window.XMLHttpRequest) {
+        xmlhttp = new XMLHttpRequest();
+    } else if (navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) {
+        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+    } else {
+        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+    }
+
+    if (! xmlhttp)
+        throw new Error("Your browser doesn't do Ajax. Unable to support external language files.");
+
+    xmlhttp.open('GET', uri, false);
+    try { xmlhttp.send(null); }
+    catch (e) { return; }
+
+    // we consider status 200 and 0 as ok.
+    // 0 happens when we request local file, allowing this to run on local files
+    var sjax_status = xmlhttp.status;
+    if (sjax_status == 200 || sjax_status == 0) {
+        return xmlhttp.responseText;
+    } else {
+        var error = xmlhttp.statusText + " (Error " + xmlhttp.status + ")";
+        if (xmlhttp.responseText.length) {
+            error += "\n" + xmlhttp.responseText;
+        }
+        alert(error);
+        return;
+    }
+}
+
+Gettext.prototype.JSON = function (data) {
+    return eval('(' + data + ')');
+}
+
+
+/*
+
+=head1 NOTES
+
+These are some notes on the internals
+
+=over
+
+=item LOCALE CACHING
+
+Loaded locale data is currently cached class-wide. This means that if two scripts are both using Gettext.js, and both share the same gettext domain, that domain will only be loaded once. This will allow you to grab a new object many times from different places, utilize the same domain, and share a single translation file. The downside is that a domain won't be RE-loaded if a new object is instantiated on a domain that had already been instantiated.
+
+=back
+
+=head1 BUGS / TODO
+
+=over
+
+=item error handling
+
+Currently, there are several places that throw errors. In GNU Gettext, there are no fatal errors, which allows text to still be displayed regardless of how broken the environment becomes. We should evaluate and determine where we want to stand on that issue.
+
+=item syncronous only support (no ajax support)
+
+Currently, fetching language data is done purely syncronous, which means the page will halt while those files are fetched/loaded.
+
+This is often what you want, as then following translation requests will actually be translated. However, if all your calls are done dynamically (ie. error handling only or something), loading in the background may be more adventagous.
+
+It's still recommended to use the statically defined <script ...> method, which should have the same delay, but it will cache the result.
+
+=item domain support
+
+domain support while using shortcut methods like C<_('string')> or C<i18n('string')>.
+
+Under normal apps, the domain is usually set globally to the app, and a single language file is used. Under javascript, you may have multiple libraries or applications needing translation support, but the namespace is essentially global.
+
+It's recommended that your app initialize it's own shortcut with it's own domain.  (See examples/wrapper/i18n.js for an example.)
+
+Basically, you'll want to accomplish something like this:
+
+    // in some other .js file that needs i18n
+    this.i18nObj = new i18n;
+    this.i18n = this.i18nObj.init('domain');
+    // do translation
+    alert( this.i18n("string") );
+
+If you use this raw Gettext object, then this is all handled for you, as you have your own object then, and will be calling C<myGettextObject.gettext('string')> and such.
+
+
+=item encoding
+
+May want to add encoding/reencoding stuff. See GNU iconv, or the perl module Locale::Recode from libintl-perl.
+
+=back
+
+
+=head1 COMPATABILITY
+
+This has been tested on the following browsers. It may work on others, but these are all those to which I have access.
+
+    FF1.5, FF2, FF3, IE6, IE7, Opera9, Opera10, Safari3.1, Chrome
+
+    *FF = Firefox
+    *IE = Internet Explorer
+
+
+=head1 REQUIRES
+
+bin/po2json requires perl, and the perl modules Locale::PO and JSON.
+
+=head1 SEE ALSO
+
+bin/po2json (included),
+examples/normal/index.html,
+examples/wrapper/i18n.html, examples/wrapper/i18n.js,
+Locale::gettext_pp(3pm), POSIX(3pm), gettext(1), gettext(3)
+
+=head1 AUTHOR
+
+Copyright (C) 2008, Joshua I. Miller E<lt>unrtst@cpan.orgE<gt>, all rights reserved. See the source code for details.
+
+=cut
+
+*/
+
diff --git a/resources/static/shared/renderer.js b/resources/static/shared/renderer.js
index 4b66dafa0..a3ac39687 100644
--- a/resources/static/shared/renderer.js
+++ b/resources/static/shared/renderer.js
@@ -24,7 +24,15 @@ BrowserID.Renderer = (function() {
         url: "/dialog/views/" + body + ".ejs"
       };
     }
-
+    if (vars) {
+      var params = {
+            "domain" : "client",
+            "locale_data" : json_locale_data
+      };      
+      var gt = new Gettext(params);
+      vars['gettext'] = gt.gettext.bind(gt);
+      vars['strargs'] = gt.strargs.bind(gt);
+    }
     var html = new EJS(config).render(vars);
     return html;
   }
@@ -42,6 +50,5 @@ BrowserID.Renderer = (function() {
   return {
     render: render,
     append: append
-  }
+  };
 }());
-
diff --git a/resources/views/add_email_address.ejs b/resources/views/add_email_address.ejs
index 1c2ee3ffa..13b6a5af6 100644
--- a/resources/views/add_email_address.ejs
+++ b/resources/views/add_email_address.ejs
@@ -5,48 +5,48 @@
 <div id="vAlign" class="display_always">
     <div id="signUpFormWrap">
         <ul class="notifications">
-            <li class="notification error" id="cannotconfirm">Error encountered while attempting to confirm your address. Have you previously verified this address?</li>
-            <li class="notification error" id="cannotcomplete">Error encountered trying to complete registration.</li>
+            <li class="notification error" id="cannotconfirm"><%= gettext('Error encountered while attempting to confirm your address. Have you previously verified this address?') %></li>
+            <li class="notification error" id="cannotcomplete"><%= gettext('Error encountered trying to complete registration.') %></li>
         </ul>
 
         <form id="signUpForm" class="cf">
-            <p class="hint siteinfo">Finish signing into: <strong><span class="website"></span></strong></p>
+            <p class="hint siteinfo"><%= gettext('Finish signing into: ') %><strong><span class="website"></span></strong></p>
 
-            <h1 class="serif">Email Verification</h1>
+            <h1 class="serif"><%= gettext('Email Verification') %></h1>
 
             <ul class="inputs password_entry">
                 <li>
-                    <label class="serif" for="email">Email Address</label>
-                    <input class="youraddress sans email" id="email" placeholder="Your Email" type="email" value="" disabled="disabled" maxlength="254" />
+                    <label class="serif" for="email"><%= gettext('Email Address') %></label>
+                    <input class="youraddress sans email" id="email" placeholder="<%= gettext('Your Email') %>" type="email" value="" disabled="disabled" maxlength="254" />
                 </li>
                 <li>
-                    <label class="serif" for="password">New Password</label>
-                    <input class="sans" id="password" placeholder="Enter a Password" type="password" autofocus maxlength=80 />
+                    <label class="serif" for="password"><%= gettext('New Password') %></label>
+                    <input class="sans" id="password" placeholder="<%= gettext('Enter a Password') %>" type="password" autofocus maxlength=80 />
 
                     <div class="tooltip" id="password_required" for="password">
-                      Password is required.
+                      <%= gettext('Password is required.') %>
                     </div>
 
                     <div class="tooltip" id="password_length" for="password">
-                      Password must be between 8 and 80 characters long.
+                      <%= gettext('Password must be between 8 and 80 characters long.') %>
                     </div>
                 </li>
                 <li>
-                    <label class="serif" for="vpassword">Verify Password</label>
-                    <input class="sans" id="vpassword" placeholder="Repeat Password" type="password" maxlength=80 />
+                    <label class="serif" for="vpassword"><%= gettext('Verify Password') %></label>
+                    <input class="sans" id="vpassword" placeholder="<%= gettext('Repeat Password') %>" type="password" maxlength=80 />
 
                     <div class="tooltip" id="vpassword_required" for="vpassword">
-                      Verification password is required.
+                      <%= gettext('Verification password is required.') %>
                     </div>
 
                     <div class="tooltip" id="passwords_no_match" for="vpassword">
-                      Passwords do not match.
+                      <%= gettext('Passwords do not match.') %>
                     </div>
                 </li>
             </ul>
 
             <div class="submit cf password_entry">
-                <button>Finish</button>
+                <button><%= gettext('Finish') %></button>
             </div>
 
 
@@ -54,12 +54,10 @@
 
         <div id="congrats">
             <p class="serif">
-                <strong class="email">Your address</strong> has been verified!
+                <%- gettext('<strong class="email">Your address</strong> has been verified!') %>
 
                 <p class="siteinfo">
-                  Your new address is set up and you should now be signed in.
-                  You may now close this window and go back to
-                  <strong class="website"></strong>
+                  <%= gettext('Your new address is set up and you should now be signed in. You may now close this window and go back to') %> <strong class="website"></strong>
                 </p>
             </p>
         </div>
diff --git a/resources/views/dialog.ejs b/resources/views/dialog.ejs
index 89e8f40ec..32d0da73e 100644
--- a/resources/views/dialog.ejs
+++ b/resources/views/dialog.ejs
@@ -24,8 +24,8 @@
     <section id="wait">
         <div class="table">
             <div class="vertical contents">
-                <h2>Communicating with server</h2>
-                <p>Just a moment while we talk with the server.</p>
+                <h2><%= gettext('Communicating with server') %></h2>
+                <p>><%= gettext('Just a moment while we talk with the server.') %></p>
             </div>
         </div>
     </section>
diff --git a/resources/views/dialog_layout.ejs b/resources/views/dialog_layout.ejs
index e794d1600..3303649ac 100644
--- a/resources/views/dialog_layout.ejs
+++ b/resources/views/dialog_layout.ejs
@@ -2,7 +2,7 @@
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-<html>
+<html LANG="<%= lang %>" dir="<%= lang_dir %>">
 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; width=device-width;">
@@ -17,7 +17,7 @@
       <link href="/dialog/css/m.css" rel="stylesheet" type="text/css">
   <% } %>
   <link href="https://fonts.googleapis.com/css?family=Droid+Serif:400,400italic,700,700italic" rel="stylesheet" type="text/css">
-  <title>Browser ID</title>
+  <title><%= gettext('Browser ID') %></title>
 </head>
   <body class="waiting">
       <div id="wrapper">
@@ -41,7 +41,7 @@
                 </ul-->
 
                 <div class="learn">
-                    BrowserID is the fast and secure way to sign in &mdash; <a target="_blank" href="/about">learn more</a>
+<%- gettext('BrowserID is the fast and secure way to sign in &mdash; <a target="_blank" href="/about">learn more</a>') %>
                 </div>
 
           </footer>
@@ -50,13 +50,15 @@
 
       <% if (useJavascript !== false) { %>
         <% if (production) { %>
-          <script type="text/javascript" src="/production/dialog.js"></script>
+          <script type="text/javascript" src="/production/<%= locale %>/dialog.js"></script>
         <% } else { %>
           <script type="text/javascript" src="/lib/jquery-1.7.1.min.js"></script>
           <script type="text/javascript" src="/lib/winchan.js"></script>
           <script type="text/javascript" src="/lib/underscore-min.js"></script>
           <script type="text/javascript" src="/lib/vepbundle.js"></script>
           <script type="text/javascript" src="/lib/ejs.js"></script>
+          <script type="text/javascript" src="/i18n/<%= locale %>/client.json"></script>
+          <script type="text/javascript" src="/shared/gettext.js"></script>
           <script type="text/javascript" src="/shared/browserid.js"></script>
           <script type="text/javascript" src="/lib/hub.js"></script>
           <script type="text/javascript" src="/lib/dom-jquery.js"></script>
diff --git a/resources/static/test/index.html b/resources/views/test.ejs
similarity index 100%
rename from resources/static/test/index.html
rename to resources/views/test.ejs
diff --git a/resources/views/verify_email_address.ejs b/resources/views/verify_email_address.ejs
index 1a682d1af..e8ead6f6f 100644
--- a/resources/views/verify_email_address.ejs
+++ b/resources/views/verify_email_address.ejs
@@ -1,64 +1,62 @@
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+<% /* This Source Code Form is subject to the terms of the Mozilla Public
+      License, v. 2.0. If a copy of the MPL was not distributed with this
+      file, You can obtain one at http://mozilla.org/MPL/2.0/. */ %>
 
 <div id="vAlign" class="display_always">
     <div id="signUpFormWrap">
         <ul class="notifications">
-            <li class="notification error" id="cannotconfirm">There was a problem with your signup link.  Has this address already been registered?</li>
-            <li class="notification error" id="cannotcommunicate">Error comunicating with server.</li>
-            <li class="notification error" id="cannotcomplete">Error encountered trying to complete registration.</li>
+            <li class="notification error" id="cannotconfirm"><%= gettext('There was a problem with your signup link.  Has this address already been registered?') %></li>
+            <li class="notification error" id="cannotcommunicate"><%= gettext('Error comunicating with server.') %></li>
+            <li class="notification error" id="cannotcomplete"><%= gettext('Error encountered trying to complete registration.') %></li>
         </ul>
 
         <form id="signUpForm" class="cf">
-            <p class="hint siteinfo">Finish signing into: <strong><span class="website"></span></strong></p>
-            <h1 class="serif">Last step!</h1>
+            <p class="hint siteinfo"><%= gettext('Finish signing into: ') %><strong><span class="website"></span></strong></p>
+            <h1 class="serif"><%= gettext('Last step!') %></h1>
 
             <ul class="inputs">
                 <li>
-                    <label class="serif" for="email">Email Address</label>
-                    <input class="youraddress sans" id="email" placeholder="Your Email" type="email" value="" disabled="disabled" maxlength="254" />
+                    <label class="serif" for="email"><%= gettext('Email Address') %></label>
+                    <input class="youraddress sans" id="email" placeholder="<%= gettext('Your Email') %>" type="email" value="" disabled="disabled" maxlength="254" />
                 </li>
                 <li>
-                    <label class="serif" for="password">New Password</label>
-                    <input class="sans" id="password" placeholder="Enter a Password" type="password" autofocus maxlength=80 />
+                    <label class="serif" for="password"><%= gettext('New Password') %></label>
+                    <input class="sans" id="password" placeholder="<%= gettext('Enter a Password') %>" type="password" autofocus maxlength=80 />
 
                     <div class="tooltip" id="password_required" for="password">
-                      Password is required.
+                      <%= gettext('Password is required.') %>
                     </div>
 
                     <div class="tooltip" id="password_length" for="password">
-                      Password must be between 8 and 80 characters long.
+                      <%= gettext('Password must be between 8 and 80 characters long.') %>
                     </div>
                 </li>
                 <li>
-                    <label class="serif" for="vpassword">Verify Password</label>
-                    <input class="sans" id="vpassword" placeholder="Repeat Password" type="password" maxlength=80 />
+                    <label class="serif" for="vpassword"><%= gettext('Verify Password') %></label>
+                    <input class="sans" id="vpassword" placeholder="<%= gettext('Repeat Password') %>" type="password" maxlength=80 />
 
                     <div class="tooltip" id="vpassword_required" for="vpassword">
-                      Verification password is required.
+                      <%= gettext('Verification password is required.') %>
                     </div>
 
                     <div class="tooltip" id="passwords_no_match" for="vpassword">
-                      Passwords do not match.
+                      <%= gettext('Passwords do not match.') %>
                     </div>
                 </li>
             </ul>
 
             <div class="submit cf">
-                <button>Finish</button>
+                <button><%= gettext('Finish') %></button>
             </div>
 
         </form>
 
         <div id="congrats">
-            <p class="serif">Thank you for signing up with <strong>BrowserID</strong>. You can now use your <strong>BrowserID</strong> account to <em>Sign In</em> or <em>Sign Up</em> to websites all across the web!
+            <p class="serif"><%- gettext('Thank you for signing up with <strong>BrowserID</strong>. You can now use your <strong>BrowserID</strong> account to <em>Sign In</em> or <em>Sign Up</em> to websites all across the web!') %>
             </p>
 
             <p class="serif siteinfo">
-              Your new address is set up and you should now be signed in.
-              You may now close this window and go back to
-              <strong class="website"></strong>
+              <%= gettext('Your new address is set up and you should now be signed in. You may now close this window and go back to') %> <strong class="website"></strong>
             </p>
         </div>
 
diff --git a/scripts/compile_mo.sh b/scripts/compile_mo.sh
new file mode 100755
index 000000000..8330cacec
--- /dev/null
+++ b/scripts/compile_mo.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# syntax:
+# compile-mo.sh locale-dir/
+
+function usage() {
+    echo "syntax:"
+    echo "compile.sh locale-dir/"
+    exit 1
+}
+
+# check if file and dir are there
+if [[ ($# -ne 1) || (! -d "$1") ]]; then usage; fi
+
+for lang in `find $1 -type f -name "*.po"`; do
+    dir=`dirname $lang`
+    stem=`basename $lang .po`
+    msgfmt -o ${dir}/${stem}.mo $lang
+done
diff --git a/scripts/compress.sh b/scripts/compress.sh
index 433a8c6db..516286aa6 100755
--- a/scripts/compress.sh
+++ b/scripts/compress.sh
@@ -58,7 +58,10 @@ cp templates.js $BUILD_PATH/templates.js
 cd ../..
 
 # produce the dialog js
-cat lib/jquery-1.7.1.min.js lib/winchan.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js shared/browserid.js lib/hub.js lib/dom-jquery.js lib/module.js lib/jschannel.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/provisioning.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js dialog/resources/internal_api.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/page.js dialog/controllers/code_check.js dialog/controllers/actions.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgot_password.js dialog/controllers/check_registration.js dialog/controllers/pick_email.js dialog/controllers/add_email.js dialog/controllers/required_email.js dialog/controllers/verify_primary_user.js dialog/controllers/provision_primary_user.js dialog/controllers/primary_user_provisioned.js dialog/controllers/email_chosen.js dialog/start.js > $BUILD_PATH/dialog.uncompressed.js
+for locale in `../../scripts/production_locales`; do
+    mkdir -p $BUILD_PATH/$locale
+    cat lib/jquery-1.7.1.min.js lib/winchan.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js i18n/${locale}/client.json shared/gettext.js shared/browserid.js lib/hub.js lib/dom-jquery.js lib/module.js lib/jschannel.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/provisioning.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js dialog/resources/internal_api.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/page.js dialog/controllers/code_check.js dialog/controllers/actions.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgotpassword.js dialog/controllers/check_registration.js dialog/controllers/pick_email.js dialog/controllers/add_email.js dialog/controllers/required_email.js dialog/controllers/verify_primary_user.js dialog/controllers/provision_primary_user.js dialog/controllers/primary_user_provisioned.js dialog/controllers/set_password.js dialog/controllers/email_chosen.js dialog/start.js > $BUILD_PATH/$locale/dialog.uncompressed.js
+done
 
 # produce the dialog css
 cat css/common.css dialog/css/popup.css dialog/css/m.css > $BUILD_PATH/dialog.uncompressed.css
@@ -81,9 +84,14 @@ echo '****Compressing all JS, CSS****'
 echo ''
 
 cd $PRODUCTION_PATH
+
+pwd 
 # minify the JS
 $UGLIFY < $BUILD_PATH/include.uncompressed.js > include.js
-$UGLIFY < $BUILD_PATH/dialog.uncompressed.js > dialog.js
+for locale in `../../../scripts/production_locales`; do
+    mkdir -p $locale
+    $UGLIFY < $BUILD_PATH/$locale/dialog.uncompressed.js > $locale/dialog.js
+done
 $UGLIFY < $BUILD_PATH/communication_iframe.uncompressed.js > communication_iframe.js
 $UGLIFY < $BUILD_PATH/browserid.uncompressed.js > browserid.js
 
diff --git a/scripts/extract_po.sh b/scripts/extract_po.sh
new file mode 100755
index 000000000..a6f6da912
--- /dev/null
+++ b/scripts/extract_po.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# syntax:
+# extract-po.sh
+
+
+# messages.po is server side strings
+xgettext  -j --keyword=_ -L Perl --output-dir=locale/templates/LC_MESSAGES --from-code=utf-8 --output=messages.pot\
+ `find lib -name '*.js' | grep -v 'i18n.js'`
+xgettext -j -L PHP --keyword=_ --output-dir=locale/templates/LC_MESSAGES --output=messages.pot `find resources/views -name '*.ejs'`
+xgettext -j -L PHP --keyword=_ --output-dir=locale/templates/LC_MESSAGES --output=messages.pot `find lib/browserid -name '*.ejs'`
+
+# client.po 
+# js
+xgettext -j -L Perl --output-dir=locale/templates/LC_MESSAGES --from-code=utf-8 --output=client.pot\
+ `find resources/static -name '*.js' | grep -v /lib/ | grep -v /build/ | grep -v /production/ | grep -v 'gettext.js'`
+xgettext -j -L Perl --output-dir=locale/templates/LC_MESSAGES --output=client.pot `find resources/static/dialog/ -name '*.js'`
+# ejs
+xgettext -j -L PHP --keyword=_ --output-dir=locale/templates/LC_MESSAGES --output=client.pot `find resources/static -name '*.ejs'`
+
+
+
+
diff --git a/scripts/merge_po.sh b/scripts/merge_po.sh
new file mode 100755
index 000000000..a8481b4f8
--- /dev/null
+++ b/scripts/merge_po.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# syntax:
+# compile-mo.sh locale-dir/
+
+function usage() {
+    echo "syntax:"
+    echo "compile.sh locale-dir/"
+    exit 1
+}
+
+# check if file and dir are there
+if [[ ($# -ne 1) || (! -d "$1") ]]; then usage; fi
+
+for lang in `find $1 -type f -name "*.po"`; do
+    dir=`dirname $lang`
+    stem=`basename $lang .po`
+    msgmerge -o ${dir}/${stem}.po.tmp ${dir}/${stem}.po $1/templates/LC_MESSAGES/${stem}.pot
+    mv ${dir}/${stem}.po.tmp ${dir}/${stem}.po
+done
+
+# Optionally auto-localize our test locale db-LB
+if hash podebug >/dev/null; then
+    for catalog in messages client; do
+                                                                                                         
+        echo "Translating ${catalog}.po"
+        podebug --rewrite=flipped -i locale/templates/LC_MESSAGES/${catalog}.pot\
+               -o locale/eo/LC_MESSAGES/${catalog}.po
+    done  
+else
+  echo 'Skipping db-LB, install translate-toolkit if you want to have that up-to-date.'
+fi
diff --git a/scripts/production_locales b/scripts/production_locales
new file mode 100755
index 000000000..2ba990ca8
--- /dev/null
+++ b/scripts/production_locales
@@ -0,0 +1,18 @@
+#!/usr/bin/env node
+/* This is a helper script for compress.sh */
+
+// configuration will create directories under VAR_PATH
+process.env['VAR_PATH'] = '/tmp/browserid';
+
+// Pick up production languages
+process.env['NODE_ENV'] = 'production';
+
+var path = require('path'),
+    format = require('util').format,
+
+    config = require(path.join(__dirname, '../lib/configuration.js')),
+    i18n = require(path.join(__dirname, '../lib/i18n.js'));
+
+var langs = config.get('supported_languages');
+
+process.stdout.write(format("%s\n", langs.map(i18n.localeFrom).join(' ')));
\ No newline at end of file
-- 
GitLab