2

Theme settings are not translatable in core. Is there a way to make them translatable? I have some additional theme settings which needs to have different values per language.

I'm trying to achieve something like this - How do I translate theme settings?

What I have so far -

mytheme/config/schema/mytheme.schema.yml

mytheme.settings:
  type: theme_settings
  label: 'My theme settings'
  mapping:
    custom_textarea:
      type: text_format
      label: 'Additional settings'

mytheme/config/install/mytheme.settings.yml

custom_textarea:
  value: "<p><sup>*</sup>this is an additional settings.</p>\r\n"
  format: full_html
langcode: en

mytheme/mytheme.config_translation.yml

mytheme.settings:
  title: 'my theme settings'
  base_route_name: system.theme_settings
  names:
    - mytheme.settings

theme-settings.php

/**
 * Implements hook_form_system_theme_settings_alter().
 *
 * Form override for theme settings.
 */
function mytheme_form_system_theme_settings_alter(array &$form, FormStateInterface $form_state) {


  $custom_textarea = theme_get_setting('custom_textarea');
  $form['custom_textarea'] = [
    '#type'          => 'text_format',
    '#title'         => t('custom textarea'),
    '#format'        => 'full_html',
    '#default_value' => $custom_textarea['value'],
  ];


}

When I navigate to admin/config/regional/config-translation it shows the 'my theme settings' but when I click on Translate it navigates to admin/appearance/settings/translate and returns Access Denied.

I also tried updating the base_route_name in mytheme.config_translation.yml to system.theme_settings_theme but when I navigage to admin/appearance/settings/mytheme/translate it throws a fatal error.

Looking forward for any suggestions.

2
  • Do you use different domains per language? Are you being redirected to a different domain where you haven't logged in yet?
    – leymannx
    Jul 19, 2019 at 17:32
  • All the languages are in a single domain. It's not multi site or multi domain.
    – wilNev
    Jul 20, 2019 at 12:05

1 Answer 1

3

in schema change field type to text and add translatable: true

mytheme.settings:
  type: theme_settings
  label: 'My theme settings'
  mapping:
    custom_textarea:
      type: text
      label: 'Additional settings'
      translatable: true

You may also face this problem later https://www.drupal.org/project/drupal/issues/2719553 (my reply there is the last from current date)

2
  • Doesn't seem to work even after reinstalling the theme, are there any additional steps? Where should the translation interface appear?
    – int_ua
    Oct 8, 2020 at 17:03
  • Can't remember where it should appear, was too long ago. Take a look into link above, may be it brings you ideas. As I remember all was fine in the end of those my project Oct 9, 2020 at 19:25

Your Answer

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

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