-
Notifications
You must be signed in to change notification settings - Fork 34
Feature/internationalize date formatting of charts #3381
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
Feature/internationalize date formatting of charts #3381
Conversation
@@ -69,7 +72,7 @@ Template.medianResponseTime.onRendered(function () { | |||
|
|||
// Get dates | |||
const labels = chartData.map(dataset => { | |||
return moment(dataset.date).format('MM/DD'); | |||
return moment(dataset.date).format(getLocaleDateFormat()); |
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 good enough. Get the locale format outside of loop
@@ -94,7 +97,7 @@ Template.requestTimeline.onRendered(function () { | |||
|
|||
// Initialization | |||
const labels = selectedPathData.dates.map(date => { | |||
return moment(date).format('MM/DD'); | |||
return moment(date).format(getLocaleDateFormat()); |
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.
Get the locale format outside of loop
@@ -69,7 +72,7 @@ Template.requestsOverTime.onRendered(function () { | |||
|
|||
// Get dates | |||
const labels = chartData.map(dataset => { | |||
return moment(dataset.date).format('MM/DD'); | |||
return moment(dataset.date).format(getLocaleDateFormat()); |
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.
Get the locale format outside of loop
@@ -89,7 +92,7 @@ Template.responseTimeTimeline.onRendered(function () { | |||
|
|||
// Create labels value | |||
const labels = selectedPathData.dates.map(date => { | |||
return moment(date).format('MM/DD'); | |||
return moment(date).format(getLocaleDateFormat()); |
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.
Get the locale format outside of loop
@@ -69,7 +72,7 @@ Template.uniqueUsersOverTime.onRendered(function () { | |||
|
|||
// Get dates | |||
const labels = chartData.map(dataset => { | |||
return moment(dataset.date).format('MM/DD'); | |||
return moment(dataset.date).format(getLocaleDateFormat()); |
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.
Get the locale format outside of loop
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.
One remarks
|
||
export function getLocaleDateFormat () { | ||
// Get locale | ||
const locale = window.navigator.userLanguage || window.navigator.language; |
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.
Using another command to cover all user's preferred language:
const locale = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage)
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.
And please squash all commits to one
27255d8
to
dedaf46
Compare
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.
One change in date.
let format = localeData.longDateFormat('L'); | ||
|
||
// Remove year part | ||
format = format.replace(/.YYYY/, ''); |
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.
Remove only the year, not the dot before year.
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.
@matleppa For what? The label looks "07.02" and I don't understand why do we need save the last dot?
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 label should look "07.02.", because the last dot is part of the date in this form.
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.
Can't agree with you 👀 let's ask other devs about this?
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.
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.
Keep the dot. In Finnish last dot is an indicator of the date. There's now dates without a fot after the month. "14.2." is a date in Finnish. "14.2" is not a date in Finnish.
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.
@preriasusi, That means we go with keep the dot with finish date.
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.
First if you get a date format from a i18n component/library, it is not a good ide ato start clipping it. And also very bad idea to do now some logic according to the language. Isn't there a format for the date without a year that you could use without doing any mods on it?
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.
@preriasusi Nope. We use moment.js and it doesn't provide locale date w/out year
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.
@marla-singer Ok, it seems that it doesn't. So, ok stripping the year away is in this case accettable. But touching the dot in Finnish date is very, very wrong thing to do.
@matleppa Add case for Finnish locale. Please check and let's merge it |
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.
Change in comparison.
let format = localeData.longDateFormat('L'); | ||
|
||
// Remove year part | ||
format = format.replace(/.YYYY/, ''); | ||
if (locale === 'fi') { |
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.
Seems not to work.
Should the comparison be
locale === 'fi-FI'
Or use regex to find 'fi'
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 remade it by using regex. Please check again. If everything is fine then not merge it yet, I wanna do rebase
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.
Unfortunately still some problem.
Does not fill the charts and
gives lots of exceptions about regex.text.
Exception from Tracker afterFlush function:
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 TypeError: regex.text is not a function
at getLocaleDateFormat (format_date.js:41)
at Blaze.View. (requests_over_time.js:74)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1934
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1932
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at viewAutorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1931)
at Tracker.Computation._compute (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:339)
at new Tracker.Computation (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:229)
at Object.Tracker.autorun (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:613)
at Blaze.View.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1944)
at Blaze.TemplateInstance.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3604)
at Blaze.TemplateInstance. (requests_over_time.js:69)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3398
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at fireCallbacks (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3394)
at Blaze.View. (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3487)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1845
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1844
at Object.Tracker._runFlush (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:548)
at onGlobalMessage (meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:398)
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 Exception from Tracker afterFlush function:
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 TypeError: regex.text is not a function
at getLocaleDateFormat (format_date.js:41)
at Blaze.View. (median_response_time.js:74)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1934
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1932
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at viewAutorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1931)
at Tracker.Computation._compute (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:339)
at new Tracker.Computation (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:229)
at Object.Tracker.autorun (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:613)
at Blaze.View.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1944)
at Blaze.TemplateInstance.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3604)
at Blaze.TemplateInstance. (median_response_time.js:69)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3398
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at fireCallbacks (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3394)
at Blaze.View. (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3487)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1845
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1844
at Object.Tracker._runFlush (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:548)
at onGlobalMessage (meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:398)
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 Exception from Tracker afterFlush function:
meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:942 TypeError: regex.text is not a function
at getLocaleDateFormat (format_date.js:41)
at Blaze.View. (unique_users.js:74)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1934
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1932
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at viewAutorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1931)
at Tracker.Computation._compute (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:339)
at new Tracker.Computation (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:229)
at Object.Tracker.autorun (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:613)
at Blaze.View.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1944)
at Blaze.TemplateInstance.autorun (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3604)
at Blaze.TemplateInstance. (unique_users.js:69)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3398
at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3744)
at fireCallbacks (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3394)
at Blaze.View. (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:3487)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1845
at Object.Blaze._withCurrentView (blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:2271)
at blaze.js?hash=f33d3dfed63a491d24e3aa07ad66c24b5fe8c761:1844
at Object.Tracker._runFlush (tracker.js?hash=997515fa2d5b0530ba07741da556c4b36963ef3b:548)
at onGlobalMessage (meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:398)
- Create an additional case fo Finnish locale. Using regex because different browsers handle it different way
d431611
to
72140a7
Compare
@matleppa Please check again |
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.
Works as expected.
Closes #2900
Changes
Developer checklist
This checklist is to be completed by the PR developer:
Reviewer checklist
Reviewed by: @marla-singer @matleppa
This list is to be completed by the pull request reviewer: