Closed mohitwp closed 10 months ago
@aaemnnosttv This feels to me like something we should fix sooner than later as it just doesn't look very nice. Let me know what you think!
This is a limitation of Google charts which defers this kind of formatting to the configured locale of the charts library as a whole. This isn't ideal because the currency of the data isn't specific to a geographic locale.
https://developers.google.com/chart/interactive/docs/gallery/linechart#data-format
We currently load the charts with the default locale, but even if we passed through the user's locale (used for formatting numbers, etc) this wouldn't exactly solve the problem because it would still be formatting the currency based on the locale, not the data it's plotting which we don't know about until it comes from the API of course.
Not a great experience, but I'm not sure what we can really do about this for now 😕
I've looked into this and it turns out we can address this by using the vAxis.format
decimal pattern syntax, in conjunction with loading the Google Chart in the user's locale (this is necessary in order to fully support locale-specific number formatting).
I've put together a PoC - here's how it looks with the WP language set to French (note this is a development site so SK's own text isn't translated, but it would be in a real-world scenario):
It seems to me that loading the charts in the user's locale is the right thing to anyway, so I've added AC to this issue which include that aspect.
@techanvil Does setting the locale to French force the Euro currency in this case? Locales and currencies shouldn't be tied together like that 😓
I suppose if Google Charts won't let us manually specify currency there's not much we can do, but French locale could warrant all sorts of non-Euro currencies, just as a for instance. 🤔
Hey @tofumatt, the locale and currency are decoupled by virtue of specifying our own pattern for vAxis.format
, rather than specifying the built-in currency
format. In the previous example the vAxis.format
value is determined to be #,###,##0.00 €
- which is the French format barring the group ,
and decimal .
separators, which the Google Chart always expects as the comma and period respectively. Setting the locale on the chart then ensures it renders the locale-specific separators (e.g. these are swapped in the French notation). Note that the currency symbol in the format pattern is determined from the currencyCode
provided by the AdSense report.
To illustrate further here's the same chart with Japanese selected in WP:
And here it is in en-US
:
With the vAxis.format
value being determined as €#,###,##0.00
in both of these cases.
Awesome, okay, thanks for the explanation 😅
In that case: all is good! 🙂
@derweili Looks good, but can you add an estimate for the issue? I'm guessing around an 11 but want to confirm with you 🙂
IB ✅
Verified:
Bug Description
While using oi.ie site. Under AdSense (Performance for the last 28 days) widget showing earnings in euro 💶 but on Y axis currency listed as $. Ideally, both currency should match and graph currency must get update as per data.
Steps to reproduce
Screenshots
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
en-US
-equivalent format for any unsupported locale.Implementation Brief
This PoC can serve as a starting point for the IB.
assets/js/components/GoogleChart/index.js
GoogleChart component, pass the locale to the chart usingchartLanguage={ getLocale() }
assets/js/components/GoogleChart/utils.js
create a new functiongetCurrencyPattern()
currencyCode
(e.g.USD
,GBP
,EUR
), andlocale
(optional). Set the default value for local togetLocale()
.vAxis.format
on the Google Charts docs. Example:'$ #,###,##0.00'
.
while the grouping/thousands separator must always be,
. This will part will be localized by the GoogleChart automatically, as we set the Chart locale.getCurrencyPattern()
function on the PoC.getCurrencyPattern()
function.getFormat
function within the Stats component.options.vAxis.format
and call the new getFormat() function and passcurrentRangeData.headers[ selectedStats + 1 ]
.currentRangeData
do a deep clone usingcloneDeep
from lodash.getFormat()
function descructuretype
andcurrencyCode
.type
isMETRIC_CURRENCY
returngetCurrencyPattern()
from the funciton.formats[ type ];
Test Coverage
getCurrencyPattern()
QA Brief
$
(English US) and some show it likeUS$
(English Canada)Changelog entry