-
Notifications
You must be signed in to change notification settings - Fork 189
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
feat(i18n): new locale interface, and translation configs #1710
Changes from 10 commits
fbbfde3
b54bc7a
4894219
1701c4e
568da6a
b8813a6
d7ef3df
0ca33ac
40b9032
4fae08f
57cf915
04bc907
f6259bb
2db59ad
e799a2a
2d8273d
72459c4
ab1a29c
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 |
---|---|---|
|
@@ -18,16 +18,17 @@ export class MeterTitle extends Title { | |
const options = this.getOptions() | ||
const svg = this.getComponentContainer() | ||
const { groupMapsTo } = options.data | ||
|
||
const meterTitle = getProperty(options, 'locale', 'translations', 'meterTitle') | ||
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. let's try to organize these better (e.g. |
||
const proportional = getProperty(options, 'meter', 'proportional') | ||
|
||
if (proportional) { | ||
this.displayTotal() | ||
this.displayBreakdownTitle() | ||
} else { | ||
// the title for a meter, is the label for that dataset | ||
const title = svg.selectAll('text.meter-title').data([dataset[groupMapsTo]]) | ||
|
||
const title = svg | ||
.selectAll('text.meter-title') | ||
.data(meterTitle ? [meterTitle] : [dataset[groupMapsTo]]) | ||
title | ||
.enter() | ||
.append('text') | ||
|
@@ -214,7 +215,7 @@ export class MeterTitle extends Title { | |
*/ | ||
appendPercentage() { | ||
const dataValue = getProperty(this.model.getDisplayData(), 0, 'value') | ||
|
||
const { code, number: numberFormatter } = getProperty(this.getOptions(), 'locale') | ||
// use the title's position to append the percentage to the end | ||
const svg = this.getComponentContainer() | ||
const title = DOMUtils.appendOrSelect(svg, 'text.meter-title') | ||
|
@@ -237,7 +238,7 @@ export class MeterTitle extends Title { | |
.append('text') | ||
.classed('percent-value', true) | ||
.merge(percentage as any) | ||
.text((d: any) => `${d}%`) | ||
.text((d: any) => `${numberFormatter(d, code)}%`) | ||
.attr('x', +title.attr('x') + title.node().getComputedTextLength() + offset) // set the position to after the title | ||
.attr('y', title.attr('y')) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,6 +252,7 @@ export class Alluvial extends Component { | |
this.services.domUtils.generateElementIDString(`alluvial-node-title-${d.index}`) | ||
) | ||
|
||
const { code, number: numberFormatter } = getProperty(options, 'locale') | ||
// Node title - text | ||
textNode | ||
.append('text') | ||
|
@@ -267,7 +268,7 @@ export class Alluvial extends Component { | |
// shift 13 pixels down to fit background container | ||
.attr('dy', 13) | ||
.text((d: any) => { | ||
return `${d.name} (${d.value})` | ||
return `${d.name} (${numberFormatter(d.value, code)})` | ||
}) | ||
.attr('aria-label', (d: any) => { | ||
return `${d.name} (${d.value})` | ||
|
@@ -327,6 +328,7 @@ export class Alluvial extends Component { | |
addLineEventListener() { | ||
const options = this.getOptions() | ||
const self = this | ||
const { number: numberFormatter, code } = getProperty(this.getOptions(), 'locale') | ||
|
||
// Set delay to counter flashy behaviour | ||
const debouncedLineHighlight = debounce((link, event = 'mouseover') => { | ||
|
@@ -379,7 +381,9 @@ export class Alluvial extends Component { | |
items: [ | ||
{ | ||
label: datum.target.name, | ||
value: datum.value + (options.alluvial.units ? ` ${options.alluvial.units}` : ''), | ||
value: | ||
numberFormatter(datum.value, code) + | ||
(options.alluvial.units ? ` ${options.alluvial.units}` : ''), | ||
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. let's not do string concatenation here, since a user might return a number through 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. should I convert the numberFormatter value to a string? since we have to append alluvial units to it. |
||
color: strokeColor, | ||
labelIcon: self.getRightArrowIcon() | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||
import { select } from 'd3' | ||||||
import { flipDomainAndRangeBasedOnOrientation, generateSVGPathString } from '@/tools' | ||||||
import { flipDomainAndRangeBasedOnOrientation, generateSVGPathString, getProperty } from '@/tools' | ||||||
import { boxplot as boxplotConfigs } from '@/configuration' | ||||||
import { BoxplotChartModel } from '@/model/boxplot' | ||||||
import { Component } from '@/components/component' | ||||||
|
@@ -334,7 +334,9 @@ export class Boxplot extends Component { | |||||
hoveredElement, | ||||||
items: [ | ||||||
{ | ||||||
label: options.tooltip.groupLabel, | ||||||
label: | ||||||
getProperty(options, 'locale', 'translations', 'group') || | ||||||
getProperty(options, 'tooltip', 'groupLabel'), | ||||||
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.
Suggested change
|
||||||
value: datum[groupMapsTo], | ||||||
class: self.model.getColorClassName({ | ||||||
classNameTypes: [ColorClassNameTypes.TOOLTIP] | ||||||
|
@@ -442,7 +444,9 @@ export class Boxplot extends Component { | |||||
hoveredElement, | ||||||
items: [ | ||||||
{ | ||||||
label: options.tooltip.groupLabel, | ||||||
label: | ||||||
getProperty(options, 'locale', 'translations', 'group') || | ||||||
getProperty(options, 'tooltip', 'groupLabel'), | ||||||
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.
Suggested change
|
||||||
value: datum[groupMapsTo], | ||||||
class: self.model.getColorClassName({ | ||||||
classNameTypes: [ColorClassNameTypes.TOOLTIP] | ||||||
|
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.
pls use more readable names. it's clear on this line that you're pulling a locale code, but in another line in this file when you will pass
code
into a function, it's not clear (from the name) whatcode
isThere 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 I'll keep this in mind, I have updated to localeCode.