Skip to content
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

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b43f864
Fetch price to DB
nikkozzblu Jan 18, 2017
627457a
Price from ENTSOE
nikkozzblu Jan 20, 2017
fc4430b
Styling and not importing future prices
nikkozzblu Jan 21, 2017
deb9f8a
Merge branch 'master' into master
nikkozzblu Jan 21, 2017
2d5659f
Merge branch 'master' of https://github.com/nikkozzblu/electricitymap
nikkozzblu Jan 21, 2017
16b853f
Last point if no date specify
nikkozzblu Jan 21, 2017
e54699f
Merge branch 'master' into master
nikkozzblu Jan 21, 2017
e1ede10
BUG position
nikkozzblu Jan 21, 2017
c52f13a
Merge branch 'master' of https://github.com/nikkozzblu/electricitymap
nikkozzblu Jan 21, 2017
c944573
alphaorder
nikkozzblu Jan 22, 2017
ad33062
Merge branch 'master' into master
nikkozzblu Jan 22, 2017
df76105
Solar speed
nikkozzblu Jan 24, 2017
5af9403
Merge branch 'master' into master
nikkozzblu Jan 24, 2017
b8d463b
index and rounding (fix a 0.5deg shift)
nikkozzblu Jan 24, 2017
4976d02
Merge branch 'master' into master
nikkozzblu Jan 24, 2017
e51e675
Merge branch 'master' of https://github.com/nikkozzblu/electricitymap
nikkozzblu Jan 24, 2017
bc56c68
Styling and warning
nikkozzblu Jan 24, 2017
ce1eec5
Optimize rounding and comments
nikkozzblu Jan 25, 2017
00f7c02
Merge branch 'master' into master
nikkozzblu Jan 25, 2017
398492d
Continuous scale replace levels
nikkozzblu Jan 25, 2017
5ae3c8d
legend, formatting filter
nikkozzblu Jan 25, 2017
e917d1a
forgot those 2
nikkozzblu Jan 25, 2017
5846dfd
Merge remote-tracking branch 'refs/remotes/corradio/master'
nikkozzblu Feb 6, 2017
f7f1dd9
Merge lang from local to updated branch
nikkozzblu Feb 6, 2017
4a4b7b9
Fix rejected updates
nikkozzblu Feb 6, 2017
d849530
fossil fuels
nikkozzblu Feb 6, 2017
669e55f
Style and language correction
nikkozzblu Feb 6, 2017
51de788
Missing bracket
nikkozzblu Feb 6, 2017
8942fae
Merge branch 'master' into master
nikkozzblu Feb 6, 2017
e799aec
Indentations fix
nikkozzblu Feb 7, 2017
3d31c99
Merge branch 'master' into master
nikkozzblu Feb 7, 2017
4bea4b4
remove loggings
nikkozzblu Feb 7, 2017
03046ed
Merge remote-tracking branch 'origin/master'
nikkozzblu Feb 7, 2017
8d1cfa5
Merge branch 'master' into master
nikkozzblu Feb 7, 2017
768adf3
Merge branch 'master' into master
nikkozzblu Feb 7, 2017
c2ab9dd
auto-redirect to your language,Correct indentation, adding latest mis…
nikkozzblu Feb 7, 2017
ca60203
Merge branch 'master' of https://github.com/nikkozzblu/electricitymap
nikkozzblu Feb 7, 2017
7826433
Merge branch 'master' into master
nikkozzblu Feb 7, 2017
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 docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
- './web/server.js:/home/web/server.js'
- './web/views:/home/web/views'
- './web/webpack.config.js:/home/web/webpack.config.js'
- './web/locales:/home/web/locales'
feeder:
build:
context: .
Expand Down
41 changes: 41 additions & 0 deletions web/app/configs/lang.json
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";
}
}
10 changes: 7 additions & 3 deletions web/app/countrytable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

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

Not needed

// State
this._displayByEmissions = false;

Expand All @@ -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')
Expand Down Expand Up @@ -368,7 +371,7 @@ CountryTable.prototype.resize = function() {

CountryTable.prototype.data = function(arg) {
var that = this;

console.log(this._data);
Copy link
Member

Choose a reason for hiding this comment

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

not needed

if (!arg) return this._data;

this._data = arg;
Expand All @@ -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)
};
Expand Down
9 changes: 7 additions & 2 deletions web/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,8 +36,10 @@ var selectedCountryCode;
var forceRemoteEndpoint = false;
var customDate;
var timelineEnabled = false;
var reqLang = 'en';
Copy link
Member

Choose a reason for hiding this comment

The 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 moment locale?

// Set proper locale
var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale);

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

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

ok can you then also update the locale used by moment for consistency? Should be around L134.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"...
the server should be able to understand fr from i18n spec, not sure what is going wrong here.
Anyway I thought the query string could be a good intermediate solution for first release before we get the text actually read and corrected by external reviewer

var currentMoment;


Copy link
Member

Choose a reason for hiding this comment

The 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);
}
Expand Down Expand Up @@ -82,6 +85,8 @@ args.forEach(function(arg) {
} else if (kv[0] == 'countryCode') {
selectedCountryCode = kv[1];
replaceHistoryState('countryCode', selectedCountryCode);
} else if(kv[0] == 'lang'){
Copy link
Member

Choose a reason for hiding this comment

The 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).
I suggest instead that the node server adds a global variable to the template, thus defining the locale.
Then you don't need to read it here.

reqLang = kv[1];
Copy link
Member

Choose a reason for hiding this comment

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

  • Style: indent

}
});

Expand Down Expand Up @@ -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(); },
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions web/app/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getConsumption(country) {
}

// ** Country table
exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2color) {
exports.setupCountryTable = function (countryTable, countries, co2Colorbar, co2color,lang) {
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand All @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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')
Expand All @@ -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) : '?';
Expand Down
49 changes: 49 additions & 0 deletions web/locales/en.json
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"
}
50 changes: 50 additions & 0 deletions web/locales/fr.json
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"
}
3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

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

Style: Indentation error

},
"devDependencies": {
"nodemon": "^1.10.2",
Expand Down
2 changes: 1 addition & 1 deletion web/public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,4 @@ div.fb-share-button, div.fb-like, div.fb-follow, iframe.twitter-share-button, if

.time-travel {
display: none;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This file shouldn't change

13 changes: 13 additions & 0 deletions web/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'],
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down
Loading