Problem/Motivation
We have a site that uses English as the Interface language, for the editorial team. We are in the process of translating webforms, but it seems the webform renderer uses the INTERFACE language rather than the CONTENT language when rendering it's elements.
IMO this is the wrong approach, a webform feels like it's content rather than part of the interface. I've had the same issue with Block titles and had to make a workaround so that the correct title renders.
However I can imagine this is a breaking change, and a difficult one to judge how much this would effect other sites with existing webforms.
Maybe the better option is to provide a checkbox on the form settings, "Use content language" or something that is opt in.
Steps to reproduce
- On a multilingual site, set the interface language detection to "Selected language", set the content language detection to "URL and selected language".
- Translate a webform
- View the webform in a language other than the interface language, the elements will render in the interface language. (Translation not rendering)
- Set the interface language detection to "URL" & "Selected language"
- View the webform in a language other than the interface language, the elements will render in the interface language. (Translation rendering)
Proposed resolution
Either:
- Change Webform rendering to use the content language
- Add checkbox to allow of content language rendering.
Remaining tasks
Depends on approach.
User interface changes
Depends on approach.
API changes
Depends on approach.
Data model changes
Depends on approach.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | working-configuration-example.png | 176.87 KB | joelseguin |
| #26 | 3175374-23.patch | 225.75 KB | zulljin |
| #22 | 3175374-22.patch | 225.65 KB | redwan jamous |
| #20 | Screenshot from 2023-03-09 01-11-27.png | 29.28 KB | redwan jamous |
| #20 | Screenshot from 2023-03-09 01-10-56.png | 16.94 KB | redwan jamous |
Issue fork webform-3175374
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jrockowitz commentedI think most people are expecting or are used to a Webform using interface language translation.
I could see us implementing "Add checkbox to allow of content language rendering."
A few thoughts...
I am not exactly sure who we would go about implementing content language rendering for a webform. If you could provide some sample code it would help me understand the complexity of the solution.
Comment #3
danielvezaI agree with this, I also think this is the safest approach.
I'll get started on a sandbox today.
I don't have any sample code yet for this, I've only started to build the forms and translations in the UI. I seem to be running into a few places were my and Drupals expectations clash. I wonder if I'm not understanding something correctly. It makes sense to me to keep the interface language static, and the content language dynamic.
Comment #4
jrockowitz commentedI think interface and content translation should use the same detection method because content may be rendered with interface translations like the label for a "back to top" link in a TOC.
Comment #5
danielvezaI'm going to take a step back on this I think.
I considered making a WebformHandler that handles the rendering of the translated elements, but considering I've run into issue with Blocks & webforms, who knows how many other things may pop up. I think my approach just fundamentally doesn't match Drupals.
So I was going to make an administrator language negotiator, and found this. https://www.drupal.org/project/administration_language_negotiation
I'll leave this up to @jrockowitz if he wants to close this issue or experiment further with the checkbox idea.
Comment #6
jrockowitz commentedI think this should be handled in a dedicated contrib module or custom code
Comment #7
florianboehmeAny news here? Is there any module or tip for custom code which handle this?
Comment #8
google01 commentedDo we still have no options for webform to show the content language and not the interface language?
Comment #9
anybody@jrockowitz are you open to discuss reopening this? (see below)
I think you closed this as you didn't experience this issue yet, and it wasn't described well, why the form should be displayed in content language (user selected language) and not in interface language?
Let me try to explain why I think this is important for multilanguage sites and should not be contrib or custom code:
Why separate languages?
Having a multilang site, for example being a company in Germany with website translated to English and Czech, you typically want:
So you split interface (administration ui) from content language (frontend). See the screenshot below for a typical best-practise configuration to have admin language (interface) split from content language (visitor language selector / URL):

