4

I wrote a module where I using a form for editing my module's configs. My current goal to be able to translate some of my config field's values with configuration translation. I already implemented the followings:

  • For the menus:

    • mymodule.links.menu.yml
    • mymodule.links.task.yml
  • For the translation:

    • mymodule.config_translation.yml
    • config/schema/mymodule.schema.yml (I indicated also which should be translated and which shouldn't)

I also added language into my config, however, I don't think there's any meaning for it

My current problem is: when I going to my settings page, I go to the translate tab, add a language and that form is totally empty. There's no field listed where I can write anything, just a save button... what am I missing?

config/install/mymodule.mymodulesettings.yml

service_id: '' normalized: true success: 'Successfully subscribed!' langcode: en 

config/schema/mymodule.schema.yml

mymodule.mymodulesettings: type: config_object label: 'Mymodule settings' mapping: success: type: string label: 'Success message' translatable: true normalized: type: boolean label: 'E-mail address should be normalized?' translatable: false service_id: type: string label: 'Service id' translatable: false 

mymodule.links.menu.yml

mymodule.mymodule_settings_form: title: 'Mymodule Settings' route_name: mymodule.mymodule_settings_form description: 'Configure Mymodule integration' parent: system.admin_config_system weight: 99 

mymodule.links.task.yml

mymodule.mymodule_settings_form_tab: base_route: mymodule.mymodule_settings_form title: 'Mymodule Settings' route_name: mymodule.mymodule_settings_form 

mymodule.routing.yml

mymodule.mymodule_settings_form: path: '/admin/config/system/mymodule-settings' defaults: _form: '\Drupal\mymodule\Form\MymoduleSettingsForm' _title: 'Mymodule Settings Form' requirements: _permission: 'manage mymodule settings' options: _admin_route: TRUE 

mymodule.permission.yml

manage mymodule settings: title: 'Manage mymodule settings' description: 'Allows users to configure mymodule' 

mymodule.config_translation.yml

mymodule.mymodule_settings_form: title: 'Newsroom Mymodule Form' base_route_name: mymodule.mymodule_settings_form names: - mymodule.mymodulesettings 
9
  • 1
    What I learned so far from configuration translation is that you need at least one root property to be translatable in order to make nested keys to be translatable. Commented Jan 24, 2020 at 14:26
  • 1
    Also worth checking stackoverflow.com/questions/50862690/…. TLDR; hojtsy.hu/blog/2014-may-26/… Commented Jan 24, 2020 at 14:28
  • I don't have nested keys, all keys are in the same level and I viewing the site as user 1 Commented Jan 24, 2020 at 14:34
  • 2
    I think I found the problem, on your schema change the type from string to label for those you want to be translatable. Also remove all translatable: false since its the default behavior. Also for label does not need the translatable key since also defualt. Check this hojtsy.hu/files/ConfigSchemaCheatSheet1.5.pdf Commented Jan 24, 2020 at 15:55
  • 2
    Yes, the label was the missing part. langcode is not required to schema I think, because the config_object contains it. Commented Jan 24, 2020 at 16:03

1 Answer 1

4

The problem as commented above is the type of the translatable properties on the schema. Needs to be changed from string to label also the translatable: false can be safely removed since is default behavior, and also no needed for label or text types.

For more information about config translation check the cheatsheet.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.