From 19095a44181911b8b8496a5f85225bcc9f7242a5 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson Date: Tue, 25 Mar 2014 16:19:01 +0000 Subject: [PATCH] fix(build): Normalize TOS/PP filenames to use the `_` separator. * All other l10n files use the `_` separator, use them here too. --- grunttasks/marked.js | 14 ++++++++++++-- server/lib/routes/get-terms-privacy.js | 15 +++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/grunttasks/marked.js b/grunttasks/marked.js index e67616e58..842c5562c 100644 --- a/grunttasks/marked.js +++ b/grunttasks/marked.js @@ -2,11 +2,19 @@ * 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/. */ +const path = require('path'); +const i18n = require('i18n-abide'); + module.exports = function (grunt) { 'use strict'; // convert localized TOS/PP agreements from markdown to html partials. + function rename(destPath, destFile) { + // Normalize the filenames to use the locale name. + return path.join(destPath, i18n.localeFrom(destFile)); + } + grunt.config('marked', { options: { sanitize: false, @@ -19,14 +27,16 @@ module.exports = function (grunt) { cwd: '<%= yeoman.pp_md_src %>', src: ['**/*.md'], dest: '<%= yeoman.pp_html_dest %>', - ext: '.html' + ext: '.html', + rename: rename }, { expand: true, cwd: '<%= yeoman.tos_md_src %>', src: ['**/*.md'], dest: '<%= yeoman.tos_html_dest %>', - ext: '.html' + ext: '.html', + rename: rename } ] } diff --git a/server/lib/routes/get-terms-privacy.js b/server/lib/routes/get-terms-privacy.js index d20dfc225..7450d6056 100644 --- a/server/lib/routes/get-terms-privacy.js +++ b/server/lib/routes/get-terms-privacy.js @@ -28,11 +28,12 @@ var PAGE_TEMPLATE_DIRECTORY = path.join(config.get('page_template_root'), 'dist' var TOS_ROOT_PATH = path.join(PAGE_TEMPLATE_DIRECTORY, 'terms'); var PP_ROOT_PATH = path.join(PAGE_TEMPLATE_DIRECTORY, 'privacy'); -var DEFAULT_LANG = config.get('i18n.defaultLang'); - module.exports = function verRoute (i18n) { + var DEFAULT_LANG = config.get('i18n.defaultLang'); + var DEFAULT_LOCALE = i18n.localeFrom(DEFAULT_LANG); + var route = {}; route.method = 'get'; @@ -49,7 +50,9 @@ module.exports = function verRoute (i18n) { var templateCache = {}; function getTemplate(type, lang) { - var templatePath = path.join(getRoot(type), lang + '.html'); + // Filenames are normalized to locale, not language. + var locale = i18n.localeFrom(lang); + var templatePath = path.join(getRoot(type), locale + '.html'); var resolver = Promise.defer(); // cache the promises to avoid multiple concurrent checks for @@ -63,11 +66,11 @@ module.exports = function verRoute (i18n) { if (! exists) { var bestLang = i18n.bestLanguage(i18n.parseAcceptLanguage(lang)); - if (lang === DEFAULT_LANG) { - var err = new Error(type + ' missing `' + DEFAULT_LANG + '` template: ' + templatePath); + if (locale === DEFAULT_LOCALE) { + var err = new Error(type + ' missing `' + DEFAULT_LOCALE + '` template: ' + templatePath); return resolver.reject(err); } else if (lang !== bestLang) { - logger.warn('`%s` does not exist, trying `%s`', lang, bestLang); + logger.warn('`%s` does not exist, trying next best `%s`', lang, bestLang); return resolver.resolve(getTemplate(type, bestLang)); }