fix(build): Normalize TOS/PP filenames to use the `_` separator.

* All other l10n files use the `_` separator, use them here too.
This commit is contained in:
Shane Tomlinson 2014-03-25 16:19:01 +00:00
Родитель b430cd7c15
Коммит 19095a4418
2 изменённых файлов: 21 добавлений и 8 удалений

Просмотреть файл

@ -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
}
]
}

Просмотреть файл

@ -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));
}