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.
API page: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7
The docs say:
> The context the source string belongs to.
but they don't explain how this works or what this is. For instance, reading this you might think this is a machine name, or an option from a list defined somewhere else.
It's actually arbitrary, and AFAICT more of a description. There's more detail here: https://localize.drupal.org/node/2109
Comment | File | Size | Author |
---|---|---|---|
#26 | 2676472-7.x-26.patch | 2.03 KB | jhodgdon |
#11 | docs-for-t-function-and-related-2676472.11.patch | 2.48 KB | micaelamenara |
Comments
Comment #2
jhodgdonIt's an arbitrary string, which is why it isn't really explained...
There is some explanation here for 8:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Language!language...
and there are a bunch of 8.x functions with the same args, like TranslationInterface::translate() and for that matter t() and StringTranslationTrait::t(), that would need this documentation updated if we're going to update it for the D7 t() function.
So for D8 functions, we should do something like:
In D7, we don't have this topic, so we'd need to write something (preferably short) and then maybe link to that localize.drupal.org page.
Comment #3
micaelamenara CreditAttribution: micaelamenara at Globant commentedHere Its the Patch!
Comment #4
jhodgdonThanks for trying! The patch needs some work though:
This line has an extra space at the end. And it needs a space at the beginning between the * and the text.
Also rather than being its own paragraph, it should be added above at the end of the text that mentions 'context'.
This comment applies to the other two places this was put into the patch as well.
Comment #6
micaelamenara CreditAttribution: micaelamenara at Globant commentedThis is how I understood what you wrote. Please let me know if there is anything to be changed.
Regards.
Comment #7
jhodgdonCloser!
Yes, that is what I meant.
However:
- Why did you move the word "string" down to the next line? It was better up where it was. We want documentation lines to wrap as close to 80 characters as possible, without going over.
- @link ... @endlink has to stay on the same line. I think if you move "string" back up a line, you'll be able to fit the @endlink there... if not, then you would need to move the whole @link ... @endlink down to the next line.
Here, move @link ... @endlink down to the next line.
Here too.
Comment #9
heykarthikwithu.
Comment #10
heykarthikwithuComment #11
micaelamenara CreditAttribution: micaelamenara at Globant commentedComment #13
dagmarUnrelated test failure.
Comment #14
jhodgdonThanks! patch looks good now.
Comment #16
dagmarUnrelated test failure.
Comment #17
jhodgdonComment #22
catchCommitted/pushed to all three 8.x branches. Moving to 7.x for backport.
Comment #23
dagmarThis is the patch for Drupal 7.
Comment #24
jhodgdonThanks! It's pretty good... a few small suggestions:
It would be better, in this line, to just put in the URL directly rather than making an @link ... @endlink.
know -> learn
Comment #25
dagmarSure, thanks!
Comment #26
jhodgdonBetter!
So ... sorry I didn't look at this before... but let's compare this patch to the 8.x patch.
8.x, after patching:
And the internationalization topic says (in part):
And here is what is in the current patch for 7.x:
So... Since we don't have a topic that explains context in more detail in 7.x, I like that you put in more information in the 7.x doc block for t() than we had in the 8.x block. But I'm not sure that this text really explains the problem very well...
What about something like this?
Note: I didn't bother with an interdiff file since it's the same exact lines as the patch itself (all patched lines changed).
Comment #27
dagmarLooks great. Thanks!
Comment #28
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedMarked for commit, thanks!
Comment #29
stefan.r CreditAttribution: stefan.r commentedThis looks great, thanks!
Comment #30
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedCommitted to 7.x - thanks!
Comment #32
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedJust a note that the "@ref sec_context" doesn't seem to be working (it's just displayed as is at https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7.x - no automatic link to the section). Not sure if that's something that should be fixed on api.drupal.org or if we should just remove it from the code here instead.
Comment #33
stefan.r CreditAttribution: stefan.r commentedHow about
See the "String context" section above for more information
(no link) for now?Interestingly the @ref tag does seem to work on in D8 core documentation
Comment #34
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThat sounds good to me.