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.
Problem/Motivation
It is a bad habit to have code like:
$this->t($some_var)
because potx cannot find those strings.
There are places like generic YML files, where it is required to have such a mechanism
Proposed resolution
- Let's use a special inline comment to make sure potx don't forget about some of them.
- Discuss the comment
- Bikeshed the comment
- Write a patch and identify all instances
- Commit it
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#13 | 2303113-13.patch | 778 bytes | er.pushpinderrana |
#13 | interdiff-2303113-6-13.txt | 929 bytes | er.pushpinderrana |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedtypo in summary.
---
Might be related to, or need a related issue in, https://www.drupal.org/project/issues/search/potx?issue_tags=Drupal%208%...
Comment #2
YesCT CreditAttribution: YesCT commentedin
$this->t($some_var)
I wonder where the value of $some_var usually comes from.
If it is from a config file, or an annotation, we might be gathering them anyway.
Maybe we should look at some specific examples.
Comment #3
xjmComment #4
pwolanin CreditAttribution: pwolanin commentedComment #5
herom CreditAttribution: herom commentedmy suggestion:
or if "potx" isn't a well-known module:
Comment #6
dawehnerWe should also mention that calling t() with variables is a bad thing, so maybe something like this?
Comment #7
er.pushpinderrana CreditAttribution: er.pushpinderrana commentedComment #8
jhodgdonThe comment in #6 seems very verbose, and yet it doesn't give enough information to tell people who don't have any idea what's really happening.
So my suggestion would be:
a) Write up a brief documentation page (or section on a page) about this. There's probably something already that says "don't do this" in a module developer guide, so we could just add an "except" there.
b) In the "standard comment", link to this. Something like:
Comment #9
herom CreditAttribution: herom commentedwhat about this?
Comment #10
dawehnerWe don't have to mention POTX here, given that POTX is part of our community. POTX might confuse more people.
Comment #11
herom CreditAttribution: herom commentedremoved the potx mention.
Comment #12
jhodgdonProbably we should link to https://www.drupal.org/node/2133321 (which probably could use an alias), instead of https://www.drupal.org/developing/api/localization for Drupal 8, and add notes there about this topic?
Comment #13
er.pushpinderrana CreditAttribution: er.pushpinderrana commentedUpdated this patch on the basis of points mentioned in #11 and #12. Please review.
Comment #14
herom CreditAttribution: herom commentedI have also added a note in https://www.drupal.org/node/2133321 about (not) using variables in t() calls. maybe review that too?
Comment #15
jhodgdonThe note is OK; maybe it could be clearer with an example of what not to do though, and more prominent? And it could use a copy edit for minor punctuation, but no worse than the rest of the page... I'll make an edit now.
The patch looks OK too. It doesn't satisfy the issue summary since it is just the one spot being documented, but I think the idea was to get approval for the format before proceeding with the rest of the patch. If so, I think it's OK but maybe we should wait a day or two for others subscribed to this issue to respond.
I'm also going to add an alias to https://www.drupal.org/node/2133321 -- I guess it should be https://www.drupal.org/developing/api/8/localization for consistency with other pages in that section and the 7.x page. So you can update the patch to use that URL (shortly).
Comment #16
jhodgdonSetting this patch to "needs work" since it needs to be expanded, and the URL needs to be updated. See comment #16.
Comment #28
quietone CreditAttribution: quietone at PreviousNext commentedSince this issue was created there have been many patches to improve and correct the usages of t(). The documentation not directs the reader to https://www.drupal.org/node/322729 which explains the correct usage. That seems a much better approach than having to add comments to each usage of t().
Therefore, closing as outdated.
Thanks