fede-green
9/19/2018 - 5:22 AM

Translating configuration

d8 configs are translatable!

module.translatable_message_text:
  route_name: module.translatable_message_text
  title: Settings
  base_route: module.translatable_message_text
/* Then one can use the config directly this way. */
$text = \Drupal::config('module.translatable_message_text')->get('text');
/* to be put in module/config/schema folder. */
module.translatable_message_text:
  type: config_object
  label: 'Module config'
  mapping:
    text:
      type: mapping
      label: 'Translatable block message'
      mapping:
        value:
          type: text
          label: 'Message text - Value'
        format:
          type: string
          label: 'Message - Format'
/* To be put in module/config/install folder. */
langcode: 'en'
text:
  value: '<h4>HELLO</h4>'
  format: "full_html"
module.translatable_message_text:
  title: 'Module Translatable config'
  base_route_name: module.translatable_message_text
  names:
    - module.translatable_message_text
module.translatable_message_text:
  title: 'Module translatable block settings'
  route_name: 'module.translatable_message_text'
  description: 'Set the translatable block message text'
  parent: 'system.admin_config_system'
  weight: 99