Problem/Motivation
The translate interface (admin/config/regional/translate) lacks filtering by string context and location, making translation management difficult on sites with many strings. Key use cases:
- Webforms*: Cannot isolate strings for specific webforms (context includes webform node ID)
- Node types: Cannot filter by bundle (e.g., "type:page:")
- SDC components: Context usage will increase significantly with #3493070
- Location filtering: Cannot filter by file path where strings are defined
*Webform contributed module
Steps to reproduce
- Install Drupal with multiple languages enabled
- Navigate to
/admin/config/regional/translate
- Observe the available filters: "String contains", "Translation language", "Translation status"
- Try to filter strings by their context value → No context filter available
- Try to filter strings by their location (file path) → No location filter available
- Result: On sites with hundreds or thousands of translatable strings, finding strings from a specific context or location requires manual scrolling or using the generic "String contains" search
Proposed resolution
Add Context and Location filter dropdowns to the translate interface:
- Dropdowns populated with all available contexts/locations (alphabetically sorted)
- Uses LIKE matching for partial searches
- Filters combine with AND logic
Remaining tasks
- Add location filter implementation (mentioned in #10, #18, #58, #63 but not yet coded)
- Final code review of context filter (MR !4174)
- Manual testing confirmation
User interface changes
New "Context" and "Location" dropdown filters on /admin/config/regional/translate.
API changes
New optional interfaces:
StringContextInterface::getContexts(): array;
StringContextInterface::getDistinctLocations(): array;
No BC breaks - existing implementations unaffected.
Comments
Comment #1
jweowu commentedComment #2
rogerrogers commentedHey, this is a very helpful filter. In fact, it's more essential than any of the existing filters. However, it would be great if, instead of a free text field, the filter was another dropdown with the full list of contexts. The trouble with a free text field is that the content manager doesn't know the context names. Even if the list is long, it would still be more useful for the content manager to have a list of names to pick from.
Regardless, thanks for this very helpful patch!
Comment #3
jweowu commentedIt needs to be a text field, because it's not necessarily a complete value you're searching for.
Certainly my use case was to find ALL contexts associated with a particular webform, by searching for the common prefix (and ditto for the example I gave in the issue description, whereby filtering on "type:page:" will find all string translation contexts for the 'page' node type.
I can see the potential use in also having a select list filter (although that list really can get huge), but the current approach has more general utility.
Comment #4
rogerrogers commentedI too have used the approach of prefixing all site specific contexts with a unique keyword and it does work well.
Thanks for the reply!
Comment #5
mario.awad commentedThis is very useful. Thanks.
Regarding the usage of a textfield vs a dropdown I think both are very needed and the perfect solution would be to provide both in the interface. If the user wants to choose a context from the dropdown, it's easily there and usable. If they fill the textfield then that will be used.
I know this is harder to implement but maybe we can help if there's interest in pushing this into core.
Thanks again.
Comment #6
daulet2030 commentedI used this patch and it works great! I think it needs review and hopefully a commit :)
Comment #7
jasonyarringtonHas anyone created a patch that creates the same filter on the Translate Export?
Comment #8
ericdsd commentedThis patch works like a charm, thanks
This should really be committed in next release as it fits a widespread need.
Comment #9
stefanweberworks great. Commit please.
Comment #10
hargobindGreat patch. I also find Location a helpful field to search on. Here's a patch with that field added.
Comment #12
hargobindI guess automated testing doesn't work unless you create the patch against an actual branch.
Comment #13
nicrodgersPatch applied cleanly and works perfectly. Code appears to confirm to the coding standards. Looks great - such a useful addition!
Do we need to add some automated tests before we can get this committed?
Comment #14
bird-cage commentedWe are currently developing a D8 Site for which this same feature would be very useful. Here is the feature request for D8.
Comment #15
ljcarnieri commentedNice patch, i created one looks like this, but the context filter is the select options, because context is used in code,then sometimes is difficult to remember the names that you used.
What do you think?
Comment #16
jweowu commentedljcarnieri: Please see comment #2 and comment #3 above.
Comment #17
ljcarnieri commentedjweowu: sorry.
Maybe, one autocomplete works well?
Look this patch. What do you think?
Comment #18
David_Rothstein commentedBased on the above discussion it looks like this is relevant for Drupal 8 too and would need to go in there first.
Also retitling based on the direction of the latest patches (although perhaps they could be separate issues instead).
Will the average site administrator really have a clue what "location" and "context" mean in this user interface?
Comment #19
swentel commentedworking on this
Comment #20
gábor hojtsyA location filter in Drupal 8 could allow to filter to configuration strings, or JS strings, that kind of stuff. A context filter could filter down to long month names or PHP date formats, etc. I think with concrete options provided the users could easily figure it out (eg. for context, the filter can be a dropdown in Drupal 8, for location TYPE the list can be a dropdown).
Comment #21
swentel commentedSo the problem is that I'd need a method on StringStorageInterface, something like getDistinctContexts() but that isn't possible to add in patch, or even minor.
Catch suggested adding a public method to StringDatabaseStorage() which is a possibility, but not very neat. So the cleanest option seems to be adding a new interface in 8.1.x then ?
pasted log from IRC
Comment #22
jweowu commentedI'm not familiar with D8 but, regarding the use of drop-down lists for this, does comment #3 not still hold?
Not including the ability to filter on a partial context value would be contrary to my original intent.
If the widget facilitates both a pre-populated drop-list and an arbitrary textfield input, that could be nice. I haven't spent much time thinking about the best approach to including a select list, but if D8 uses something like https://harvesthq.github.io/chosen/ to make excessively-long select lists manageable, I could see that working reasonably well. Failing that, I'd guess some kind of auto-complete widget might be appropriate?
In fact, an auto-complete field which also allowed you to submit incomplete text might be a nice way to combine the two requirements? That way you could see which contexts you were matching, and either select a specific one, or submit as-is to match all of them.
(edit: which might be what ljcarnieri's comment #17 provides? I haven't tried that patch...)
Comment #23
swentel commentedRegarding #22: makes sense - I actually hadn't read the complete thread, sorry about that. One downside of a textfield is that users would have to know which contexts exists in the first place (however, I quickly checked and the filters already use LIKE, so it could do partial matching). The immediate plus of a textfield is also that it allows us to implement this without having to make any changes to the class interfaces and even include this in a patch release.
Autocomplete would be nice indeed, but that requires updates to the interfaces which would only be possible for 8.1.
@Gábor Hojtsy any preferences ?
Comment #24
swentel commentedPatch which uses a textfield for the widget, it actually works nicely.
Comment #25
jweowu commented+1 from me for implementing this approach for 8.0.x and perhaps aiming to enhance it with autocomplete abilities in 8.1.
Comment #26
gábor hojtsy@jweowu: what is your use case for partial contexts in Drupal 8? Drupal 8 does not have textgroups and does not identify webform or content type translations with contexts. I don't think its a problem that we use a dropdown.
Comment #27
jweowu commentedI'm using Drupal 7, so I have no specific use case for this in Drupal 8 at present; but is it not still possible for contrib/custom code to create arbitrary translation contexts in Drupal 8?
Comment #28
gábor hojtsy@jweowu: only shipped English strings are translated with locale now. What would modules use arbitrary translation contexts for then?
Comment #29
jweowu commentedI'm not certain I understand the changes, but if modules cannot dynamically generate contexts which are visible to this interface, that probably does eliminate the need for partial matching.
Maybe that doesn't change things in practice, though? A select-based approach evidentially isn't possible to add earlier than 8.1, so I would still suggest that a textfield-based solution will be an improvement for the 8.0.x series, as it still provides the missing functionality, even if the interface might be improved later on.
Continuing to use LIKE matching for the textfield version would probably still be a convenience for the end user, even if it's no longer a necessity to facilitate partial matches.
Comment #30
jweowu commentedFurthermore, with a 8.0.x commit, we can hopefully make the backport to 7.x in short order, as the 8.1-specific UI enhancements would be a separate issue. That would be a nice bonus.
Comment #31
gábor hojtsyI can see how the textfield is useful in Drupal 7, although it is far from discoverable. I don't see the benefits of a textfield over a select box in Drupal 8 honestly. How do people know what to put there?
Comment #32
jweowu commentedThe benefit of a textfield for this is that it can be implemented in Drupal 8.0, whereas a select list cannot (at least not in a reasonable way).
The options appear to be:
a) Implement as a textfield for 8.0; backport to 7.x; enhance with select list in 8.1.
b) 8.0 gets nothing; implement as a select list for 8.1; "backport" the textfield approach to 7.x.
I think (a) seems better than (b).
I can see the context named in the results shown in the screenshot in #24, so that seems like an obvious way for everyone. Other people will already know what they're looking for. I don't think the fact that some people won't know what to do with it should prevent the addition of a feature which other people will know what to do with, and which may prove very convenient to them?
Comment #33
gábor hojtsy@jweowu: I see you are advocating to add a cumbersome UI element, so we don't need to add something less than ideal on the API. I would value a better UI over a very elegant API.
Comment #34
jweowu commentedSure. I had thought the consensus was the necessary API change for 8.0 was untenable, but I don't have an opinion on it myself. If the select list UI is still an option for 8.0 then I have no issue with that.
Comment #35
kristen polI agree with #31 that a text field isn't particularly intuitive as a filter since many wouldn't know what to put there but a select list would be nice.
Comment #38
hargobindDowngrading to 7.x to include a new patch in the next comment.
Comment #39
hargobindSince there are probably a handful of folks like myself that are still supporting 7.x sites, I'm including a new patch which is essentially just an update of #17 by @ljcarnieri to be compatible with the latest 7.x branch (and applies cleanly to 7.53).
I understand that there was still some discussion about the best way to implement this in 8.x, but since I haven't migrated to that version yet, I can't provide any useful in that direction. However, the code added by @ljcarnieri in this patch has turned the Context field into an autocomplete field which seems to address the big question of "Does the average user know what location/context are." Perhaps others might agree that this approach is sufficient to move this issue forward in 8.x?
Comment #40
hargobindBumping back to 8.x
Comment #42
othermachines commented@hargobind - Thanks. I'm using the patch for 7.x so will be back to test. Do you maybe need to wait for the testbot before you switch back to 8.x? I have no idea.
Unrelated, but it's a bit more than a handful. :) https://www.drupal.org/project/usage/drupal
Comment #43
hargobind@othermachines - Yeah, I don't have much experience with the testbot, but it looks like the tests ran correctly against 7.x since that's what appears next to the test results, and even shows it on the test page for "DCI_CoreBranch". The failures don't seem to have anything to do with my code.
I appreciate you linking to the usage page, I haven't looked at it in a long time. Those stats make me feel better that I haven't yet had the time to adopt 8.x ;-)
Comment #44
othermachines commentedTested re-rolled D7 patch in #39 on a clean 7.53 installation and it applies cleanly and works as advertised. The autocomplete is a nice bonus. :) I've been hooking into the form to provide context "suggestions" in the field description, which is ugly and messy.
Be nice if we could get some work done on this for D8. (I'd offer, but I still have much to learn.)
Thanks, @hargobind.
Comment #46
reekris commentedReroll of the patch from #46 against 8.4.x
Comment #47
reekris commentedComment #49
merilainen commentedSeems to work, but should the OR operator be changed to AND? If I search for next and give a context, it doesn't really help me to find the string "next" in certain context.
Comment #52
jeroenbegyn commentedI agree with @mErilainen, it should use an AND condition and not the default OR condition.
I updated the patch to reflect this change.
Comment #53
kristen polThanks for the patch. An interdiff file would be nice :) I noticed a minor thing:
Needs space after "if".
Comment #54
kostyashupenkoComment #55
kostyashupenkoadded space after "if" and interdiff before #46 and current one
Comment #56
kristen polThe code appears to be ok but this needs testing. I'll see if I can do that soon.
Comment #57
kristen polThe context search is working with and without the string text. There was still discussion about using a select list instead of a text field though.
Comment #58
hargobindThis seems to satisfy "context". However, the idea of "location" was added to the discussion in #10 and #18. Can someone add that to the 8.x patch?
Comment #59
armandaslt commentedUpdated patch to choose context from a select list instead of a text field.

