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

max.parker created an issue. See original summary.

liam morland’s picture

Thanks for the suggestion. It would be great to have a patch implementing this which provides a test to verify that translation is happening properly.

satya.eedeti’s picture

Uploading the patch. Please review.

liam morland’s picture

Status: Active » Needs review
satya.eedeti’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new33.36 KB
new42 KB

Have tested the functionality and uploading the screenshots for test evidences.

liam morland’s picture

Status: Reviewed & tested by the community » Needs review

People are not allowed to mark their own patches "Reviewed & tested by the community" (RTBC).

liam morland’s picture

Thanks very much for the patch. Are you able to write a test for this?

vijaycs85’s picture

StatusFileSize
new7.37 KB
new8.4 KB
new7.37 KB
new50.2 KB
new86.49 KB

Here is test to cover translation.

Status: Needs review » Needs work

The last submitted patch, 8: 2871134-8-test-only.patch, failed testing.

liam morland’s picture

Status: Needs work » Needs review

Thank you! I will review this shortly.

vijaycs85’s picture

Thanks for the quick response @Liam Morland.

liam morland’s picture

Status: Needs review » Needs work

Thanks 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.

vijaycs85’s picture

Please add a test for the "or earlier" condition like the existing "or later" condition.

Sure, I'll look into it.

Can you use the existing admin user created in WebformTestCase::setUp()?

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.

vijaycs85’s picture

Status: Needs work » Needs review
StatusFileSize
new7.61 KB
new3.18 KB
new8.99 KB
new79.29 KB

Updated patch... All green locally.

vijaycs85’s picture

StatusFileSize
new222.74 KB

Not sure why test-only patch is green as it throws error locally. Sent to retest.

vijaycs85’s picture

StatusFileSize
new7.96 KB

my bad, the test-only patch missing the inclusion in .info file :(. here is a proper test-only patch to fail.

Status: Needs review » Needs work

The last submitted patch, 16: 2871134-test-only-16.patch, failed testing.

vijaycs85’s picture

Status: Needs work » Needs review

Awesome! now #14 is ready for review.

liam morland’s picture

Status: Needs review » Needs work

Thanks 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.

vaza18’s picture

StatusFileSize
new9.22 KB

Take a look on this patch (simpletest should work too): 2871134-20-4.x-dev.patch

vaza18’s picture

Status: Needs work » Needs review
liam morland’s picture

Thanks 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.

vaza18’s picture

Hi Liam.

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.

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".

edemidenko’s picture

Version: 7.x-4.x-dev » 7.x-3.x-dev
StatusFileSize
new12.4 KB

Please take a look at the patch with unit tests for webform_7.x-3.x

liam morland’s picture

So, 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.

vaza18’s picture

Hi Liam.

So, 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.

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.

badjava’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev

Webform 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.

liam morland’s picture

Status: Needs review » Needs work

@vaza18: Thanks for the explanation. I am happy with the patch if it gets more comments explaining what it is doing.

liam morland’s picture

Status: Needs work » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.