Drupal 8 has many improvements for interface, configuration and content translation. There are great series of articles from Gábor Hojtsy: Multilingual Drupal 8.
Let's make Hello World module settings from this article translatable.
Full module code is avalible here: https://github.com/kalabro/drupal-examples/tree/master/hello
This code was tested with core 8.x dev branch (
1. Preparing Drupal 8 installation
- Enable “Language”, “Interface Translation” and “Configuration Translation” modules.
- Configure multiple languages.
- Place “Language switcher” block.
- Check how “Configuration Translation” with Site information form.
2. “Hello World” module
3. More complex settings
4. Make settings translatable
Our setting 'Your "Hello World!" message' should be translatable.
First of all we have to add config schema. It is recommended to add schema for any modules with configuration.
label: 'Hello World settings'
label: 'Letter case of your "Hello World!" message'
# translatable: true
type: text # translatable by default.
label: 'Your "Hello World!" message'
Now Drupal knows what kind of data is stored in module config. Some of config data types are translatable by default (text, label, mail). You can also add
translatable: true to settings manually (try to do it for “case” setting).
Just small YAML file and that's all.
To see “Translate settings” tab you need existing default local task (See hello.local_tasks.yml for an example. Note: because of a change in Drupal core, this file name is no longer correct. It should be
Only translatable settings are appeared.
P.S.: In Drupal 7 i18n_variable API is used for this task.