Why should webform use content language (in the form display)?
Webform currently seems to only use interface language, which is correct for administrative pages, but not the form displayed to users. This leads to a combination where all texts on the page are displayed in content language but the form is displayed in interface language.
This is simply wrong and not a special case. So for the webform rendering the content language variable should be used. Anyway, if content language special handling switch (see screenshot) is off, both are the same and the variable falls back to the interface language.
Hope my explanation can be understood? Otherwise, please let me know for further explanations :)
Comment #10
jrockowitz commentedI understand the explanation. I am not seeing how we can support the content's language. I could use some guidance.
I am fine with reopening this ticket but I might not have the bandwidth to commit a patch that does not include test coverage and a significant amount of code review.
Comment #11
anybodyHey @jrockowitz,
thank you very much for your super-fast reply! I think we should perhaps have some others have a look at this and wait for further feedback. I'd like to be sure that I understood and configured everything correctly before we start coding here.
If you should have any ideas how this could be solved or where the relevant language variables are set in webform code, please leave your notes. I'll to the same. Also if you should talk to anyone who's more experienced with these separated language options, perhaps he could have a look. Thanks a lot! :)
Comment #12
jfeltkampThis can be managed with the language manager.
Whenever a webform is rendered, the current language must be retrieved beforehand. This is also done in Webforms with the LanguageManager. I suspect, the only thing that is required, is that the parameter must be entered everywhere in the getCurrentLanguage function.
I know Webforms is very complex and maybe my guess is naive.
Comment #13
anybodyThank you very very much for your help @JFeltkamp! @jrockowitz as you might know the points where the language is fetched - what do you think about that change for the end-user display of the form? Possible?
Comment #14
liquidcms commented@Anybody, re: #9 - OMG YES!! You have no idea how much trouble i have explaining to people on Drupal what "content" is. My clients on the other hand, all, 100% agree that typical users should see everything as content.
My site is almost perfectly set this way where basically users (anon or auth) see that site in the content language based on the url prefix and editors/admins can set interface language in their profile so that they can work on the site without having to know 5 different languages.
I use the code similar to what is mentioned in #13 for handling block config elements that should be seen as content - combined with setting $language_manager->setConfigOverrideLanguage($language); Views is the one bright spot in Drupal core that lets you handle most things as required by simply setting render language as required. The tranc module also helps things a lot.
All that being said, i have now hit the webform blocker for this. Has this issue gone anywhere? It is listed as Needs Work; but has no patches.. so i think that means Active. Was someone going to look at adding option and then using that in webform's LanguageManager as mentioned in #12?
Comment #15
anybodyThank you for your feedback @liquidcms! Totally agree. Same for us... still a technical solution has to be found here, correct.
Comment #16
liquidcms commentedI assumed no one is looking at this anymore so i took a look last night at the code. Didn't see obvious place where language is being set. Likely will get back to this within next 2 weeks to come up with a solution (assuming someone doesn't beat me to it).
Right now it looks like as Anon, no translation is done at all (not even using Interface language, which, as Anon is the same as Content language). But different issue.
Comment #17
google01 commentedThe error persists, always showing the language of the interface instead of the language of the content
All the calls in the various module files are:
languageManager->getCurrentLanguage()
instead of:
getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
where the language of the content is specified.
Comment #18
cilefen commentedComment #19
justclint commentedIve been trying to resolve this with form process and since our editors add webforms via paragraphs Ive even tried to see if I could get the translated webform from a paragraph preprocess but no luck. Cant find any methods that allow to set language on the webform either.
This is a pain point our editors and translators have been having since they can not accurately review translated pages with webforms in them before publishing. When user is logged in all content on page is in the page language except the form.
Currently the pages have to get published and a translation reviewer has to be logged out so they can review the full page in expected language.
Im at a road block on how to proceed resolving this but just wanted to chime in and follow this issue.
Comment #20
redwan jamous commentedThe attached patch adds a new checkbox to both the global configuration and the webform entity settings form under a new group called "Multilingual".
This adds the ability to force all webforms to be rendered using the content language, or to select specific webforms to be rendered using the content language.
This is an old issue and I really hope this gets merged soon.
Webform entity settings

Global configuration

Comment #22
redwan jamous commentedUpdated forms settings and schema for tests to pass.
Next step is to add a test for this new functionality.
Comment #23
droprocker commentedI applied the patch to V6.1.x by removing all the hunks for test files.
Generally speaking, this patch works like charm! Thanks for the work. :-) I have some improvements, since the functionality can be confusing.
I think it's not clear enough that the global settings overrides all webform-specific settings. This could be improved. When the global setting is set to content language, the webform-specific setting should be disabled. Otherwise I would expect, that the specific setting overrides the global config.
Or to have a third option in the webform-specific setting like this (which I prefer):
Comment #24
redwan jamous commentedHi @droprocker,
Thank you for your feedback.
The patch follows the general implementation of webform config/settings.
Referring to
In fact, this is the case as shown in #20, you have the following options:
Since the implementation of the current patch covers all use cases, I don't think there is a need for what you suggested lastly:
Plus, going with such suggestion will create an inconsistency in the UX since other settings work exactly this way (the way that the current patch is implemented).
On a side note, neither the webform-specific checkbox nor the global checkbox will be available unless the site is multilingual.
Comment #25
redwan jamous commentedComment #26
zulljin commentedAdded compatibility with 6.2.0-rc2 version.
Comment #27
zulljin commentedComment #28
anybody@Zulljin could you perhaps prepare this as MR?
Comment #29
gbotis commentedThank you very much! #26 applies perfectly and resolves the issue rendering the form using content language (in my case url).
I still have issue with confimrations emails. The form values are translated but the subject/body and other fields are still using default language. Has anybody else encountered the same issue?
Comment #30
joelseguin1) Thanks! I can confirm that the latest patch from #26 (3175374-23.patch) works against Webform version 6.2.
I came across this issue after a bit of searching as I couldn't quite figure out why my webforms' translations were not getting applied. There is definitely a need for translation based on content as I would've had to take a different approach for translating our site. My use case is that only certain content types from our native French website are offered in English. The rest of the site, we simply offer Google translation.
2) As per @gbotis, I've noticed the same issue with the patch where specifically the subject, the body and the confirmation message cannot be translated. Happy to test out any future patches.
Comment #31
joelseguinI'd like to offer up an solution that seems to have worked nicely for my use case without the need for a patch. Perhaps this will work for others.
No issues with content translation with Webform when using the following language and detection configuration:
Previously I did not have an option enabled for "Interface text language selection" and only had "Content language" enabled for "Content language detection". Now, with both having "Session" enabled, everything works as expected and cleaner URLs (?language=en vs using ?language_content_entity=en and does not get added to the default site language).
Comment #32
anybody#31 isn't a real solution. If webforms are used as content and content and interface language differ (for example interface language English for Chinese content language), the webform will display in English while Chinese is expected.
This is by design and can only be fixed in code by adding a setting or sth. like that as proposed.
The patch still needs to be turned into a MR for review.
Comment #37
zulljin commented@anybody, MR is ready: https://git.drupalcode.org/project/webform/-/merge_requests/510
Comment #38
anybodyThanks @zulljin that looks like a good first step. I left a comment and tests are failing that need to be fixed. Also tests for the new functionality need to be added.
Comment #39
anybodyMaybe insted of the checkbox we should be more clear here and use a select for
selection?
Comment #40
liam morland