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
string
tolabel
for those you want to be translatable. Also remove all translatable: false since its the default behavior. Also forlabel
does not need the translatable key since also defualt. Check this hojtsy.hu/files/ConfigSchemaCheatSheet1.5.pdflabel
was the missing part.langcode
is not required to schema I think, because theconfig_object
contains it.