Problem/Motivation
This is just a continuation of
https://www.drupal.org/node/2540886#comment-10639286
I am creating a new issue to maintain traceability....
It is better to have only one commit per issue
The initial patch is a renamed copy of
replace_t_with_this_t-2540886-10.patch
Just a pre commit node :
krishnan.n deserves credit see
Steps to reproduce
grep -rl "use[ ]*StringTranslationTrait" * |grep -v "^modules" |xargs grep -n "\<t\>(" | grep -v "\* *" | grep -v "this->t"
Proposed resolution
Use $this->t where possible in files using StringTranslationTrait
See #42 for latest results of the grep command
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
martin107 commented@krishnan.n
This issue is mis-labelled. It is not a simple gmap issue ... it is a core thing.
Comment #3
krishnan.n commented@martin107, should we brute-force change *all* t()'s to $this->t() in core?
Adding another patch again only for quick review. Let me know if these changes seem good and will then script it.
Comment #4
martin107 commentedI don't think that is practical ...
There are a couple of issues which make a global replace difficult
1) in *.module files or other procedural code t() is still the only way forward.
2) The class in which the change is made must have use the stringTranslationTrait. ( or one of its base classes).
3) It is a tough ask to review thousands of changes at a time
... so t() will still be in Drupal15 ... I hope not :)
Comment #5
dawehnerIn general to make such conversions feasible ensure that you follow the following rule: Do just one kind of change at the same time, so like have an issue which converts all t() usages in classes that already have the StringTranslationTrait. With that you have an easier time as you can make less mistakes and reviewing is much easier as the changes are all in one logical changeset.
Comment #6
krishnan.n commentedFollowing dawehner's suggestion which seems sensible, grep'd thru the core and found only one instance where t() is used without $this->t(), other than in ./core/modules, which we should ignore? In any case, there is one instance in node module and a couple in tests.
An uglyish grep added just for future reference/(ab)use: search for files containing "use StringTranslationTrait", ignore modules dir, and then search for t() that is not in comments, return() or has this->t()
grep -rl "use[ ]*StringTranslationTrait" * |grep -v "^modules" |xargs grep -n "\<t\>(" | grep -v "\* *" | grep -v "this->t"Attaching patch -- this should be safe to commit.
Comment #7
krishnan.n commentedComment #8
krishnan.n commented@martinFrances:
Think making t() this-t() in only core is a good starting point. There was only one occurrence in the patch, but now few more; 'still manageable. Note: 'git blame' showed the current changes were all made by alexpott, so may want to discuss if this is valid/important patch
Comment #9
neha.gangwar commentedMade the suggested changes in Drupal/core/modules/config module.
If need to made changes in any other modules. Please let me know.
Comment #11
neha.gangwar commentedComment #14
heykarthikwithuComment #15
akishankarComment #16
aditya_anurag commentedComment #17
Bandana.kaur commentedI have reviewed the patch and it looks fine.
Comment #18
akishankarWhile reviewing the latest pull as of now, I figured out a couple of code snippets which need to updated with 't() to $this->t()' change.
Please review the patch.
Comment #23
martin107 commentedJust going back through old issues... triggering a retest
Comment #24
martin107 commented@akishankar
Sorry this issue got lost ... here is a reroll .. all your changes look good!
Comment #35
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Some of these appear to have already been completed.
Also don't think t() should be used in tests unless the test is for translation.
Comment #36
rassoni commentedFound new files in D10. Fixed and create a patch. Please review.
Comment #37
rassoni commentedComment #38
smustgrave commentedThis looks much better!
Comment #39
quietone commentedI checked the original issue and am adding credit for krishnan.n as suggested in the Issue Summary.
A reminder that when reviewing a patch or setting it to RTBC it is very helpful to describe in detail what one did to review the patch. There is Review a patch or merge request which should provide some guidance.
I applied that patch and ran the grep command, which I added to the IS, and there were more usages. The reason these are not being changed should be stated in the Issue Summary and/or the review comment.
The issue title status 'round 2'. Is there a round 3? Is there more to do? If these are indeed the last ones to fix, then a title change is in order.
Oh wait, there are many other issues about replacing t(). Yes, here is the Meta, #3113904: [META] Replace t() calls inside of classes . I am adding this to that Meta.
So, now we need to make sure that the scope is correct here and not conflicting with that issue or other children of that issue.
Setting to NW for scoping, title change, issue summary update.
Comment #42
quietone commentedRunning the grep command now results in the following. The remaining occurrences are in comments and non-object context.
Comment #43
quietone commentedComment #44
quietone commentedComment #45
smustgrave commentedI got a different result then #42 but after removing all the translation items believe I got the same actually
grep -rl "use[ ]*StringTranslationTrait" * |grep -v "^modules" |xargs grep -n "\<t\>(" | grep -v "\* *" | grep -v "this->t"was what I ran and I gotEither way definitely a net improvement.
Comment #48
catchLooks good. Committed/pushed to 11.x, thanks!