Skip to content
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

fix unit plural in contribution page #21944

Merged
merged 1 commit into from
Nov 23, 2021
Merged

Conversation

masetto
Copy link
Contributor

@masetto masetto commented Oct 30, 2021

This is the proposal to solve the problem of translation of the plural of frequency units in contribution page.
See this issue.

If the solution is good, it should also be applied in the pledge page.

@civibot
Copy link

civibot bot commented Oct 30, 2021

(Standard links)

@civibot civibot bot added the master label Oct 30, 2021
@demeritcowboy
Copy link
Contributor

It looks like all the .po files were autoupdated and now a lot of things have become untranslated, e.g. https://lab.civicrm.org/dev/translation/-/commit/5590912b2eb023c84975d86c51da68922c1c300b#21b169ad3734b06f683b854acd7a6621196eed52_30615_31048

@masetto
Copy link
Contributor Author

masetto commented Oct 31, 2021

@demeritcowboy sorry, I don't understand your comment and why checks are not passed.

@demeritcowboy
Copy link
Contributor

The month names used to be in report.po, but after the latest transifex update they are now in common-base.po and are no longer translated. fr_FR and es_MX need the month names to be retranslated in transifex.

@masetto
Copy link
Contributor Author

masetto commented Oct 31, 2021

But what does that have to do with my pull request?

@demeritcowboy
Copy link
Contributor

It just explains the test fails. It's not caused by your PR. All the PRs will fail until those month names are updated in fr_FR and es_MX. I posted here since it's where I saw it first but you're right it's a more general test fail.

@mlutfy
Copy link
Member

mlutfy commented Nov 5, 2021

jenkins, test this please

@demeritcowboy
Copy link
Contributor

jenkins retest this please

strange error

FATAL: command execution failed
java.io.EOFException
	at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2681)
	at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3156)
	at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:862)
	at java.io.ObjectInputStream.<init>(ObjectInputStream.java:358)
	at hudson.remoting.ObjectInputStreamEx.<init>(ObjectInputStreamEx.java:49)
	at hudson.remoting.Command.readFrom(Command.java:142)
	at hudson.remoting.Command.readFrom(Command.java:128)
	at hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:35)
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:63)
Caused: java.io.IOException: Unexpected termination of the channel
	at hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:77)

return ts('year(s)');

