7

How do you translate custom theme settings in Drupal 8?

I use hook_form_system_theme_settings_alter to add custom settings to a theme. One setting is the text string (e.g. 'Menu') to display beside the menu icon for a responsive menu. How can I integrate with the configuration translation system to allow the text to be translated?

All of the examples I have found describe how to translate a custom module's settings. I have not found any examples about how to translate a themes's settings, but there are a few hints in the Drupal code base that suggest it should be possible to create a THEME.config_translation.yml file.

I have taken a lead from this article on Gábor Hojtsy's blog and created the following files:

  • config/install/mytheme.settings.yml
  • config/schema/mytheme.schema.yml
  • mytheme.config_translation.yml

The schema is valid (tested using Configuration Inspector) and I have managed to get a Translate button for my theme's settings to show up on the Configuration translation admin page (admin/config/regional/config-translation). That's as far as I've got.

I don't know what to use for base_route_name in mytheme.config_translation.yml. Here's what I have:

mytheme.settings:
  title: 'My Theme Settings'
  base_route_name: system.theme_settings

For base_route_name I used system.theme_settings which results in a Translate button that links to /admin/appearance/settings/translate, but clicking on it leads to an Access denied, I assume because there is no translate page for theme settings. Also, I think the base_route_name should be system.theme_settings_theme and the Translate button should map to /admin/appearance/settings/mytheme/translate, but I get an error when I try that.

Am I on the right track? How would I go about creating a /admin/appearance/settings/mytheme/translate page and integrate it with the config translation system?

protected by kiamlaluno Apr 20 '18 at 6:51

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Browse other questions tagged or ask your own question.