0

I have a module that lets site editors enter plain text title and description for a sitewide element. This site supports several languages - how can I enable entering values for each enabled language?

I see documentation here:

https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemametadata#intro

Do I simply update my schema for a langcode and add a language selector on the configuration form?

enter image description here

1 Answer 1

2

No, you don't need to add anything to the config form. Once you have created the schema and cleared the cache the translation form is built automatically (if the Configuration Translation module is enabled) and you can access it via the Translate tab. It looks by the way completely different than the original form and contains only values which are translatable according to the schema.

As @Kevin commented Drupal expects more, to be able to connect the translation tab to a base route. For simple configuration, as in this case, define a mymodule.config_translation.yml file.

Example for /admin/config/system/site-information:

system.config_translation.yml

system.site_information_settings:
  title: 'System information'
  base_route_name: system.site_information_settings
  names:
    - system.site

And a tab, so that the tabs are displayed when the second translation tab is generated:

system.links.task.yml

system.site_information_settings_tab:
  route_name: system.site_information_settings
  title: Settings
  base_route: system.site_information_settings
6
  • I am not seeing a translate tab, do I have to add anything to my router or menu link file?
    – Kevin
    Feb 17, 2022 at 16:46
  • Is the core module enabled? I've edited the answer.
    – 4uk4
    Feb 17, 2022 at 16:46
  • I just enabled it and see new areas in the admin, but no translate tab and the name of the module is not listed with the others under Configuration Translation
    – Kevin
    Feb 17, 2022 at 16:49
  • Hang on - I think my mistake was using config_object and not a config_entity.
    – Kevin
    Feb 17, 2022 at 16:59
  • OK, for simple configuration you need to define the route in a yaml file in contrast to config entities where you do this in the entity definition. I add an example to the answer.
    – 4uk4
    Feb 17, 2022 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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