Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Posted by xjm
Part of meta #500866: [META] remove t() from assert message.
Comment | File | Size | Author |
---|---|---|---|
#61 | 1797364-61-t-locale.patch | 813 bytes | dcam |
#56 | interdiff.txt | 1.88 KB | dcam |
#56 | 1797364-56-t-locale.patch | 51.5 KB | dcam |
#54 | 1797364-54-t-locale.patch | 51.5 KB | dcam |
#50 | 1797364-50-t-locale.patch | 50.86 KB | dcam |
Comments
Comment #1
xjmIncludes lots of
format_string()
replacements.An assertion in
LocaleJavascriptTranslation
was trying to win the Fewest Lines of Code Award™ with multiple conditions, a ternary, and two uses oft()
with arguments inside the assertion. I factored it out into something somewhat more sane:Since the string doesn't need to be translated, the rule about using it directly within
t()
of course does not apply, which is why we can store the message template with placeholders to a variable for readability.Comment #3
xjmI think this is a sign that I should stop doing these now. :)
Comment #4
Lars Toomre CreditAttribution: Lars Toomre commentedI reviewed the patch in #3 and found a couple of things further to clean up. Attached is a revised patch and an interdiff.
Comment #5
Lars Toomre CreditAttribution: Lars Toomre commentedThis is going to conflict with #1808374: Wrong plural for french in locale tests depending on which gets in first.
Comment #6
xjmThanks Lars. The changes in #4 look mostly correct as well (though the group message part wasn't part of the original scope). One issue:
Bug here. The placeholder is
%expected
but the array key is%expect
.I also had to think twice about these messages, since they include
t()
-style placeholders in them, but they should default to displaying the placeholder as part of the message when it's not set in the array of substitutions.Comment #7
Lars Toomre CreditAttribution: Lars Toomre commentedThanks for the review @xjm. Good catch on '%expect' where it should be '%expected'.
Regarding t() around the group parameter, in one of the sub-issues of this initiative (sorry, I cannot recall which one), @jhodgdon stated that she would welcome any patches that also remove t() from around the group parameter. Hence, since then, where appropriate, I have added that change as well.
I will try to re-roll a patch for the issue you noted in #6.
Comment #8
Lars Toomre CreditAttribution: Lars Toomre commentedMy limited git skills are failing me. Apparently since #4 was created, an independent commit was made to LocaleUninstallTest.php. Hence, I am not able to resolve what is going wrong with git apply.
Perhaps someone else can re-roll the patch in #4 that includes the comment for #6. Thanks in advance.
Comment #9
xjm@Lars Toomre, there are two things you can try. One would be to reroll the patch with rebase and resolve any merge conflicts. The other would be to apply the patch with
git apply --reject
, which would apply all the lines but the ones that no longer work, and then re-add those changes manually if appropriate.Comment #10
Lars Toomre CreditAttribution: Lars Toomre commentedThanks @xjm. The second option in #9 worked and I simply went through and made all of the changes again in LocaleUninstallTest.php. Hence, that file too needs to reviewed carefully again in the attached patch. I am unable to create an interdiff at present.
Comment #11
Lars Toomre CreditAttribution: Lars Toomre commentedGrr.. Need to remember to change the status.
Comment #12
xjmGlad to see that worked.
I reviewed #10 carefully both locally and in Dreditor (gotta love the new patch format from
.gitattributes
) and didn't find any additional errors. (Several things to be careful of in this patch since it's from the module that testst()
itself!)I can't RTBC this because I created the original patch.
Comment #13
Lars Toomre CreditAttribution: Lars Toomre commentedI obviously cannot RBTC this patch either. Perhaps we can recruit someone (beside @jhodgdon) to do a review so that @jhodgdon can do a further review before commit?
Comment #14
boran CreditAttribution: boran commentedI looked though he sources changes, and didn't notice any problems. The basic change involved removing t() from the second argument to assertRaw().
There is the issue of "1 heure" to "@count heure" as noted in a separated issue #1808374.
$this->assertRaw("msgid \"1 hour\"\nmsgid_plural \"@count hours\"\nmsgstr[0] \"1 heure\"\nmsgstr[1] \"@count heures\"", 'Plural translations exported properly.');
So, did a fresh d8 install from git, enabled locale and added the french language.
Ran the locale tests from admin/config/development/testing
Applied the patch in #10, and reran the tests and verified that the results are exactly the same (see attached screenshot).
==> Is this the testing required? Please advise what you'd like done.
Now, I'm pretty new to units tests, so I'm not sure if this review i enough. I presume the idea was to see if the lines where t() was removed contained syntax errors or cause tests to fail?
Comment #15
Lars Toomre CreditAttribution: Lars Toomre commented#10: 1797364-10-t-locale.patch queued for re-testing.
Comment #17
Lars Toomre CreditAttribution: Lars Toomre commentedIssue #1809962: Move some locale updates to update.inc for a safe language upgrade. was committed so this will need to re-rolled.
Comment #18
xjmThanks @boran for the review! Yep, for this issue, it's basically just a matter of ensuring that each change is transparent (i.e. that it only has the effect of removing the coupling to translation, without altering the actual assertion displayed at all or accidentally altering different parameters).
git diff --color-words --unified=0
with the patch applied is a good way to scan the changes, and for trickier bits running the test locally and checking the assertions is a good idea too, though in most cases that's not necessary. Testbot takes care of checking for failed tests and syntax errors for us.Comment #19
xjm#1812170: Remove dependency on the standard profile from LocaleContentTest will probably collide with this as well.
Comment #20
dcam CreditAttribution: dcam commentedRerolled #10. interdiff.txt shows additional t() functions removed after the reroll.
Comment #21
izus CreditAttribution: izus commented#20: 1797364-20-t-locale.patch queued for re-testing.
Comment #22
izus CreditAttribution: izus commentedhi,
the patch seems good.
Thanks
Comment #23
jhodgdonI was taking a look at committing this, but really I don't think the changes to some of the tests' syntax in several places are very good. They make the code less clear IMO. I'll leave this for someone else to commit if they want to.
I don't really get why we need to use a really complicated format_string() in place of what was a fairly simple string concatenation in a test assertion?
Comment #24
alexpottThese changes are out-of-scope... we're not removing a call to t() here.
The messages here look bogus... surely we the creation of deletion is unsuccessful we want to know the name of the file!... the following looks much simpler to me...
This change is not logically equivalent... something like the following is..
Comment #25
jhodgdonBump! There are only a few of these "remove t()" issues left. Does someone want to make a new patch addressing the comments in #24 so we can get this one done?
Comment #26
dcam CreditAttribution: dcam commentedI'm camping this weekend. I probably won't be able to fix it until Tuesday. Maybe someone else will get to it first. It would be nice to finally get these reviewed and out of my issue queue.
Comment #27
dcam CreditAttribution: dcam commentedRerolled #20, then made the changes from #24. Changes are shown in interdiff.txt.
Comment #28
lazysoundsystem CreditAttribution: lazysoundsystem commentedAt last I think we're going to get to the end of this issue... RTBC.
Comment #29
jhodgdonSorry, but the patch does not apply today.
Comment #30
neetu morwani CreditAttribution: neetu morwani commentedrerolled patch in the tests for the locale module.
Comment #31
neetu morwani CreditAttribution: neetu morwani commentedrerolled patch in the tests for the locale module.
Comment #33
lazysoundsystem CreditAttribution: lazysoundsystem commentedThe cmi statistics patch in #31 involves quite a few other changes. Re-rolling the patch in #27 has one change that needed to be removed, and removal of another remaining t().
These from the patch in #31
This change should probably go in a different issue.
and this too.
And the many changes to LocaleUpdateTest.php
Comment #35
lazysoundsystem CreditAttribution: lazysoundsystem commentedSorry for the noise, there was another change, from '->langcode' to '->id'. This one applies.
Comment #36
jhodgdonTHIS IS THE LAST ONE OF THESE plain-vanilla remove t() from test assert issues!!!! (at least, I think it is)... Can someone please review it so we can get it into 8.x, then backport to 7.x, and be DONE with the meta-issue? :)
Comment #37
Lars Toomre CreditAttribution: Lars Toomre commentedI do not have a local D8 installation to apply the patch in #35 against. Hence, I am unable to confirm that the resulting patched file has caught all of the appropriate t() calls.
However, what is changed in the patch I can confirm is all correct. Hence, I think that this final pain-vanilla remove t() patches is ready to go!
Comment #38
jhodgdonThere are still problems with this patch:
a) This segment of LocaleJavascriptTranslation.php is not quite right:
For one thing, the indentation of the first line is wrong. For another thing, let's just keep the code as it was and remove t() rather than making completely new code. Out of scope for this issue. Thanks!
b) Also, on another issue we were asked to stop using format_string():
#2035077-2: removing t() from asserts - remaining changes.
so I guess I cannot commit this until that is addressed for lines changed in this patch. :(
c) Don't change the code around in tests -- out of scope -- such as this segment of LocaleUninstallTest.php:
Comment #39
dcam CreditAttribution: dcam commentedHere's a reroll and the changes from #38.
Comment #41
dcam CreditAttribution: dcam commentedLet's try this again. A '}' was accidentally deleted.
Comment #43
lazysoundsystem CreditAttribution: lazysoundsystem commentedThanks @dcam for taking this back to basics, it had started to get out of control. The patch applies fine and looks good, but it needs
use Drupal\Component\Utility\String;
at the top of each file that uses String::format.here,
and here,
and here.
Comment #44
dcam CreditAttribution: dcam commentedOops. I guess I expected the namespace was already loaded or maybe I just wasn't thinking.
Comment #45
lazysoundsystem CreditAttribution: lazysoundsystem commentedThanks - this is now complete. RTBC.
Comment #46
jhodgdonUmmm... This change in LocaleUninstallTest still doesn't look right to me:
I think the message used to say "none" if the test failed and the file did not exist. That won't happen with the patch.
Everything else looks OK.
Comment #47
dcam CreditAttribution: dcam commentedI checked for other problems, but obviously wasn't diligent enough. I also made certain to check for newer t() functions and found one.
Comment #48
lazysoundsystem CreditAttribution: lazysoundsystem commentedWell, this issue has already been RTBC four times (twice by me), so I'm a bit hesitant to try once more. RTBC.
Comment #49
alexpottNeeds a reroll...
Comment #50
dcam CreditAttribution: dcam commentedUgh.... rerolled #47.
Comment #51
lazysoundsystem CreditAttribution: lazysoundsystem commentedFor what it's worth, once more: RTBC.
Comment #52
jhodgdonTHANKS! Committed to 8.x (before it needs another reroll). :)
7.x should require much less rerolling and anguish... anyone up for a backport?
Comment #53
dcam CreditAttribution: dcam commentedOh, thank goodness... I wasn't looking forward to the possibility of rerolling it yet again for D8. I'll backport it later unless someone beats me to it.
Comment #54
dcam CreditAttribution: dcam commentedBackport of #50.
Comment #55
lazysoundsystem CreditAttribution: lazysoundsystem commentedThis all looks good except for an inconsistency with t()s inside 'format_string()' calls. All have been removed, except these three.
Comment #56
dcam CreditAttribution: dcam commentedHere's #54 + the changes from #55.
Comment #57
lazysoundsystem CreditAttribution: lazysoundsystem commentedThanks, RTBC.
Comment #58
David_Rothstein CreditAttribution: David_Rothstein commentedI'm not sure that one is right, but there's no way I'm holding up what is apparently the last one of these "remove t()" issues over that!!! (I think it doesn't matter much in practice, and we could always have a followup to add it back.)
Therefore, committed to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/e516351
If this is really the last one of these issues, someone should throw a very large party. Great work everyone.
Comment #59
hass CreditAttribution: hass commentedThis 'Save translations' looks wrong to me as it fails in other site languages.
Comment #60
jhodgdonYes, that one was wrong. (#58). Follow-up please?
Comment #61
dcam CreditAttribution: dcam commentedHere's the follow-up.
Comment #62
David_Rothstein CreditAttribution: David_Rothstein commentedLooks good - thanks!
FYI, the reason I don't think this matters much in practice is that this test (like almost all tests) runs in English. It doesn't matter if the parent site is in another language; this code runs against the site that is being tested so it should pass regardless.
But it still makes sense to fix this anyway, for consistency etc.
@jhodgdon, you can certainly feel free to commit this whenever you want (including right before the 7.23 release - this patch is definitely not subject to "code freeze").
Comment #63
jhodgdonThanks! Follow-up committed to 7.x
And, this was the *****LAST ONE*****
(cheers!)
Comment #64.0
(not verified) CreditAttribution: commentedRemoving myself from the author field to unfollow the issue. --xjm