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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan created an issue. See original summary.

Sutharsan’s picture

james.williams’s picture

@Sutharsan sorry, where would a group's label be translated then, with this change?

Sutharsan’s picture

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

james.williams’s picture

Right, 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.

rodrigoaguilera’s picture

Version: 8.x-1.x-dev » 8.x-3.x-dev
Status: Active » Needs review
FileSize
3.66 KB

I 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

label:
      type: string
      label: 'Label of the fieldgroup'

it will read

label:
      type: label
      label: 'Label of the fieldgroup'

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

RobertoGuzman’s picture

Hi, 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

rodrigoaguilera’s picture

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

holist’s picture

Removing 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 and translatable: 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. :)

holist’s picture

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

zero2one’s picture

Re-roll of the patch against the latest dev branch commit (9ab1b99).

zero2one’s picture

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

Sutharsan’s picture

Status: Needs review » Needs work

The solution looks solid to me. One remark:

+++ b/config/schema/field_group.entity_display.schema.yml
@@ -12,8 +12,9 @@ core.entity_view_display.*.*.*.third_party.field_group:
+          translatable: true
         parent_name:

This is not needed in this schema. 'type: label' _is_ translatable.

james.williams’s picture

This 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

Sutharsan’s picture

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
7.74 KB
5.94 KB

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

sonnykt’s picture

Status: Needs review » Reviewed & tested by the community

Patch #16 works for me.

DuaelFr’s picture

Patch looks good.
It would be nice to find a way to build an UI for translating these items but it looks quite complicated.

DuaelFr’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
5.92 KB

Here 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

johnchque’s picture

Anybody’s picture

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

johnchque’s picture

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

TwoD’s picture

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

TwoD’s picture

TwoD’s picture

Well that was bad, left a ) in 'Fieldset.php'....

Sutharsan’s picture

Status: Needs review » Reviewed & tested by the community

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

globexplorer’s picture

Applied patch 21 but field group lables still not translateable!

globexplorer’s picture

Field group labels not translateable via UI.

dercheffe’s picture

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

swentel’s picture

Status: Reviewed & tested by the community » Fixed

committed and pushed, thanks all!

Anybody’s picture

Great news finally, thank you so much @swentel!!! :)

Anybody’s picture

PS: 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.

  • swentel committed 11d33b3 on 8.x-3.x authored by TwoD
    Issue #2846617 by Sutharsan, TwoD, zero2one, holist, DuaelFr, yongt9412...
swentel’s picture

Ah crap, forgot to push, sorry :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ReneW’s picture

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

abia08’s picture

Translation was still not working and I believe that it was missing t()
https://www.drupal.org/project/field_group/issues/3111107

globexplorer’s picture

It's config and should never got translated trough t(). That would trigger a lot of strange side effects on multi lang sites.