Problem/Motivation
The text that appears within the validation message for a date element is translatable but the date itself isn't.
See:
('The entered date must be @start_date or later.', array('@start_date' => date($format, $start_date)))
Since '@start_date' is passed directly into date() it will always use the default timezone (usually set as the servers timezone or UTC) so ignores any translations.
Proposed resolution
Instead of using date() I suggest that it is changed to format_date() which handles the timezone and also any date format translations.
Many thanks
Comments
Comment #2
liam morlandThanks for the suggestion. It would be great to have a patch implementing this which provides a test to verify that translation is happening properly.
Comment #3
satya.eedeti commentedUploading the patch. Please review.
Comment #4
liam morlandComment #5
satya.eedeti commentedHave tested the functionality and uploading the screenshots for test evidences.
Comment #6
liam morlandPeople are not allowed to mark their own patches "Reviewed & tested by the community" (RTBC).
Comment #7
liam morlandThanks very much for the patch. Are you able to write a test for this?
Comment #8
vijaycs85Here is test to cover translation.
Comment #10
liam morlandThank you! I will review this shortly.
Comment #11
vijaycs85Thanks for the quick response @Liam Morland.
Comment #12
liam morlandThanks very much. Please add a test for the "or earlier" condition like the existing "or later" condition.
Can you use the existing admin user created in WebformTestCase::setUp()? If that works, it would be better than creating your own user.
Comment #13
vijaycs85Sure, I'll look into it.
I tired, but some permissions(related to translation) are missing and there is no way to alter the permissions of users under $this->webform_users list. So I had to create a new admin user.
Comment #14
vijaycs85Updated patch... All green locally.
Comment #15
vijaycs85Not sure why test-only patch is green as it throws error locally. Sent to retest.
Comment #16
vijaycs85my bad, the test-only patch missing the inclusion in .info file :(. here is a proper test-only patch to fail.
Comment #18
vijaycs85Awesome! now #14 is ready for review.
Comment #19
liam morlandThanks very much for the patch.
There are some coding standards issues in WebformTranslationTestCase.test. Please use coder_review. Please make sure every method has a docblock (even if just @inheritdoc) and that every @param has a type.
In WebformTranslationTestCase.test, please add more comments to translateString(). It is not clear what it is for. What is the purpose of the "\f\r" inside the date format for the "The entered date must be" messages? Is it supposed to be testing in both English and French? When I run it, line 125 is only called twice, always in English.
Comment #20
vaza18 commentedTake a look on this patch (simpletest should work too): 2871134-20-4.x-dev.patch
Comment #21
vaza18 commentedComment #22
liam morlandThanks for the patch.
I don't understand the "\f\r" inside the date format for the "The entered date must be" messages. This message appears for me in English. I thought it was supposed to be translated. I don't understand what translateString() is doing.
Comment #23
vaza18 commentedHi Liam.
In terms of testing the functionality it does not matter what translation will be applied for French version of the date. Of course we can add translation for day of week and month in French but I don't know French. Anyway, we just need to validate that the date is not in English and this means it was translated but translation itself is does not matter for test. We decided to split English and French translation by adding "FR" suffix to French version of the date. For example: "Tuesday" in English is translated to French like "Tuesday FR".
Comment #24
edemidenko commentedPlease take a look at the patch with unit tests for webform_7.x-3.x
Comment #25
liam morlandSo, do I understand correctly that it is not actually doing the translation, it it just testing that the translation system is working by faking the translation? There needs to be more comments in the code explaining what it is doing. Will these tests run correctly on a site that has French translations installed? Perhaps it should use a dummy language code instead of faking French.
Comment #26
vaza18 commentedHi Liam.
Yes, you understand it correctly. But in terms of translation testing, the translation itself is does not matter. The same as the languge. The only requirement is that language should be anything but English. In our case it overrides translation of "Tuesday" to "Tuesday fr" (French version) even if translation to French was present before. And it does this in tables with prefix, which were created by simpletest. So it has no affect to real web-site. I agree, that language can be any other. Using French is not required. But in terms of testing it is simpler to add/select some predefined language (e.g. French) from dropdown list rather than creating some dummy language.
Comment #27
badjava commentedWebform 3.x only receives critical bug fixes and not sure if this qualifies. Regardless, I'm changing it back while this issue is resolved in 4.x.
Comment #28
liam morland@vaza18: Thanks for the explanation. I am happy with the patch if it gets more comments explaining what it is doing.
Comment #29
liam morlandDrupal 7 is no longer supported. If this applies to a supported version, please re-open.