Comment #60
raphaeltbm commentedPatch for select list updated with contexts sort alphabetically.
Comment #61
nicrodgersComment #62
raphaeltbm commentedAn other one for the version with textfield, to avoid "Illegal mix of collations" when searching with accents in the context textfield. The context column in DB being in "varchar_ascii".
Comment #63
hargobindCould someone add a Location search to these patches? It doesn't seem like that would be too much work.
Comment #64
m_z commentedMaybe my post in #3104585: Add context filtering capabilities to the core translation interface is a duplicate of this issue, so I ask my questions here:
1. Does this issue also covers a "context" filter for the translation export (.po file generation)? In my opinion this would be a very important feature for multilingual websites with custom modules that use "context" for their translation strings.
2. Does this issue contains a "context" column in the translations backend overview (as you can see on the screenshot image of the contrib module https://www.drupal.org/project/locale_translation_context)? I think that this column is helpful to quickly find a context Name.
As far as I can see the contrib module https://www.drupal.org/project/locale_translation_context offers a working solution (that suffers on too much core code duplication) and that is why this should be a core feature (but the working code is available in the contrib module)… Am I wrong? Where is help needed?
Comment #67
mbovan commentedThank you all for the previous work!
Here is the updated patch and interdiff against #60 since our client perfers the "Context" filter as a dropdown menu.
I made the following updates:
Comment #68
mbovan commentedHere is Drupal 8.9.x-friendly patch that fixes condition object initialization.
Comment #69
mbovan commentedAs per #52, the default condition should be
AND.Comment #71
damienmckennaRerolled. This applies cleanly against 9.2.x and 9.3.x.
Comment #74
andrerb commentedRerolled. This applies cleanly against 9.4.x.
Comment #77
m_z commented@AndreRB: I didn't tested your patch #74, but I reviewed the code and it looks promising. Thank you for your work. Maybe someone else can test the patch to move status to RTBC...
Comment #78
kgaut commented#74 is fine for me to !
Comment #79
leksat commentedRe-rolled #74 on 10.0.x
Comment #80
leksat commentedComment #81
hargobindReadding the D7 patch that was hidden by @Lekstat
@Lekstat why did you hide your own patch in #79?
Comment #82
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
The issue summary could be updated to show what the proposed solution is? Remaing tasks, etc.
Also will need test coverage to ensure it doesn't break.
Comment #83
jheinon_finland commentedI had some issues in #74 on the project for which I'm working on. The code section where all the available string translation contexts are fetched in the function
translateFilters()didn't apply.This is an updated version of the patch where the said code segment is placed between the
filtersarray and language fetching sans English.Comment #84
phonoman commented#83 seems to have some linting errors, please adjust those so that the tests can pass :)
Comment #85
jheinon_finland commentedAll right, as stated in #84, these should be fixed with the version provided in this comment, #85.
Comment #86
martijn de wit@jheinon_finland Drupal core issues are fixed in development versions. So please don't move versions down.
Current development versions is 10.1.x. Maybe the patch can be applied to previous versions and back-ported if needed but that's up to the core maintainers.
Can you upload a diff in the same comment? So people can see what you changed?
Comment #87
smustgrave commentedIssue summary still needs updating.
Tests are still needed.
And yes interdiffs need to be uploaded for #83 and #85
Comment #88
jheinon_finland commentedIn this, I will upload the interdiff between versions
#83and#85. To answer#86, it appears it's not possible to edit an old comment and provide a file with it, so I will be uploading the interdiff file in this comment.Comment #89
smustgrave commentedper #87
Comment #97
parisekUpdated MR to support Drupal 10, unfortunately couldn't rebase
Comment #99
bbu23Rebased MR 4174.
Comment #100
candelas commentedIs there any patch for 10.2.1 ?
Thanks
Comment #102
sascha_meissner+1 This would be sooo useful, using this patch in many projects.
Rebased 4174 with current 11.x so it is mergeable again, but somehow messed up, the changes are correct but it shouldn´t show the ~1800 commits ... i´ll fix this now
Comment #103
sascha_meissnerAdded a little context-filter testing to testStringSearch of LocaleTranslationUiTest
Still not sure if i messed up the MR, but it says 2 commits will be added when merged into 11.x so i think its principally correct, i´ll leave it like this for now
Comment #104
sascha_meissnerComment #105
lisotton commentedIn my project, we had a Drupal 10.3 installation pointing to the patch of the MR, but with the rebase of the MR, the MR is not applicable anymore in Drupal 10.3.
So for those looking for a patch that work with Drupal 10.3, I'm attaching one to the issue.
Comment #106
smustgrave commentedIssue summary still appears to need to be updated.
also MR is showing 1000s
Comment #108
codebymikey commentedAlso worth checking if this could be consolidated into #1853534: Reintroduce Views integration for locale.module since it makes integration a whole lot easier.
Comment #109
penyaskitoThis will even more relevant when #3493070: SDC `enum` props should have translatable labels: use `meta:enum` is supported, as the context strings usage will likely increment a lot once SDC components can be translated.
Comment #110
baikho commentedUsing patch from #105, works as expected on:
Drupal Core 11.1.7
PHP v8.3
Comment #111
bbu23Idk what happened, but the MR had more than 1900 commits and 1000+ changes 🙈
For now I fixed the branch against 11.x while keeping the original 5 pending commits as they were.
Comment #112
bbu23Comment #113
smustgrave commentedFor the summary update.
Comment #114
bbu23Updated the issue summary.
Keeping the status in "Needs work" since it seems that the MR doesn't yet include the "filter by location" functionality.
Comment #115
bbu23Comment #116
bbu23Comment #117
bbu23I added the location filter solution proposed in earlier comments, though idk how I feel about the large amount of select options it can have, and the size of the filter.
Comment #119
smustgrave commentedAppears to need a rebase. Also the API change will need a change record please.
Comment #120
bbu23Rebased with latest code in
mainbranch.Added draft change record.
Comment #121
bbu23Hi @smustgrave, anything else needed?
Comment #122
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.