Replace t() with $this->t() where StringTranslationTrait is used

Created on 5 December 2015, over 8 years ago
Updated 28 June 2024, about 16 hours ago

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

📌 Task
Status

Needs review

Version

11.0 🔥

Component
Configuration 

Last updated about 5 hours ago

Created by

🇬🇧United Kingdom martin107

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India Rashmisoni Bangalore
    grep -rl "use[ ]*StringTranslationTrait" * |grep -v "^modules" |xargs grep -n "\<t\>(" | grep -v "\* *"  |  grep -v "this->t"
    

    Found new files in D10. Fixed and create a patch. Please review.

  • Status changed to Needs review over 1 year ago
  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    This looks much better!

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • Status changed to Needs work about 1 year ago
  • 🇳🇿New Zealand quietone New Zealand

    I 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, 📌 [META] Replace t() calls inside of classes Active . 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.

  • Pipeline finished with Success
    about 17 hours ago
    #210607
  • Status changed to Needs review about 16 hours ago
  • 🇳🇿New Zealand quietone New Zealand

    Running the grep command now results in the following. The remaining occurrences are in comments and non-object context.

    )$ grep -rl "use[ ]*StringTranslationTrait" * |grep -v "^modules" |xargs grep -n "\<t\>(" | grep -v "\* *"  |  grep -v "this->t"
    core/lib/Drupal/Core/Entity/EntityFieldManager.php:668:    // hook_entity_extra_field_info_alter() might contain t() calls, we cache
    core/lib/Drupal/Core/Config/ConfigManager.php:178:      // Cast the result of t() to a string, as the diff engine doesn't know
    core/lib/Drupal/Core/Config/ConfigManager.php:184:      // Cast the result of t() to a string, as the diff engine doesn't know
    core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php:104:        // rather than use t() since we are in the middle of error handling, and
    core/lib/Drupal/Core/EventSubscriber/FinalExceptionSubscriber.php:105:        // we don't want t() to cause further errors.
    core/modules/media/src/Entity/Media.php:483:      ->setLabel(t('Name'))
    core/modules/media/src/Entity/Media.php:497:      ->setLabel(t('Thumbnail'))
    core/modules/media/src/Entity/Media.php:498:      ->setDescription(t('The thumbnail of the media item.'))
    core/modules/media/src/Entity/Media.php:513:      ->setLabel(t('Authored by'))
    core/modules/media/src/Entity/Media.php:514:      ->setDescription(t('The user ID of the author.'))
    core/modules/media/src/Entity/Media.php:545:      ->setLabel(t('Authored on'))
    core/modules/media/src/Entity/Media.php:546:      ->setDescription(t('The time the media item was created.'))
    core/modules/media/src/Entity/Media.php:563:      ->setLabel(t('Changed'))
    core/modules/media/src/Entity/Media.php:564:      ->setDescription(t('The time the media item was last edited.'))
    core/modules/media_library/src/MediaLibraryUiBuilder.php:95:      'title' => t('Add or select media'),
  • 🇳🇿New Zealand quietone New Zealand
  • 🇳🇿New Zealand quietone New Zealand
Production build 0.69.0 2024