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.
Problem/Motivation
Field Group uses a Drupal 7 approach to making the field group label translatable. In a single language (non-English) site, a field label such as 'Contact' gets be translated. 'Contact' is a translated string from Core.
Proposed resolution
As long as the field labels are not translatable via Configuration translation (#2663352: Wrong place for translating field groups), I propose to remove translation of the labels. This is the preferred solution for a single language site.
This is a different approach than #2822299: Double-escaped HTML entities in group titles, which does not solve the problem above.
Comments
Comment #2
Sutharsan CreditAttribution: Sutharsan commentedComment #3
james.williams CreditAttribution: james.williams at ComputerMinds commented@Sutharsan sorry, where would a group's label be translated then, with this change?
Comment #4
Sutharsan CreditAttribution: Sutharsan commentedIt will _not_ be translated. That's why I wrote "I propose to remove translation of the labels". A single language site does not need translation of labels. You can enter them in the language you want, no need for translation.
Comment #5
james.williams CreditAttribution: james.williams at ComputerMinds commentedRight, well, that's a separate issue to dealing with double-escaped HTML in group titles so I'm going to re-open and re-direct that issue.
Comment #6
rodrigoaguileraI did a rebase against 8.x-3.x that seems to be in active development although it seems to me like a bug since is polluting the database with non-English strings since my site default language is not English.
After this change for translating the labels I think a schema change is needed:
In the field_group.field_group_formatter_plugin.base schema definition the type of the label is "string" and I think is should be "label" to make it translatable. Can someone confirm this?
So instead of
it will read
Lots of "label" there :)
And probably other translatable properties need to change from "string" to "label" or "text" if it is multiline according to
https://www.drupal.org/docs/8/api/configuration-api/configuration-schema...
Comment #7
RobertoGuzman CreditAttribution: RobertoGuzman commentedHi, i applied the last patch field_group-no-label-translation-2846617-6.patch, but i do not find where or how to translate the field group i have created
Comment #8
rodrigoaguileraField groups are inside Entity view displays and those are translatable. Altought there is no interface for it
#2546212: Entity view/form mode formatter/widget settings have no translation UI
But I think we have to change the schema so the labels are translatable.
Comment #9
holist CreditAttribution: holist at Siili Solutions commentedRemoving the
t()
is also a good idea for multilingual sites that have other default language than English. Gets very confusing.@rodrigoaguilera yes, to my understanding too changing schema so that there is
type: label
andtranslatable: true
should do it. And an update hook that will update the schema when module is already installed.Creating the translation Yaml files is fairly simple for anyone who's not afraid of text files. :)
Comment #10
holist CreditAttribution: holist at Siili Solutions commentedWell it wasn't that complicated, writing an update hook seems not to be necessary in this case. I attached a patch that changes the config schema to support reading translations if they are manually created in
config/sync/[langcode]/core.entity_view_display.node.[bundle].[view_mode].yml
.Also attached is a version of the patch for 8.x-1.0, as I didn't want to move to beta version on the production site I need this for, someone else might want to use that too.
Comment #11
zero2one CreditAttribution: zero2one at Serial Graphics for District09 commentedRe-roll of the patch against the latest dev branch commit (9ab1b99).
Comment #12
zero2one CreditAttribution: zero2one at Serial Graphics for District09 commentedTesting out the new patch a hit a new issue: the output is double escaped:
* Once in code
Html::escape()
* And automatically by twig when the variables are printed
{{ label }}
(see https://www.drupal.org/node/2296163)I updated the patch and removed the need to
Html::escape()
in the formatters and alters.Comment #13
Sutharsan CreditAttribution: Sutharsan commentedThe solution looks solid to me. One remark:
This is not needed in this schema. 'type: label' _is_ translatable.
Comment #14
james.williams CreditAttribution: james.williams at ComputerMinds commentedThis will also conflict with #2822299: Double-escaped HTML entities in group titles, which is already RTBC. The latest patch has also taken this issue in a new direction... but a good one. Personally, I'd suggest the latest patch here does the correct things, for both translation and HTML. Because of that, I'm going to close that other issue, even though it reached RTBC. People may not be happy with that, but that one was always aiming for a temporary workaround anyway, I believe (see comment #2822299-18).
Having said that, I haven't actually tested, I'm just reviewing the approach taken by the latest patch(es).
So, remaining steps here:
1) Address comment 13
2) Test & review
Comment #15
Sutharsan CreditAttribution: Sutharsan commentedRe-rolled #12
Comment #16
Sutharsan CreditAttribution: Sutharsan commentedI went through the schema and converted "type: text" to "type: label" for each translatable string. Also removed "translatable: true" as this is no needed when 'label' is used.
I tested the translation and it works. I tested it by creating a language override configuration file and imported it. Then the translated labels show up.
I did not find a way to translate the labels via the interface. I did not find a module that uses third_party_settings with translatable configuration which can be used as example.
Comment #17
sonnyktPatch #16 works for me.
Comment #18
DuaelFrPatch looks good.
It would be nice to find a way to build an UI for translating these items but it looks quite complicated.
Comment #19
DuaelFrHere is the updated patch for the 8.x-3.x branch
This patch conflicts with the one in #2878359: Field groups are not compatible with field layout so it's going to need a reroll soon
Comment #20
james.williams CreditAttribution: james.williams at ComputerMinds commentedComment #21
johnchqueRebasing this, we found this problem when working on #2546212: Entity view/form mode formatter/widget settings have no translation UI.
Comment #22
AnybodyThe patch in #21 looks good. Do we need an interdiff to #19 or simply review #21 now?
Is the patch from #2546212: Entity view/form mode formatter/widget settings have no translation UI required for this to work?
Comment #23
johnchqueCannot provide an interdiff since it is the same patch as #19 just rebased.
No need of the patch of the related issued. Just wanted to clarify how I ended up in this issue. :)
The patch should be ready for review.
Comment #24
TwoD#21 works great for me together with #2577761-73: We need a way to dynamically alter the list of config names for config mappers and #2546212-89: Entity view/form mode formatter/widget settings have no translation UI added to a Drupal 8.5.6 site.
The patch looks great, but I haven't checked if there are any strings left to change to labels.
Comment #25
TwoDRe-rolled and changed tabs description to
label
as well. Possibly it should betext
?Comment #26
TwoDWell that was bad, left a
)
in 'Fieldset.php'....Comment #27
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commentedSeveral people have now looked a the solution and confirm that it fixes the problem.
Since tests are broken, that can not be verified now. But in #21 the tests did passed.
Comment #28
globexplorer CreditAttribution: globexplorer commentedApplied patch 21 but field group lables still not translateable!
Comment #29
globexplorer CreditAttribution: globexplorer commentedField group labels not translateable via UI.
Comment #30
dercheffeOkay so field group isn't translatable at the moment generally? I'm asking, because I'm creating a multi language currently.
IMHO it's better to translate elements via string translation, when there's no other implemented solution available. Is there a way, where I can translate my field labels?
Comment #31
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedcommitted and pushed, thanks all!
Comment #32
AnybodyGreat news finally, thank you so much @swentel!!! :)
Comment #33
AnybodyPS: No commit message here yet? Have you perhaps forgotten to mention this in the commit message? Or not yet pushed? - Just to ensure this was truely committed.
Comment #35
swentel CreditAttribution: swentel at eps & kaas for Dropsolid commentedAh crap, forgot to push, sorry :)
Comment #37
ReneW CreditAttribution: ReneW commentedI'm using Field Group for the account form display (admin/config/people/accounts/form-display), but translation for the label doesn't seem to work. Can anyone confirm this?
Comment #38
abia08 CreditAttribution: abia08 commentedTranslation was still not working and I believe that it was missing t()
https://www.drupal.org/project/field_group/issues/3111107
Comment #39
globexplorer CreditAttribution: globexplorer commentedIt's config and should never got translated trough t(). That would trigger a lot of strange side effects on multi lang sites.