-
Notifications
You must be signed in to change notification settings - Fork 959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-language and French #344
Changes from 29 commits
b43f864
627457a
fc4430b
deb9f8a
2d5659f
16b853f
e54699f
e1ede10
c52f13a
c944573
ad33062
df76105
5af9403
b8d463b
4976d02
e51e675
bc56c68
ce1eec5
00f7c02
398492d
5ae3c8d
e917d1a
5846dfd
f7f1dd9
4a4b7b9
d849530
669e55f
51de788
8942fae
e799aec
3d31c99
4bea4b4
03046ed
8d1cfa5
768adf3
c2ab9dd
ca60203
7826433
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"en": | ||
{ | ||
"wind": "wind", | ||
"solar": "solar", | ||
"hydro": "hydro", | ||
"hydrostorage": "hydro storage", | ||
"biomass": "biomass", | ||
"nuclear": "nuclear", | ||
"gas": "gas", | ||
"coal": "coal", | ||
"oil": "oil", | ||
"unknown": "unknown", | ||
"exportto": "of export to", | ||
"importfrom":"of import from", | ||
"productionimport":"production/import", | ||
"consumption":"consumption", | ||
"electricityfrom":"electricity comes from", | ||
"electricityto":"electricity is exported to", | ||
"electricitystored":"electricity is stored using"; | ||
}, | ||
"fr": { | ||
"wind": "éolien", | ||
"solar": "solaire", | ||
"hydro": "hydro", | ||
"hydrostorage": "stockage hydro", | ||
"biomass": "biomasse", | ||
"nuclear": "nucléaire", | ||
"gas": "gaz", | ||
"coal": "charbon", | ||
"oil": "fioul", | ||
"unknown": "inconnu", | ||
"exportto": "exportée vers", | ||
"importfrom":" importée depuis", | ||
"productionimport":"production/import", | ||
"consumption":"consommation", | ||
"electricityfrom":"électricité importée depuis", | ||
"electricityto":"électricité exportée vers", | ||
"electricitystored":"électricité stockée dans"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ var moment = require('moment'); | |
// This means drawing them once at `.data()` or at construction, and not | ||
// during `render()` | ||
|
||
function CountryTable(selector, co2Color, modeColor, modeOrder) { | ||
function CountryTable(selector, co2Color, lang, modeColor, modeOrder) { | ||
var that = this; | ||
|
||
this.root = d3.select(selector); | ||
|
@@ -33,6 +33,9 @@ function CountryTable(selector, co2Color, modeColor, modeOrder) { | |
this.SCALE_TICKS = 4; | ||
this.TRANSITION_DURATION = 250; | ||
|
||
|
||
this.LANG = lang; | ||
console.log('a',this.LANG); | ||
// State | ||
this._displayByEmissions = false; | ||
|
||
|
@@ -55,7 +58,7 @@ function CountryTable(selector, co2Color, modeColor, modeOrder) { | |
return 'translate(0,' + (i * (that.ROW_HEIGHT + that.PADDING_Y)) + ')'; | ||
}); | ||
gNewRow.append('text') | ||
.text(function(d) { return d.mode }) | ||
.text(function(d) { return that.LANG[d.mode] || d.mode }) | ||
.attr('transform', 'translate(0, ' + this.TEXT_ADJUST_Y + ')'); | ||
gNewRow.append('rect') | ||
.attr('class', 'capacity') | ||
|
@@ -368,7 +371,7 @@ CountryTable.prototype.resize = function() { | |
|
||
CountryTable.prototype.data = function(arg) { | ||
var that = this; | ||
|
||
console.log(this._data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
if (!arg) return this._data; | ||
|
||
this._data = arg; | ||
|
@@ -393,6 +396,7 @@ CountryTable.prototype.data = function(arg) { | |
isStorage: d.isStorage, | ||
capacity: capacity, | ||
mode: d.mode, | ||
text: that.LANG[d.mode], | ||
gCo2eqPerkWh: footprint, | ||
gCo2eqPerH: footprint * 1000.0 * Math.max(production, 0) | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ var Wind = require('./wind'); | |
// Configs | ||
var capacities = require('json-loader!./configs/capacities.json'); | ||
var zones = require('json-loader!./configs/zones.json'); | ||
var lang = require('json-loader!./configs/lang.json'); | ||
|
||
// Constants | ||
var REFRESH_TIME_MINUTES = 5; | ||
|
@@ -35,8 +36,10 @@ var selectedCountryCode; | |
var forceRemoteEndpoint = false; | ||
var customDate; | ||
var timelineEnabled = false; | ||
var reqLang = 'en'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is the language changed except by querystring argument? Shouldn't it be detected automatically? Maybe you can use ~L134 where we set the // Set proper locale
var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The translation is a mix of server (through i18n) and client, so far i had no luck to get the server understanding same locale as client but i ll have another try since it shoudl be the defaut behaviour of the i18n library. As matter of consistency i therefore also use the query string on client. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok can you then also update the locale used by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it was what I did originally but because my french locale was not understood by server.js, it results in some mix between English text/French "source names"... |
||
var currentMoment; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line not needed |
||
function isMobile() { | ||
return (/android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i).test(navigator.userAgent); | ||
} | ||
|
@@ -82,6 +85,8 @@ args.forEach(function(arg) { | |
} else if (kv[0] == 'countryCode') { | ||
selectedCountryCode = kv[1]; | ||
replaceHistoryState('countryCode', selectedCountryCode); | ||
} else if(kv[0] == 'lang'){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually not in favor of using a querystring argument because the URL is used when sharing to social media (and we don't want to url to be part of that). |
||
reqLang = kv[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
}); | ||
|
||
|
@@ -210,7 +215,7 @@ var modeOrder = [ | |
// Set up objects | ||
var countryMap = new CountryMap('.map', co2color); | ||
var exchangeLayer = new ExchangeLayer('.map', co2color); | ||
var countryTable = new CountryTable('.country-table', co2color, modeColor, modeOrder); | ||
var countryTable = new CountryTable('.country-table', co2color, lang[reqLang], modeColor, modeOrder); | ||
//var countryHistoryGraph = new AreaGraph('.country-history', modeColor, modeOrder); | ||
var countryHistoryGraph = new LineGraph('.country-history', | ||
function(d) { return moment(d.stateDatetime).toDate(); }, | ||
|
@@ -495,7 +500,7 @@ if (isSmallScreen()) { | |
}); | ||
|
||
// Tooltip setup | ||
Tooltip.setupCountryTable(countryTable, countries, co2Colorbar, co2color); | ||
Tooltip.setupCountryTable(countryTable, countries, co2Colorbar, co2color, lang[reqLang] ); | ||
} | ||
|
||
function dataLoaded(err, state, argSolar, argWind) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ function getConsumption(country) { | |
} | ||
|
||
// ** Country table | ||
exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2color) { | ||
exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2color,lang) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: missing space after |
||
countryTable | ||
.onExchangeMouseOver(function (d, countryCode) { | ||
var isExport = d.value < 0; | ||
|
@@ -25,7 +25,7 @@ exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2c | |
co2Colorbar.currentMarker(co2intensity); | ||
var tooltip = d3.select('#countrypanel-exchange-tooltip'); | ||
tooltip.style('display', 'inline'); | ||
tooltip.select('#label').text(isExport ? 'export to' : 'import from'); | ||
tooltip.select('#label').text(isExport ? lang['exportto'] : lang['importfrom']); | ||
tooltip.select('#country-code').text(d.key); | ||
tooltip.select('.emission-rect') | ||
.style('background-color', co2intensity ? co2color(co2intensity) : 'gray'); | ||
|
@@ -38,8 +38,8 @@ exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2c | |
var totalConsumption = getConsumption(country); | ||
var totalPositive = country.totalProduction + country.totalImport; | ||
|
||
var domain = isExport ? totalPositive : totalPositive; | ||
var domainName = !isExport ? 'electricity comes from' : 'electricity is exported to'; | ||
var domain = isExport ? totalPositive : totalConsumption; | ||
var domainName = isExport ? lang['electricityfrom'] : lang['electricityto']; | ||
var isNull = !isFinite(d.value) || d.value == undefined; | ||
|
||
var absFlow = Math.abs(d.value); | ||
|
@@ -82,7 +82,7 @@ exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2c | |
co2Colorbar.currentMarker(co2intensity); | ||
var tooltip = d3.select('#countrypanel-production-tooltip'); | ||
tooltip.style('display', 'inline'); | ||
tooltip.selectAll('#mode').text(d.mode); | ||
tooltip.selectAll('#mode').text(d.text || d.mode); | ||
tooltip.select('.emission-rect') | ||
.style('background-color', co2intensity ? co2color(co2intensity) : 'gray'); | ||
tooltip.select('.emission-intensity') | ||
|
@@ -98,7 +98,7 @@ exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2c | |
var value = d.isStorage ? d.storage : d.production; | ||
|
||
var domain = d.isStorage ? totalPositive : totalPositive; | ||
var domainName = d.isStorage ? ('electricity is stored using ' + d.mode) : ('electricity comes from ' + d.mode); | ||
var domainName = d.isStorage ? ( lang['electricitystored'] +' ' + (d.text || d.mode)) : ( lang['electricityfrom'] + ' ' + (d.text || d.mode)); | ||
var isNull = !isFinite(value) || value == undefined; | ||
|
||
var productionProportion = !isNull ? Math.round(value / domain * 100) : '?'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"oops": "Oops! We are having trouble reaching the server. We will try again in a few seconds.", | ||
"carbonintensity": "Carbon intensity", | ||
"maintitle": "Live CO2 emissions of the European electricity consumption", | ||
"source": "source", | ||
"electricityprice": "Electricity price (day-ahead)", | ||
"fossilfuels": "fossil fuels", | ||
"electricityproduction": "Electricity production", | ||
"showemissions": "show emissions", | ||
"bysource": "by source", | ||
"emissions": "Emissions", | ||
"showelectricity": "show electricity", | ||
"youareseeing": "You are currently seeing a ", | ||
"limitedversion": "limited mobile version", | ||
"forthe": "For the", | ||
"fullversion": "full experience", | ||
"visitoncomputer": "visit this page on your computer", | ||
"thisshowsrealtime": "This shows in real-time", | ||
"whereelectricitycomesfrom": "where your electricity comes from", | ||
"and": "and", | ||
"homuchco2": "how much CO2", | ||
"wasemitted": "was emitted to produce it", | ||
"takeinaccount": "We take into account electricity", | ||
"importexport": "imports and exports", | ||
"betweencountries": "between countries", | ||
"thisproject": "This project is", | ||
"opensource": "Open Source", | ||
"see": "see", | ||
"datasources": "data sources", | ||
"tip": "Tip: Click on a country to start exploring", | ||
"windpotential": "Wind power potential", | ||
"solarpotential": "Solar power potential", | ||
"likethisvisu": "Like the visualization?", | ||
"loveyourfeedback": "We would love to hear your feedback", | ||
"foundbugs": "Found bugs or have ideas? Report them", | ||
"here": "here", | ||
"co2signalprefix": "Check out how our", | ||
"co2signalsuffix": "can help your devices and electric vehicle consume electricity at the right time", | ||
"crossborderexport": "Cross-border export", | ||
"carbonintensityexport": "Carbon intensity of export", | ||
"of": "of", | ||
"ofconsumption": "of", | ||
"ofinstalled": "of installed capacity", | ||
"ofelectricity": "of", | ||
"comesfrom": "electricity comes from", | ||
"utilizing": "utilizing", | ||
"withcarbonintensity": "with a carbon intensity of", | ||
"back": "back" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"oops": "Oops! Nous rencontrons un problème de connectivité au serveur. Une nouvelle tentative aura lieu dans quelques instants.", | ||
"carbonintensity": "Intensité carbone", | ||
"maintitle": "Emissions de CO2 de la production électrique Européene en temps réel", | ||
"source": "sources", | ||
"electricityprice": "Prix de l'électricité (day-ahead)", | ||
"fossilfuels": "carburants fossiles", | ||
"electricityproduction": "Production électrique", | ||
"showemissions": "montrer les émissions", | ||
"bysource": "par source", | ||
"emissions": "Emissions", | ||
"showelectricity": "montrer la production électrique", | ||
"youareseeing": "Vous voyez actuellement", | ||
"limitedversion": "une version mobile limitée", | ||
"forthe": "Pour une", | ||
"fullversion": "meilleur experience", | ||
"visitoncomputer": "visitez ce site depuis un ordinateur", | ||
"thisshowsrealtime": "Cette carte indique", | ||
"whereelectricitycomesfrom": "de quelles sources provient votre électricité", | ||
"and": "et", | ||
"homuchco2": "quelle quantité de CO2", | ||
"wasemitted": "a été émise pour la produire", | ||
"takeinaccount": "Elle prend en compte les", | ||
"importexport": "imports et exports", | ||
"betweencountries": "entre pays", | ||
"thisproject": "Ceci est un projet", | ||
"opensource": "Open Source", | ||
"see": "voir", | ||
"datasources": "data sources", | ||
"tip": "Tip: Cliquez un pays pour explorer sa production", | ||
"windpotential": "Potentiel éolien", | ||
"solarpotential": "Potentiel solaire", | ||
"likethisvisu": "Vous aimez cette carte intéractive?", | ||
"loveyourfeedback": "Envoyez nous vos commentaires", | ||
"foundbugs": "Un bug ? une idée ? Cliquez", | ||
"here": "ici", | ||
"co2signalprefix": "Découvrez aussi comment", | ||
"co2signalsuffix": "peut aider vos appareils et véhicules électriques à consommer l électricité au meilleur moments", | ||
"crossborderexport": "Export cross-frontalier", | ||
"carbonintensityexport": "Intensité carbone de l export", | ||
"of":"de", | ||
"ofconsumption": "de la consomation", | ||
"ofinstalled": "de la capacité installée", | ||
"ofelectricity": "de l électricité de", | ||
"comesfrom": "est produite par", | ||
"capacity": " ", | ||
"utilizing": "utilisant", | ||
"withcarbonintensity": "avec une intensité carbone de", | ||
"back": "retour" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ | |
"mongodb": "^2.2.9", | ||
"opbeat": "^3.21.0", | ||
"snappy": "^5.0.5", | ||
"topojson": "^2.2.0" | ||
"topojson": "^2.2.0", | ||
"i18n":"^0.8.3" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: Indentation error |
||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.10.2", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,4 +275,4 @@ div.fb-share-button, div.fb-like, div.fb-follow, iframe.twitter-share-button, if | |
|
||
.time-travel { | ||
display: none; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file shouldn't change |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ var http = require('http'); | |
var Memcached = require('memcached'); | ||
var moment = require('moment'); | ||
var MongoClient = require('mongodb').MongoClient; | ||
var i18n = require('i18n'); | ||
|
||
//var statsd = require('node-statsd'); // TODO: Remove | ||
|
||
// Custom modules | ||
|
@@ -41,6 +43,17 @@ app.use(function(req, res, next) { | |
// * Static and templating | ||
var STATIC_PATH = process.env['STATIC_PATH'] || (__dirname + '/public'); | ||
app.use(express.static(STATIC_PATH, {etag: true, maxAge: isProduction ? '24h': '0'})); | ||
//multi-language | ||
i18n.configure({ | ||
// where to store json files - defaults to './locales' relative to modules directory | ||
locales:['en', 'fr'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: Missing space after |
||
directory: __dirname + '/locales', | ||
defaultLocale: 'en', | ||
queryParameter: 'lang' | ||
// sets a custom cookie name to parse locale settings from - defaults to NULL | ||
//cookie: 'lang', | ||
}); | ||
app.use(i18n.init); | ||
app.set('view engine', 'ejs'); | ||
var BUNDLE_HASH = !isProduction ? 'dev' : | ||
JSON.parse(fs.readFileSync(STATIC_PATH + '/dist/manifest.json')).hash; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed