Webform rendering should use the content language, not interface

Created on 7 October 2020, about 4 years ago
Updated 23 August 2024, 3 months ago

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

  1. On a multilingual site, set the interface language detection to "Selected language", set the content language detection to "URL and selected language".
  2. Translate a webform
  3. View the webform in a language other than the interface language, the elements will render in the interface language. (Translation not rendering)
  4. Set the interface language detection to "URL" & "Selected language"
  5. 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.

📌 Task
Status

Needs work

Version

6.2

Component

Code

Created by

🇳🇿New Zealand danielveza Brisbane, AU

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The 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

  • Status changed to Needs work over 1 year ago
  • Updated forms settings and schema for tests to pass.
    Next step is to add a test for this new functionality.

  • 🇩🇪Germany droprocker

    I 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):

    • Use global setting - Default
    • Use Interface language
    • Use content language
  • Hi @droprocker,

    Thank you for your feedback.

    The patch follows the general implementation of webform config/settings.

    Referring to

    When the global setting is set to content language, the webform-specific setting should be disabled.

    In fact, this is the case as shown in #20 📌 Webform rendering should use the content language, not interface Needs review , you have the following options:

    • If you have multiple webforms and you need all of them to use the interface language, you can just keep both checkboxes unchecked (global and webform-specific).
    • If you have multiple webforms and you need all of them to use the content language, you will need to check the global checkbox and as a result, the checkbox inside each webform-specific settings will be disabled.
    • If you have multiple webforms and you need only some of them to use the content language instead of the interface language, then you will need to keep the checkbox in the global settings unchecked, and check the checkboxes for the webforms you desire to render in the content language inside the settings of each of them.

    Since the implementation of the current patch covers all use cases, I don't think there is a need for what you suggested lastly:

    Or to have a third option in the webform-specific setting like this (which I prefer):

    • Use global setting - Default
    • Use Interface language
    • Use content language

    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.

  • Added compatibility with 6.2.0-rc2 version.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    536 pass
  • 🇩🇪Germany Anybody Porta Westfalica

    @Zulljin could you perhaps prepare this as MR?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    536 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    536 pass
  • 🇬🇷Greece gbotis

    Thank 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?

  • 🇨🇦Canada joelseguin Ontario, Canada

    1) 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.

  • 🇨🇦Canada joelseguin Ontario, Canada

    I'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:

    • Interface text language detection: Session enabled
    • Contenu language detection: Session enabled

    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).

  • 🇩🇪Germany Anybody Porta Westfalica

    #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.

  • zulljin changed the visibility of the branch 3175374-webform-rendering-should to hidden.

  • Merge request !510Resolve #3175374 "Webform rendering" → (Open) created by zulljin
  • Pipeline finished with Failed
    3 months ago
    Total: 3494s
    #262161
  • Status changed to Needs work 3 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @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.

Production build 0.71.5 2024