default:
throw new CRM_Core_Exception('Unknown unit: ' . $unit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that it's currently possible to edit the "Recurring Frequency Units" options from the "Administer" -> "Option Groups" area of the CiviCRM UI.

I can't think of any good reasons for adding or removing frequency units in this way, but there might be - if so it might be better to fallback to the exiting method of appending '(s)' if an unrecognised string is found, rather than throwing the exception.

Alternatively, maybe the "Recurring Frequency Units" option_group should be set to is_locked so that new options cannot be added. (and appreciate that's a seperate task, but maybe something to consider in tandem).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@braders see comments of this issue: I would have happily done so: return ts($unit . '(s)'); but we cannot put a variable in translation: https://docs.civicrm.org/dev/en/latest/translation/#best-practices.

Furthermore, the intervention is consistent with this. See also this comment.

@jaapjansma
Copy link
Contributor

test this please

@jaapjansma
Copy link
Contributor

@masetto we (@kainuk, @BettyDolfing and I) are doing reviews of PR's. We tried to test this PR, with CiviCRM in Dutch, but we failed to do so. On the contribution page we get errors and the dropdown with frequencies is still in English. It might be that something unrelated on the test site is broken but it might also be that your commits breaks something else. We are not sure about that.

Can you have another look at it? And maybe come up with instructions on how to test this? So we can reproduce the problem on dmaster.demo.civicrm.org and see whether your fix works.

Here some screenshot:
Screenshot_20211117_095113

Screenshot_20211117_095345

@masetto
Copy link
Contributor Author

masetto commented Nov 17, 2021

@jaapjansma I am sorry that you have had these problems, but they do not seem to be due to my changes.
To test them I add plurals of units in Words Replacement:
words replacement

Them my contribution form appears like this:

  • multiple units:
    contribution form with multiple units

  • single unit:
    contribution form with single unit

@demeritcowboy
Copy link
Contributor

demeritcowboy commented Nov 21, 2021

  • General standards
    • [r-explain] PASS
    • [r-user] PASS
    • [r-doc] PASS
    • [r-run] Issue
      • In the case where there's only one frequency unit it crashes when you submit the confirmation page. See r-code.
      • Otherwise it seems to work just these strings (day(s), etc) aren't in transifex yet so as noted earlier they don't translate unless you do word replacements.
  • Developer standards
    • [r-tech] PASS
      • As noted in the lab tickets redesigning the form might be better long-term, but this seems like an improvement.
      • There was some concern also in the tickets about the awkwardness of the (s), and even in english it feels funny, but again it still seems like an improvement pending a bigger fix. (This is probably why the strings don't already exist in transifex.)
    • [r-code] Issue
      • The hidden field frequency_unitCRM_Contribute_BAO_Contribution seems odd and unused. In the case where there's only one frequency unit available, you get a crash when submitting the confirmation form. Even if you put the field name back to frequency_unit, it then still crashes but with InvalidArgumentException: "recurFrequencyUnit must be day|week|month|year
      • The CRM_Core_OptionGroup::values() calls (especially where it calls it with the label column requesting value), and the $frUnits and $frequencyUnits and $unitVals manipulations are all a bit confusing. But some of it is pre-existing, and it seems to work out. But there might be some opportunity for cleanup here.
    • [r-maint] ?
      • It would be nice to have but I don't know how you'd write a test for this.
    • [r-test] PASS

Also should squash the commits.

@demeritcowboy
Copy link
Contributor

I need to update my review. The frequency_unitCRM_Contribute_BAO_Contribution field is problematic. In testing I had completed the form and submitted a couple variations but I guess not that one. I've updated above.

@masetto
Copy link
Contributor Author

masetto commented Nov 21, 2021

I am really sorry about the typo.:thumbsdown:

@demeritcowboy
Copy link
Contributor

No worries but note it still crashes. I think because the hidden field has the translated value.

@masetto
Copy link
Contributor Author

masetto commented Nov 21, 2021

In my tests it does not crash, I can't replicate it.
$form->_values['recur_frequency_unit']` shouldn't have always option group value (always month, year, week or day)?

@demeritcowboy
Copy link
Contributor

When there's only one unit option, e.g. if only months is checked on the config page.

@masetto
Copy link
Contributor Author

masetto commented Nov 21, 2021

Yes, I know, I'm testing like this, only one unit option. And these are my recur_frequency_units:
immagine

This is recurring contribution configuration of my contribution test page:
immagine

@demeritcowboy
Copy link
Contributor

On the test site here: http://core-21944-2pmad.test-1.civicrm.org:8001/civicrm/contribute/transact?reset=1&id=4

  1. This is the config for that page:

Untitled2

  1. Then fill it out and submit:

Untitled

  1. Then click the button to complete the contribution:

Untitled3

  1. Then it gives the error:
InvalidArgumentException: "recurFrequencyUnit must be day|week|month|year"

0 /home/jenkins/bknix-dfl/build/core-21944-2pmad/web/sites/all/modules/civicrm/Civi/Payment/PropertyBag.php(232): Civi\Payment\PropertyBag->setRecurFrequencyUnit("mese", "default")
1 /home/jenkins/bknix-dfl/build/core-21944-2pmad/web/sites/all/modules/civicrm/Civi/Payment/PropertyBag.php(352): Civi\Payment\PropertyBag->offsetSet("frequency_unit", "mese")
2 /home/jenkins/bknix-dfl/build/core-21944-2pmad/web/sites/all/modules/civicrm/Civi/Payment/PropertyBag.php(120): Civi\Payment\PropertyBag->mergeLegacyInputParams((Array:72))
3 /home/jenkins/bknix-dfl/build/core-21944-2pmad/web/sites/all/modules/civicrm/CRM/Core/Payment/Dummy.php(70): Civi\Payment\PropertyBag::cast((Array:72))
4 /home/jenkins/bknix-dfl/build/core-21944-2pmad/web/sites/all/modules/civicrm/CRM/Contribute/Form/Contribution/Confirm.php(2770): CRM_Core_Payment_Dummy->doPayment((Array:72))
5 /home/jenkins/bknix-dfl/build/core-21944-2pmad/web/sites/all/modules/civicrm/CRM/Contribute/Form/Contribution/Confirm.php(2397): CRM_Contribute_Form_Contribution_Confirm->processConfirm((Array:72), "204", "1", 0, "1")
6 /home/jenkins/bknix-dfl/build/core-21944-2pmad/web/sites/all/modules/civicrm/CRM/Contribute/Form/Contribution/Confirm.php(856):
  1. I haven't tested but I think you need to put back line 786 because right now it's the translated value in the hidden field.

@masetto
Copy link
Contributor Author

masetto commented Nov 22, 2021

Right! I push a fix.

@demeritcowboy
Copy link
Contributor

Thanks @masetto looks good. Can you just squash commits and then this is ready to go.

style fixes for compiling check

fix a typo

fix `recur_frequency_unit` hidden field value when there is only one unit option
@demeritcowboy demeritcowboy merged commit 6e35ea4 into civicrm:master Nov 23, 2021
@BettyDolfing
Copy link

test this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants