Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

added L10N_DEV environment variable for making all languages available #314

Merged
merged 1 commit into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"homepage": "https://github.com/mozilla/send/",
"license": "MPL-2.0",
"repository": "mozilla/send",
"availableLanguages": ["en-US"],
"scripts": {
"build": "npm-run-all build:*",
"build:upload": "browserify frontend/src/upload.js -g uglifyify -o public/upload.js",
Expand Down
5 changes: 5 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const conf = convict({
format: Number,
default: 86400,
env: 'EXPIRE_SECONDS'
},
l10n_dev: {
format: Boolean,
default: false,
env: 'L10N_DEV'
}
});

Expand Down
26 changes: 25 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const conf = require('./config.js');
const storage = require('./storage.js');
const Raven = require('raven');
const crypto = require('crypto');
const fs = require('fs');

if (conf.sentry_dsn) {
Raven.config(conf.sentry_dsn).install();
Expand All @@ -22,11 +23,34 @@ const STATIC_PATH = path.join(__dirname, '../public');

const app = express();

function allLangs() {
return fs
.readdirSync(path.join(STATIC_PATH, 'locales'))
.map(function(f) {
return f.split('.')[0];
})
.join(',');
}

function prodLangs() {
return require(path.join(
__dirname,
'..',
'package.json'
)).availableLanguages.join(',');
}

const availableLanguages = conf.l10n_dev ? allLangs() : prodLangs();

app.engine(
'handlebars',
exphbs({
defaultLayout: 'main',
partialsDir: 'views/partials/'
partialsDir: 'views/partials/',
helpers: {
availableLanguages,
l10nDev: conf.l10n_dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use this helper, or just the availableLanguages helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I was going to use it to add pontoon.js but the CSP and other changes scared me away for now

}
})
);
app.set('view engine', 'handlebars');
Expand Down
2 changes: 1 addition & 1 deletion views/layouts/main.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="defaultLanguage" content="en-US">
<meta name="availableLanguages" content="en-US">
<meta name="availableLanguages" content="{{availableLanguages}}">

<link rel="icon" type="image/png" href="/resources/favicon-32x32.png" sizes="32x32" />
<link rel="localization" href="/locales/{locale}/send.ftl">
Expand Down