Skip to content
Permalink
Browse files
Automate generating the list of available languages for the badge
Note that getMessage in the badge depends on having a complete set of
translations, unlike the webextension, which will fallback to the
default for a string.
  • Loading branch information
arlolra committed Aug 22, 2019
1 parent da21c67 commit 06eac0bcd659e4038cff675c7a8a373877a4e43a
Showing with 23 additions and 9 deletions.
  1. +1 −4 proxy/init-badge.js
  2. +22 −5 proxy/make.js
@@ -1,4 +1,4 @@
/* global Util, Params, Config, UI, Broker, Snowflake, Popup, Parse */
/* global Util, Params, Config, UI, Broker, Snowflake, Popup, Parse, availableLangs */

/*
UI
@@ -83,9 +83,6 @@ function setSnowflakeCookie(val, expires) {
}

const defaultLang = 'en_US';
const availableLangs = new Set([
'en_US',
]);

// Resolve as in,
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Internationalization#Localized_string_selection
@@ -2,6 +2,7 @@

/* global require, process */

var { writeFileSync, readdirSync, statSync } = require('fs');
var { execSync, spawn } = require('child_process');

// All files required.
@@ -36,16 +37,32 @@ var SHARED_FILES = [
'_locales',
];

var concatJS = function(outDir, init, outFile) {
var concatJS = function(outDir, init, outFile, pre) {
var files = FILES.concat(`init-${init}.js`);
execSync(`cat ${files.join(' ')} > ${outDir}/${outFile}`);
var outPath = `${outDir}/${outFile}`;
writeFileSync(outPath, pre, 'utf8');
execSync(`cat ${files.join(' ')} >> ${outPath}`);
};

var copyTranslations = function(outDir) {
execSync('git submodule update --init -- translation')
execSync(`cp -rf translation/* ${outDir}/_locales/`);
};

var availableLangs = function() {
let out = "const availableLangs = new Set([\n";
let dirs = readdirSync('translation').filter((f) => {
const s = statSync(`translation/${f}`);
return s.isDirectory();
});
dirs.push('en_US');
dirs.sort();
dirs = dirs.map(d => ` '${d}',`);
out += dirs.join("\n");
out += "\n]);\n\n";
return out;
};

var tasks = new Map();

var task = function(key, msg, func) {
@@ -76,7 +93,7 @@ task('build', 'build the snowflake proxy', function() {
execSync(`rm -rf ${outDir}`);
execSync(`cp -r ${STATIC}/ ${outDir}/`);
copyTranslations(outDir);
concatJS(outDir, 'badge', 'embed.js');
concatJS(outDir, 'badge', 'embed.js', availableLangs());
console.log('Snowflake prepared.');
});

@@ -85,13 +102,13 @@ task('webext', 'build the webextension', function() {
execSync(`git clean -f -x -d ${outDir}/`);
execSync(`cp -r ${STATIC}/{${SHARED_FILES.join(',')}} ${outDir}/`, { shell: '/bin/bash' });
copyTranslations(outDir);
concatJS(outDir, 'webext', 'snowflake.js');
concatJS(outDir, 'webext', 'snowflake.js', '');
console.log('Webextension prepared.');
});

task('node', 'build the node binary', function() {
execSync('mkdir -p build');
concatJS('build', 'node', 'snowflake.js');
concatJS('build', 'node', 'snowflake.js', '');
console.log('Node prepared.');
});

0 comments on commit 06eac0b

Please sign in to comment.