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.
Any advice? Things aren't quite working here, and I'm trying to see if that has something to do with it. I can't find any documentation of what "context" is about. Thanks!
Comments
Comment #1
RobLoachContext isn't needed in most cases. In some parts of Drupal, when they use t(), they pass in context to have different translations depending on the situation. Most of the time, you won't need it. So just leave it blank :-) .
But if it's not working, have a look at the code that's calling t(), and see if there's a
'context'
option being passed.Comment #2
jim_at_miramontes CreditAttribution: jim_at_miramontes commentedAha. Got it; thanks!
Comment #3
chiddicks CreditAttribution: chiddicks commentedAt first I thought this was a reference to a context, as provided by the Context module. I was excited, since sometimes you don't want to override a string site-wide. Obviously, this is not what it's for, but it's a tantalizing possibility. Anyone have any ideas how selective overrides might be implemented? Integration with Context is actually a pretty good option.
Comment #5
RobLoachContext module integration might actually be a really good idea, chiddicks. If we somehow create grouping of String Overrides, and then allow the Context module to apply those string overrides based on certain criteria, we'd end up with a pretty powerful system that would allow contextual overrides. Great idea.
Comment #6
Mamoun CreditAttribution: Mamoun commentedSubscribe
Comment #7
btopro CreditAttribution: btopro commentedsub
Comment #8
chiddicks CreditAttribution: chiddicks commentedThe simplest way I can think of is to create a context "reaction" for each string override on the site - since the String Overrides configuration page already has an 'enabled' checkbox, it can function as a 'site-wide enable', as before. A string override could be enabled per-page by adding it as a reaction in a context or contexts, and unchecking the site-wide checkbox. I'm not sure at present the mechanism String Overrides uses to insert its strings, but hopefully there's a simple way to do it conditionally, at page-load.
http://drupalcode.org/project/context.git/blob/refs/heads/7.x-3.x:/API.txt
I'll look at this later this week if I have a chance, if no one else has posted progress.
Comment #9
chiddicks CreditAttribution: chiddicks commentedI've taken a little time to look at String Overrides works. Rob, please correct me where I am wrong. String Overrides relies on setting locale_custom_strings_[lang] variables, which the t() function conveniently checks before rendering a string. Elegant. As far as I can see, to get a custom string to conditionally show up, we either need to manipulate that locale_custom_strings_[lang] before the page load, and somehow reset it to default afterwards. Or, perhaps taking advantage of the t() function's "caching", wherein it uses a static variable to store the value of locale_custom_strings_[lang] for the duration of the page-load. The question is, can a static variable be manipulated in that way, outside of function scope?
Comment #10
RobLoachCorrectamongo! In the Context Reaction, it would look something like this...
The
$conf
variable is the static variables table, which would allow use to manipulate the overrides without having them permanently override. So what we'd need is the ability to make groups of String Overrides. The setting for the context reaction settings would take the language, and the group to apply when the context's conditions are met. It would then load in the group of string overrides into the static variable, and boom, contextual string overrides.Comment #11
RobLoachHmmm, maybe use the "Context" column of the String Overrides table? Hmmmmmmmmmmmmmmmmmmmmmmm....
Comment #12
RobLoachNot sure why the reaction isn't being executed...
In
stringoverrides/stringoverrides.module
:In
stringoverrides/plugins/context_reaction_stringoverrides.inc
:Comment #13
RobLoachHmmmm..........
stringoverrides/plugins/context_reaction_stringoverrides.inc
End of stringoverrides.module...
Comment #14
RobLoachBlocker: #1135950: Remove static caching in t()
Comment #15
chiddicks CreditAttribution: chiddicks commentedNice work! Rob, I was thinking that each String Override could be listed individually as a Context reaction (or perhaps only the ones that have NOT been enabled site-wide), so the user could enable them as required within the native Context admin UI. However, I expect you've considered all the options in the course of writing this script.
Did you intend to file #1135950: Remove static caching in t() in the 8.x issue queue? Either way, I see no reason why it couldn't be added to 7.x too.
Comment #16
RobLoachYou wouldn't want to clutter up the Context UI with all your contextual string overrides though. Would be nice to have a different reaction for each context, but if you had like 100 different contextual String Overrides, then it would get pretty gross in the UI.
With this, you add the "String Overrides" reaction to a Context, it then popped up the options form where you choose which String Overrides context group to apply. The thing missing from the code above is...
..... Requires #1135950: Remove static caching in t() :-) . If you had another idea for the UI, that would be cool. Just wanted to keep it as simple as possible ;-).
Yup! Patches need to go into 8.x before going into Drupal 7.x though. Webchick won't commit them unless they're in 8.x first... Mind reviewing it and RTBCing it? :-)
Comment #17
chiddicks CreditAttribution: chiddicks commentedOk, we're making progress. Did some more testing and RTBC'd the latest patch.
Comment #18
RobLoachJust did some testing with #1135950: Remove static caching in t() and it works with the code in #13. Going to mark this as postponed until the patch gets into both Drupal 7.x and 8.x.
Comment #19
akalata CreditAttribution: akalata commentedsubscribe :)
Comment #20
Katrina B CreditAttribution: Katrina B commentedI am interested in being able to set a String Override for certain places (e.g., one particular Webform) and not for others). Looking forward to seeing this feature implemented.
Comment #21
j0e CreditAttribution: j0e commented+1 for this feature... i'd hope the patch could be backported to Drupal 6 too!
Comment #22
kenheim CreditAttribution: kenheim commented+1 this would be awesome!
Comment #23
TechNikh CreditAttribution: TechNikh commented+1
Comment #24
rolandu CreditAttribution: rolandu commented+1
Comment #25
kingswoodute CreditAttribution: kingswoodute commented+1 yeah this would be fantastic.
Comment #26
GiorgosKissue linked from #18 got stuck long time ago
what a pity
Comment #27
junetellain626 CreditAttribution: junetellain626 commentedUpdates? :)
Comment #28
paulwdru CreditAttribution: paulwdru commentedHi,
Any update ? Working with Context module is a great idea otherwise this module is not so useful coz many use cases of t() don't specify a context.
Thanks