diff --git a/bin/dbwriter b/bin/dbwriter index ab4933e4dd16395a77a404d669d02892665a0f36..4d92017b0130935d251243fab026fb72e3d30022 100755 --- a/bin/dbwriter +++ b/bin/dbwriter @@ -15,7 +15,6 @@ 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'), @@ -60,12 +59,6 @@ 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/lib/i18n.js b/lib/i18n.js index 4c880dd426c2ea40b4480db02fee3f3c6dedeaef..d365aaf9e68013e9f5ee547ad6b529ff95c06d11 100644 --- a/lib/i18n.js +++ b/lib/i18n.js @@ -4,14 +4,14 @@ /* * 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. */ @@ -24,7 +24,7 @@ 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'], @@ -45,7 +45,7 @@ exports.abide = function (options) { return function(req, resp, next) { var langs = parseAcceptLanguage(req.headers['accept-language']), lang_dir, - lang = bestLanguage(langs, options.supported_languages, + lang = bestLanguage(langs, options.supported_languages, options.default_lang), locale; @@ -72,7 +72,7 @@ exports.abide = function (options) { gt = new Gettext(); // app startup ??? - mo_path = path.join(__dirname, '..', options.locale_directory, locale, + mo_path = path.join(__dirname, '..', options.locale_directory, locale, 'LC_MESSAGES', 'messages.mo'); resp.local('strargs', strargs); @@ -89,9 +89,9 @@ exports.abide = function (options) { 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 + ']'); + // TODO if in development mode, warn, test ignore and 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; @@ -142,7 +142,7 @@ exports.parseAcceptLanguage = parseAcceptLanguage = function (header) { // 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(); }); diff --git a/lib/wsapi.js b/lib/wsapi.js index 45ca5854e9a98398dfdaf1086ee5929f82a5bdbd..809c27e8b5526eb96f784fbb0733b0de81aee39a 100644 --- a/lib/wsapi.js +++ b/lib/wsapi.js @@ -8,6 +8,7 @@ // exports.method - either 'get' or 'post' // exports.authed - whether the wsapi requires authentication // exports.args - an array of arguments that should be verified +// exports.i18n - boolean, does this operation display user facing strings const @@ -24,6 +25,14 @@ path = require('path'), validate = require('./validate'), statsd = require('./statsd'); bcrypt = require('./bcrypt'); +i18n = require('./i18n'); + + +var abide = i18n.abide({ + supported_languages: config.get('supported_languages'), + default_lang: config.get('default_lang'), + locale_directory: config.get('locale_directory') +}); const COOKIE_SECRET = secrets.hydrateSecret('browserid_cookie', config.get('var_path')); const COOKIE_KEY = 'browserid_state'; @@ -296,7 +305,16 @@ exports.setup = function(options, app) { // validate the arguments of the request wsapis[operation].validate(req, resp, function() { - wsapis[operation].process(req, resp); + if (wsapis[operation].i18n) { + abide(req, resp, function () { + console.log('WSAPI running i18n code'); + wsapis[operation].process(req, resp); + }); + } else { + console.log('WSAPI SKIPPING i18n code'); + wsapis[operation].process(req, resp); + } + }); } else { next(); diff --git a/lib/wsapi/account_cancel.js b/lib/wsapi/account_cancel.js index c0b59193ec497eab8f890f55636587df3b406b29..81ce63eccc50741f68960d8d032cb8176f414de4 100644 --- a/lib/wsapi/account_cancel.js +++ b/lib/wsapi/account_cancel.js @@ -6,6 +6,7 @@ logger = require('../logging.js').logger; exports.method = 'post'; exports.writes_db = true; exports.authed = 'assertion'; +exports.i18n = false; exports.process = function(req, res) { db.cancelAccount(req.session.userid, function(error) { diff --git a/lib/wsapi/add_email_with_assertion.js b/lib/wsapi/add_email_with_assertion.js index 1e6c6f99a19616d37fdebc50a015fb93d2d966e8..a1e1564539cf3666f2d0080eae2bb627d981fce6 100644 --- a/lib/wsapi/add_email_with_assertion.js +++ b/lib/wsapi/add_email_with_assertion.js @@ -12,6 +12,7 @@ exports.method = 'post'; exports.writes_db = true; exports.authed = 'assertion'; exports.args = ['assertion']; +exports.i18n = false; // This WSAPI will be invoked when a user attempts to add a primary // email address to their browserid account. They must already be diff --git a/lib/wsapi/address_info.js b/lib/wsapi/address_info.js index 15c7f0e6a486a3c5c35f520513818ee665cec8f2..36bc39b7a22236cc0a2bb9a4b2d36f6b0f3eff52 100644 --- a/lib/wsapi/address_info.js +++ b/lib/wsapi/address_info.js @@ -14,6 +14,7 @@ exports.method = 'get'; exports.writes_db = false; exports.authed = false; exports.args = ['email']; +exports.i18n = false; const emailRegex = /\@(.*)$/; diff --git a/lib/wsapi/auth_with_assertion.js b/lib/wsapi/auth_with_assertion.js index 2e9c10f61877923682acf5b13ddb9adadc5255ed..5c8c13d3d76e04426a47632ea158c1ba0ce92205 100644 --- a/lib/wsapi/auth_with_assertion.js +++ b/lib/wsapi/auth_with_assertion.js @@ -12,6 +12,7 @@ exports.method = 'post'; exports.writes_db = false; exports.authed = false; exports.args = ['assertion']; +exports.i18n = false; exports.process = function(req, res) { // this WSAPI will be invoked when a user attempts to authenticate with diff --git a/lib/wsapi/authenticate_user.js b/lib/wsapi/authenticate_user.js index 25b073bc60ef7eeb4da8a31e3285f36eb69104c1..8fd19d10c5ac23ee9e3498817c939c5268496d9c 100644 --- a/lib/wsapi/authenticate_user.js +++ b/lib/wsapi/authenticate_user.js @@ -13,6 +13,7 @@ exports.method = 'post'; exports.writes_db = false; exports.authed = false; exports.args = ['email','pass']; +exports.i18n = false; exports.process = function(req, res) { function fail(reason) { diff --git a/lib/wsapi/cert_key.js b/lib/wsapi/cert_key.js index e3212373720d514f2c3efcec6467f7a99753b7ff..3df8b5bfeda20e6b0ff2bac8c3fdda77e9c168ab 100644 --- a/lib/wsapi/cert_key.js +++ b/lib/wsapi/cert_key.js @@ -9,6 +9,7 @@ exports.method = 'post'; exports.writes_db = false; exports.authed = 'password'; exports.args = ['email','pubkey']; +exports.i18n = false; exports.process = function(req, res) { db.userOwnsEmail(req.session.userid, req.body.email, function(owned) { diff --git a/lib/wsapi/complete_email_addition.js b/lib/wsapi/complete_email_addition.js index c0449c5bfcdf83d2cbdabc3e8ecb2f9f4e7842c9..2b123758ee8a86d86236cfe2e1d92da7675892e7 100644 --- a/lib/wsapi/complete_email_addition.js +++ b/lib/wsapi/complete_email_addition.js @@ -10,6 +10,7 @@ exports.authed = false; // NOTE: this API also takes a 'pass' parameter which is required // when a user has a null password (only primaries on their acct) exports.args = ['token']; +exports.i18n = false; exports.process = function(req, res) { // a password *must* be supplied to this call iff the user's password diff --git a/lib/wsapi/complete_user_creation.js b/lib/wsapi/complete_user_creation.js index fd582b7ea02f0e9ff56aa0214cd02acbc823eb28..f8bb979c16e1de598fcb7a3adbacb92e51aa7268 100644 --- a/lib/wsapi/complete_user_creation.js +++ b/lib/wsapi/complete_user_creation.js @@ -8,6 +8,7 @@ exports.method = 'post'; exports.writes_db = true; exports.authed = false; exports.args = ['token','pass']; +exports.i18n = false; exports.process = function(req, res) { // issue #155, valid password length is between 8 and 80 chars. diff --git a/lib/wsapi/create_account_with_assertion.js b/lib/wsapi/create_account_with_assertion.js index 70c9e57b31f42429fb1e316c72c03006723058a4..737c94d36f1a4f104581d45a47cd986d3da54e53 100644 --- a/lib/wsapi/create_account_with_assertion.js +++ b/lib/wsapi/create_account_with_assertion.js @@ -10,6 +10,7 @@ exports.writes_db = true; exports.authed = false; exports.disallow_forward = true; exports.args = ['assertion']; +exports.i18n = false; exports.process = function(req, res) { // let's (re)verify that the assertion is valid diff --git a/lib/wsapi/email_addition_status.js b/lib/wsapi/email_addition_status.js index 0139e779a137a591c3ff598eabd2add04211c5a9..803c53b5a77c0586ef25f6538f3169b3030733f4 100644 --- a/lib/wsapi/email_addition_status.js +++ b/lib/wsapi/email_addition_status.js @@ -11,6 +11,7 @@ exports.method = 'get'; exports.writes_db = false; exports.authed = 'assertion'; exports.args = ['email']; +exports.i18n = false; exports.process = function(req, res) { var email = req.query.email; diff --git a/lib/wsapi/email_for_token.js b/lib/wsapi/email_for_token.js index 7e9497023f5d44885cb5ce15c2c6048e99903b87..2ec48355d90310345fdb1e1f6339defc04f4b444 100644 --- a/lib/wsapi/email_for_token.js +++ b/lib/wsapi/email_for_token.js @@ -11,6 +11,7 @@ exports.method = 'get'; exports.writes_db = false; exports.authed = false; exports.args = ['token']; +exports.i18n = false; exports.process = function(req, res) { db.emailForVerificationSecret(req.query.token, function(err, r) { diff --git a/lib/wsapi/have_email.js b/lib/wsapi/have_email.js index e399bb86bc5cd24795fdb6d5abfc925a0dcaa2a5..0560f62e25d61f6705e71fb7bdb279237ad6ae7b 100644 --- a/lib/wsapi/have_email.js +++ b/lib/wsapi/have_email.js @@ -7,6 +7,7 @@ exports.method = 'get'; exports.writes_db = false; exports.authed = false; exports.args = ['email']; +exports.i18n = false; exports.process = function(req, resp) { var email = url.parse(req.url, true).query['email']; diff --git a/lib/wsapi/list_emails.js b/lib/wsapi/list_emails.js index 4314bdf000345f80b61ebc72fbe34a45b2e0fa15..10e2f448e41e524fc5741e15a06c2564cc7a5bd0 100644 --- a/lib/wsapi/list_emails.js +++ b/lib/wsapi/list_emails.js @@ -12,6 +12,7 @@ logger = require('../logging.js').logger; exports.method = 'get'; exports.writes_db = false; exports.authed = 'assertion'; +exports.i18n = false; exports.process = function(req, resp) { logger.debug('listing emails for user ' + req.session.userid); diff --git a/lib/wsapi/logout.js b/lib/wsapi/logout.js index 41a84b2a0529d1053abbdc4aa6b4e7a4d4d695c9..ad433b415ecba46ebf1a1a2460f26af41c7fa25e 100644 --- a/lib/wsapi/logout.js +++ b/lib/wsapi/logout.js @@ -4,6 +4,7 @@ wsapi = require('../wsapi.js'); exports.method = 'post'; exports.writes_db = false; exports.authed = 'assertion'; +exports.i18n = false; exports.process = function(req, res) { wsapi.clearAuthenticatedUser(req.session); diff --git a/lib/wsapi/remove_email.js b/lib/wsapi/remove_email.js index 9df5a3818836a9527e8e96ae2816de82f0078718..2b03b87ee36ca166c38aa9bf3143cb67c7093c82 100644 --- a/lib/wsapi/remove_email.js +++ b/lib/wsapi/remove_email.js @@ -7,6 +7,7 @@ exports.method = 'post'; exports.writes_db = true; exports.authed = 'assertion'; exports.args = ['email']; +exports.i18n = false; exports.process = function(req, res) { var email = req.body.email; diff --git a/lib/wsapi/session_context.js b/lib/wsapi/session_context.js index bc57b6bfe5b14bd97a025750fdc7a953d7ac4aac..df61a6675a881a574d94e8ca87d593efbda0e49d 100644 --- a/lib/wsapi/session_context.js +++ b/lib/wsapi/session_context.js @@ -12,6 +12,7 @@ secrets = require('../secrets.js'); exports.method = 'get'; exports.writes_db = false; exports.authed = false; +exports.i18n = false; // determine the domain key creation date - issue #599 const domainKeyCreationDate = secrets.publicKeyCreationDate(); diff --git a/lib/wsapi/stage_email.js b/lib/wsapi/stage_email.js index 6b388cafebf01d707b1e5fd5ee3cf06b8ae4e9ca..18efef33b6089b3378cb4b819917112fb89861e8 100644 --- a/lib/wsapi/stage_email.js +++ b/lib/wsapi/stage_email.js @@ -15,6 +15,7 @@ exports.method = 'post'; exports.writes_db = true; exports.authed = 'assertion'; exports.args = ['email','site']; +exports.i18n = true; exports.process = function(req, res) { db.lastStaged(req.body.email, function (last) { diff --git a/lib/wsapi/stage_user.js b/lib/wsapi/stage_user.js index f7dddf1904590850b93fa7e9774d1022c62ef78e..6cac47571812cab77863f5a791443fca2c8fc49b 100644 --- a/lib/wsapi/stage_user.js +++ b/lib/wsapi/stage_user.js @@ -15,6 +15,7 @@ exports.method = 'post'; exports.writes_db = true; exports.authed = false; exports.args = ['email','site']; +exports.i18n = true; exports.process = function(req, resp) { var langContext = { diff --git a/lib/wsapi/update_password.js b/lib/wsapi/update_password.js index 97dfb7c91aaaac643330146328ed12783ed0f875..3f38899c1b00ee23c69d0bc4610c231d31fce100 100644 --- a/lib/wsapi/update_password.js +++ b/lib/wsapi/update_password.js @@ -9,6 +9,7 @@ exports.method = 'post'; exports.writes_db = true; exports.authed = 'password'; exports.args = ['oldpass','newpass']; +exports.i18n = false; exports.process = function(req, res) { var err = wsapi.checkPassword(req.body.newpass); diff --git a/lib/wsapi/user_creation_status.js b/lib/wsapi/user_creation_status.js index f62e5ea9f3bceb347a18fe98dabffc0024805112..90d8ed69b914b1557d622d0a08bd12fbcad34324 100644 --- a/lib/wsapi/user_creation_status.js +++ b/lib/wsapi/user_creation_status.js @@ -6,6 +6,7 @@ exports.method = 'get'; exports.writes_db = false; exports.authed = false; exports.args = ['email']; +exports.i18n = false; exports.process = function(req, res) { var email = req.query.email; diff --git a/resources/static/include.js b/resources/static/include.js index 84827dfe82ac03f876d6a05b65bd9fc556fe1aed..a6aff07d3c165a662b87a0bd1ac3d3a96709dae5 120000 --- a/resources/static/include.js +++ b/resources/static/include.js @@ -1 +1 @@ -resources/static/include_js/include.js \ No newline at end of file +include_js/include.js \ No newline at end of file