-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Allow chart dropdown labels to be translatable. #22349
Conversation
(Standard links)
|
2c09d80
to
28a4c4f
Compare
CRM/Report/Form.php
Outdated
*/ | ||
private function getChartLabels() { | ||
$charts = []; | ||
$charts[''] = 'Tabular'; |
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.
ts() for Tabular?
It might be more "standard" to do the assignment of _charts
in each subclass's constructor, and then you don't need this function, but this seems ok too.
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.
Oh yeah, extra ts
added. I was so focused on then other two that I missed this one.
This approach seemed like it had the advantage that the strings couldn't get out of sync between each report - I have seen a few instances where repeated strings don't match in terms of spelling, capitalisation etc. But I'm not overly fussed either way.
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.
Hm, I have noticed that at least one third-party extension has instroduced their own keys, and other extensions are using the structure that CiviCRM core is using at the moment:
I could extend getChartLabels
to continue to support the old array strucutre, but might be that moving the labels to the constuctor of each report is cleaner whilst still retaining backwards compatiability. I'll have a think about the best way forward.
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.
Based on this thread I've reworked the code so that the translations are defined in the constructor of each report.
28a4c4f
to
9051cf5
Compare
CRM/Report/Form.php
Outdated
@@ -1574,12 +1580,35 @@ public function addOptions() { | |||
*/ | |||
public function addChartOptions() { | |||
if (!empty($this->_charts)) { | |||
$this->addElement('select', "charts", ts('Chart'), $this->_charts); | |||
$this->addElement('select', "charts", ts('Chart'), $this->getChartLabels($this->_charts)); |
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.
@braders your passing through $this->_charts as a function param but the function in L1594 doesn't accept parameters
test fails were new-year related - test this please |
9051cf5
to
4e2dce6
Compare
Prior to this change, the strings 'Tabular', 'Bar Chart' and 'Pie Chart' were hardcoded.
4e2dce6
to
f787b3c
Compare
Looks good. Ran a couple. Good call on support for extensions still using the property. Interestingly I can't see how to make the dropdown appear for the soft-credit report. The trigger doesn't seem to be the |
Hm, good spot. It appears that each of the charts with |
Overview
Allow chart dropdown labels to be translatable.
Before
Prior to this change, the strings 'Tabular', 'Bar Chart' and 'Pie Chart' were hardcoded. This affects a handful of reports, which support bar and pie chart views:
After
It is possible for the strings to be translated, or for word replacement to be performed against the strings.
Technical Details
The labels were previously hardcoded within the
$_charts
array property against each report. However, in PHP properties cannot be directly assigned from a function call, so this would not have worked:As a result, I have re-worked the
$_charts
property to only contain information about the types of charts supported, not the labels. The labels are added in the newgetChartLabels
method.Every report supports a tabular display, and this is the default value. Therefore, this is no longer defined in the
$_charts
property, but instead gets added by default ingetChartLabels()
.