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

Commit

Permalink
Merge pull request #640 from mozilla/i586
Browse files Browse the repository at this point in the history
use fluent-langneg for subtag support
  • Loading branch information
dannycoates committed Nov 10, 2017
2 parents 4ed515f + bfcdf93 commit b7f922a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 46 deletions.
6 changes: 3 additions & 3 deletions app/templates/completed.js
Expand Up @@ -15,9 +15,9 @@ module.exports = function(state, emit) {
<div class="progress-text"></div>
</div>
</div>
<a class="send-new" data-state="completed" href="/" onclick=${sendNew}>${state.translate(
'sendYourFilesLink'
)}</a>
<a class="send-new" data-state="completed" href="/" onclick=${
sendNew
}>${state.translate('sendYourFilesLink')}</a>
</div>
`;

Expand Down
14 changes: 11 additions & 3 deletions app/templates/progress.js
Expand Up @@ -10,10 +10,18 @@ module.exports = function(progressRatio) {
const percent = Math.floor(progressRatio * 100);
const div = html`
<div class="progress-bar">
<svg id="progress" width="${oDiameter}" height="${oDiameter}" viewPort="0 0 ${oDiameter} ${oDiameter}" version="1.1">
<svg id="progress" width="${oDiameter}" height="${
oDiameter
}" viewPort="0 0 ${oDiameter} ${oDiameter}" version="1.1">
<circle r="${radius}" cx="${oRadius}" cy="${oRadius}" fill="transparent"/>
<circle id="bar" r="${radius}" cx="${oRadius}" cy="${oRadius}" fill="transparent" transform="rotate(-90 ${oRadius} ${oRadius})" stroke-dasharray="${circumference}" stroke-dashoffset="${dashOffset}"/>
<text class="percentage" text-anchor="middle" x="50%" y="98"><tspan class="percent-number">${percent}</tspan><tspan class="percent-sign">%</tspan></text>
<circle id="bar" r="${radius}" cx="${oRadius}" cy="${
oRadius
}" fill="transparent" transform="rotate(-90 ${oRadius} ${
oRadius
})" stroke-dasharray="${circumference}" stroke-dashoffset="${dashOffset}"/>
<text class="percentage" text-anchor="middle" x="50%" y="98"><tspan class="percent-number">${
percent
}</tspan><tspan class="percent-sign">%</tspan></text>
</svg>
</div>
`;
Expand Down
4 changes: 3 additions & 1 deletion app/templates/uploadPassword.js
Expand Up @@ -5,7 +5,9 @@ module.exports = function(state, emit) {
const div = html`
<div class="selectPassword">
<div id="addPasswordWrapper">
<input id="addPassword" type="checkbox" autocomplete="off" onchange=${togglePasswordInput}/>
<input id="addPassword" type="checkbox" autocomplete="off" onchange=${
togglePasswordInput
}/>
<label for="addPassword">
${state.translate('requirePasswordCheckbox')}</label>
</div>
Expand Down
33 changes: 5 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -96,10 +96,10 @@
"aws-sdk": "^2.149.0",
"body-parser": "^1.18.2",
"choo": "^6.5.1",
"cldr-core": "^32.0.0",
"connect-busboy": "0.0.2",
"convict": "^4.0.1",
"express": "^4.16.2",
"express-request-language": "^1.1.15",
"fluent": "^0.4.1",
"fluent-langneg": "^0.1.0",
"helmet": "^3.9.0",
Expand Down
4 changes: 1 addition & 3 deletions server/languages.js
Expand Up @@ -4,11 +4,9 @@ const fs = require('fs');
const path = require('path');

function allLangs() {
const langs = fs.readdirSync(
return fs.readdirSync(
path.join(__dirname, '..', 'dist', 'public', 'locales')
);
langs.unshift('en-US'); // default first, TODO change for fluent-langneg
return langs;
}

if (config.l10n_dev) {
Expand Down
34 changes: 27 additions & 7 deletions server/routes/index.js
@@ -1,20 +1,40 @@
const busboy = require('connect-busboy');
const helmet = require('helmet');
const bodyParser = require('body-parser');
const requestLanguage = require('express-request-language');
const languages = require('../languages');
const storage = require('../storage');
const config = require('../config');
const pages = require('./pages');
// const lang = require('fluent-langneg')
const { negotiateLanguages } = require('fluent-langneg');
const IS_DEV = config.env === 'development';
const acceptLanguages = /(([a-zA-Z]+(-[a-zA-Z0-9]+){0,2})|\*)(;q=[0-1](\.[0-9]+)?)?/g;
const langData = require('cldr-core/supplemental/likelySubtags.json');

module.exports = function(app) {
app.use(
requestLanguage({
languages
})
);
app.use(function(req, res, next) {
const header = req.headers['accept-language'] || 'en-US';
if (header.length > 255) {
req.language = 'en-US';
return next();
}
const langs = header.replace(/\s/g, '').match(acceptLanguages);
const preferred = langs
.map(l => {
const parts = l.split(';');
return {
locale: parts[0],
q: parts[1] ? parseFloat(parts[1].split('=')[1]) : 1
};
})
.sort((a, b) => b.q - a.q)
.map(x => x.locale);
req.language = negotiateLanguages(preferred, languages, {
strategy: 'lookup',
likelySubtags: langData.supplemental.likelySubtags,
defaultLocale: 'en-US'
})[0];
next();
});
app.use(helmet());
app.use(
helmet.hsts({
Expand Down

0 comments on commit b7f922a

Please sign in to comment.