-
Notifications
You must be signed in to change notification settings - Fork 958
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
Conversation
Update FR for consistency
I'm renaming to WIP - .... to make it clear it's not ready for review |
OK now should be compiling, I don't want to spend too much time on integrating latest changes like time series since it seems that it is changing fast in the coming days,... Hope the latest merging were correct |
Thanks! I'll review asap but we will need to merge master anyway.. |
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.
Pretty cool!
The merge will be needed sorry.. If I had known I would have waited :(
I suggest:
1/ fix the indentations to have a clean diff
2/ do a merge master
web/app/countrytable.js
Outdated
@@ -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); |
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
web/app/countrytable.js
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
web/views/pages/index.ejs
Outdated
<div class="country-picker-container small-screen-visible" style="margin-left: 20px"> | ||
|
||
<div class="country-table-initial-text"> | ||
<p class="small-screen-visible" style="font-style: italic"> |
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.
Additional indentation creates a lot of diff
web/views/pages/index.ejs
Outdated
<svg class="co2-colorbar colorbar" style="width: 100%"></svg> | ||
</p> | ||
<p> | ||
<p> |
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.
Indent problem
@@ -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 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);
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.
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 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.
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.
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
# Conflicts: # web/app/countrytable.js # web/app/main.js # web/views/pages/index.ejs
@nikkozzblu please let me know when to review! |
Should be alright now, (hope so, I was almost able to run a stable development environment but just lost my VM connection as I change Wi-Fi network... :() |
Should be alright now, (hope so, I was almost able to run a stable development environment but just lost my VM connection as I change Wi-Fi network... :() |
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.
Almost there.
We need to support i10n for data shared on Facebook too. See https://developers.facebook.com/docs/opengraph/guides/internationalization
- On the
/
route, set locale based on thefb_locale
query string (values received comply to https://developers.facebook.com/docs/internationalization/#locales). We should also add alocale
orlang
querystring for ourselves. - For each language supported, add a meta property
<meta property="og:locale:alternate" content="es_ES" />
- For the current language used, set
<meta property="og:locale" content="en_US" />
I'll also verify all translations.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
This file shouldn't change
web/server.js
Outdated
//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 comment
The reason will be displayed to describe this comment to others. Learn more.
Style: Missing space after :
@@ -112,8 +110,8 @@ | |||
<input type="text" class="flatpickr" /> | |||
</div> | |||
</div> | |||
<p> | |||
<span id="country-table-back-button" style="display: none"><a><< back</a></span> | |||
<p> |
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.
Style: Indentation
<svg class="co2-colorbar colorbar" style="width: 100%"></svg> | ||
</p> | ||
<p> |
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.
Style: indentation
<svg class="solar-colorbar colorbar" style="width: 100%; display:none"></svg> | ||
</p> | ||
</div> | ||
</div> | ||
<div> | ||
<hr /> | ||
Found bugs or have ideas? Report them <a href="https://github.com/corradio/electricitymap/issues/new" target="_blank">here</a>.<br /> |
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.
Style: indentation. Also seems like order of two lines has been changed.
var currentMoment; | ||
|
||
|
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.
Extra line not needed
@@ -82,6 +85,8 @@ args.forEach(function(arg) { | |||
} else if (kv[0] == 'countryCode') { | |||
selectedCountryCode = kv[1]; | |||
replaceHistoryState('countryCode', selectedCountryCode); | |||
} else if(kv[0] == 'lang'){ | |||
reqLang = kv[1]; |
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.
- Style: indent
@@ -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 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.
web/app/tooltip.js
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Style: missing space after ,
web/package.json
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Style: Indentation error
Btw I added a section for global variables coming from the server: |
Not ready for production,
Having some problems with the panel-left new styles (Css not being updated ?!). Also notice wind/solar icons and scale not being displayed.
try it on http://localhost:8000/?lang=fr
You mainly find 2 files by language extension:
/locales/$lang.json
which contain the static translations (processed server side)
/app/config/lang.json
which contains the translations of the label that are filled dynamically on JS, append new language here