0

I have two field sets

Fieldsets

In the admin/config/regional/translate I have translated the "Account settings" label accountsettingstranslation

But in the Form display I still have the english label: formdisplay What can I do to translate the field group labels?

3 Answers 3

1

Field groups are configurations which are not translated via the translation interface. I am quite sure that the string "Account settings" that is translated in your project does not come from your field group. Just change the label of a field group to any other string - you will not find the string in the translation interface.

You need to activate the "Configuration Translation" module.

3
  • Yes, this is configuration, but unfortunately the UI to translate formatter/widgets is not ready yet. See drupal.org/project/field_group/issues/3114825
    – 4uk4
    Sep 15, 2020 at 8:18
  • Yes, indeed @4k4 , I found the same issues and so far I cannot find the string to translate it. One patch I found drupal.org/files/issues/2020-07-10/… and applied it to the module, lets me output it as HTML, could this be resolved somewhere as a translation?
    – NeonBlank
    Sep 17, 2020 at 15:14
  • 1
    You need to install the core modul mentioned in the answer and then patch this module with drupal.org/project/drupal/issues/2546212#comment-13451232. After that your field group formatter/widget configuration should look like the screenshot you see in the issue I've linked.
    – 4uk4
    Sep 17, 2020 at 15:23
1

https://www.drupal.org/files/issues/2020-02-05/2546212-119.patch - Did the trick for me. It adds a "Translate form display" tab, like it is shown below.

enter image description here

0

I was able to sort of work around this with theming. In my situation I am unable to use the patch so this is what I did. I created a theme suggestion that includes my "bundle" and "group name" so I can override the fieldset.html.twig templates for the specific field groups I want to translate.

In my themes .theme file:

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function THEMENAME_theme_suggestions_fieldset_alter(array &$suggestions, array $variables, $hook) {
  $element = $variables['element'];
  $group_name = $element['#group_name'];
  $bundle = $element['#bundle'];
  if (!empty($group_name) && !empty($bundle)) {
  $suggestions[] = 'fieldset__' . strtr($bundle, '-', '_') . '__' . strtr($group_name, '-', '_');
  }
}

Now I can add a template for each of my content types field groups using fieldset--CONTENT-TYPE--GROUP-NAME.html.twig.

At this point I can copy the fieldset.html.twig code into my template and replace the legend with a translatable string.

<legend{{ legend.attributes }}>
  <span{{ legend_span.attributes.addClass(legend_span_classes) }}>{{ 'Translatable Text Using User Interface Translation'|trans }}</span>
</legend>

Make sure you visit your page in the language you want to translate before searching for your string in the User Interface Translation UI. It won't find your string until you do.

Bam! Easy, narrowly scoped work around until field groups gets the patch into a release.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.