Score:0

Allow module configuration per language

in flag

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

Score:2
cn flag

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
Kevin avatar
in flag
I am not seeing a translate tab, do I have to add anything to my router or menu link file?
4uk4 avatar
cn flag
Is the core module enabled? I've edited the answer.
Kevin avatar
in flag
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 avatar
in flag
Hang on - I think my mistake was using config_object and not a config_entity.
4uk4 avatar
cn flag
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.
Kevin avatar
in flag
Yes a config_entity will autowire like you said - let me try the other way too.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.