File system settings in UI vs. translation.path from settings.php

Created on 11 January 2024, 6 months ago

Problem/Motivation

I am trying to set the translation directory path in settings.php, like this:

$config['locale.settings']['translation']['path'] = '/var/www/d10/files/translations';

This works and the path is used by the locale module.

Unfortunately, the corresponding input field in admin/config/media/file-system is empty. This means the user cannot save the form, for example to save other options.

<!--break-->

This is because in locale_form_system_file_system_settings_alter()

'#default_value' => \Drupal::configFactory()->getEditable('locale.settings')->get('translation.path'),

returns the empty string instead of the path set in settings.php.

Steps to reproduce

Set the translation directory path in settings.php on a fresh install before enabling locale module as shown above. Enable locale module and open admin/config/media/file-system.

Proposed resolution

I am not sure if I'm setting the path in the correct way, that's why I'm tagging this as Support request for now. But maybe the following code in locale.install has to be changed?

/**
 * Implements hook_install().
 */
function locale_install() {
  // Create the interface translations directory and ensure it's writable.
  if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) {
    $site_path = \Drupal::getContainer()->getParameter('site.path');
    $directory = $site_path . '/files/translations';
    \Drupal::configFactory()->getEditable('locale.settings')->set('translation.path', $directory)->save();
  }
  \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}

Instead:

/**
 * Implements hook_install().
 */
function locale_install() {
  // Create the interface translations directory and ensure it's writable.
  if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) {
    $site_path = \Drupal::getContainer()->getParameter('site.path');
    $directory = $site_path . '/files/translations';
  }
  \Drupal::configFactory()->getEditable('locale.settings')->set('translation.path', $directory)->save();
  \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}

Remaining tasks

Clear up whether I'm understanding the settings.php override system correctly. Decide the correct way to make the translation path overridable. Create a patch file, if applicable.

User interface changes

The translation path in admin/config/media/file-system could be changed to an unchangeable display string instead of an input field like the public, private and temp directories above it, when it's overriden in settings.php.

πŸ’¬ Support request
Status

Active

Version

10.2 ✨

Component
LocaleΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡©πŸ‡ͺGermany Chase.

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024