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.
t() cannot be used in a define() statement - document that fact.
Comment | File | Size | Author |
---|---|---|---|
#22 | 338443_t_define.patch | 11.32 KB | grendzy |
#20 | 338443_t_define.patch | 11.32 KB | grendzy |
#15 | 338443reroll.patch | 10.99 KB | jhodgdon |
#10 | t_rewrite.patch | 10.97 KB | jhodgdon |
#6 | caution_t.patch | 800 bytes | CitizenKane |
Comments
Comment #1
maartenvg CreditAttribution: maartenvg commentedI've been bitten by this at least once, so I agree that this should be in the documentation.
Perhaps we want to add a line saying what developers should do instead, because that isn't straight forward. Because
t(DEFINED_CONSTANT)
is evil as well. We can refer to the documentation in #336115: Additional documentation for t(), which covers translation of variables.Comment #2
catchAn extra line explaining what you should do sounds good. Marking to CNW for that.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commented@maartenvg: Then we need to fix the translation parser to understand the define and class const declarations so that it knows how to translate the strings. Having to specify the string constant in more than one place make it a horrid fix to make changes to the text. I therefore disagree that t(MY_DEFINED_CONST) is wrong and should be the desired way to create strings.
@catch: The proper use is discussed further in the document. The patch is a caution of where not to use the t() function.
Comment #4
nedjoRe $locale in the comment: do you mean $language?
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedSeems really obvious. I was pointed to the word locale from a version 5 api function for locale(). It changed in 6.
Comment #6
CitizenKane CreditAttribution: CitizenKane commentedAttached a patch which changes $local to $language.
Comment #8
jhodgdonLooks like the test bot was broken that day.
Comment #9
axyjo CreditAttribution: axyjo commentedWould the words 'not defined' possibly be a better alternative to the word 'unknown'? Also, I think the word 'constant' isn't needed. Besides that, I think this patch is nice and simple.
I'm on crack. Are you, too?
Comment #10
jhodgdonOh gosh.
That text didn't really belong where it was inserted in the last patch. In trying to find a better place for it, I ended up reorganizing and rewriting much of the doc, in order to be able to add a short paragraph about not using t() in a define() statement, and having it all make sense.
Comment #11
grendzy CreditAttribution: grendzy commentedpatch no longer applies to HEAD.
Comment #12
jhodgdon#10: t_rewrite.patch queued for re-testing.
Comment #14
jhodgdonLooks like this patch does indeed need to be redone.
Comment #15
jhodgdonApparently the t() function moved to a different file. Here is a reroll of the patch above.
Comment #16
grendzy CreditAttribution: grendzy commentedlooks good, nice style cleanups in addition to the define() documentation.
Comment #17
Heine CreditAttribution: Heine commentedThis is not limited to define statements; any t() call before the language is defined will result in
1) an incorrect string
2) atrocious performance (at least this was so in the past).
Comment #18
grendzy CreditAttribution: grendzy commentedok... more specifically can we say that "before the language is defined" means that before DRUPAL_BOOTSTRAP_LANGUAGE is reached? How about this as an alternative?
Comment #19
jhodgdonI like the suggestion in #18. Would you like to roll it into the patch?
Comment #20
grendzy CreditAttribution: grendzy commentedOnly change is the block from #18:
Comment #21
jhodgdonOh gracious. I should really be shot for this one, and it was in my patch above.
The first line should start with a verb in 3rd person: "translates" rather than "translate".
Otherwise, I'm happy with this latest patch. What say you Heine?
Comment #22
grendzy CreditAttribution: grendzy commentedok, corrected first word. Feedback on the technical accuracy about DRUPAL_BOOTSTRAP_LANGUAGE would be appreciated.
Comment #23
jhodgdonThanks for making that correction... I am happy with that patch. Perhaps Heine can comment on the technical accuracy question, since that is who brought up the latest round of re-patches?
Comment #24
grendzy CreditAttribution: grendzy commentedDiscussed with bdragon during the drupalcon sprint. We verified that the change proposed in #18 is accurate.
Patch still applies, so this should be ready.
Comment #25
jhodgdonDo you want to mark it RTBC?
Comment #26
grendzy CreditAttribution: grendzy commentedyep!
Comment #27
grendzy CreditAttribution: grendzy commentedComment #28
webchickGeez. ;) At least re-title these issues to something like "Fix everything in the world wrong with t()" so I know what I'm getting myself into. ;)
Anyway, took a spin through the changes and looked good overall.
Committed to HEAD!