Problem/Motivation

This is blocked on #2950407: Make translations directory configurable during install.

Interface Translation allows configuring the filename pattern of translation files that are downloaded and/or imported.

The installer does not respect this leading to a mismatch of translations for existing sites vs. fresh installations.

Steps to reproduce

  1. Set the translation filename pattern in settings.php, for example:
    $config['locale.settings']['translation']['default_filename'] = '%project.%language.po';
    

    to remove the "%version" part of the filename.

Expected result:

  • If there is no translation file in the translation directory yet (e.g. drupal.de.po): The file should be downloaded and named accordingly.
  • If there is already a translation file: Nothing should be downloaded and the file should be imported.

Actual result: A file will be downloaded and named e.g. drupal-9.0.0.de.po instead of what was configured.

Proposed resolution

Make the file translation used in the installer and install_check_translations() consider the filename pattern correctly.

Remaining tasks

Review the change. As the merge request is based on the merge request from #2950407: Make translations directory configurable during install, the changes for this issue can be seen here: https://git.drupalcode.org/issue/drupal-3182660/-/compare/5838f78c5d5a65...

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

CommentFileSizeAuthor
#4 3182660-8.9.x-4.patch12.89 KBtstoeckler

Issue fork drupal-3182660

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tstoeckler created an issue. See original summary.

tstoeckler’s picture

Status: Active » Needs review

Created a merge request now based on #2950407: Make translations directory configurable during install.

The part to review for this issue is this commit: https://git.drupalcode.org/project/drupal/-/merge_requests/47/diffs?comm...

Some notes:

  1. We are touching the only place that install_retrieve_file() is called from taking a directory to a filename (which it already supports), which is why I went ahead and deprecated the directory-associated logic. This could be done in a follow-up but seems related enough to me. I did not, though, create a draft change notice yet, so the link in the code is bogus for now.
  2. _install_prepare_import() is a very strange function which probably makes the change there difficult to understand, as well. I will try to explain: The removed regular expression attempts to figure out the version from the filename. However, just above the hunk shown in the diff is this line:
            $files = locale_translate_get_interface_translation_files(['drupal'], [$langcode]);
      

    locale_translate_get_interface_translation_files() calls out to locale_translate_file_attach_properties() which already figures out the version from the filename. So the current regular expression is completely unnecessary and we can instead just use the already determined version. So since we have to touch that code anyway to do the fallback if the version is not part of the filename I opted to do this tiny amount of clean-up to remove the regular expression. It could also be avoided theoretically, though. Note also that there are a bunch of other things that could be cleaned up here, which I did not attempt in order to keep this in scope. in particular locale_translate_get_interface_translation_files() does not fully support configurable filename patterns, it just has a fairly loose regular expression so that a bunch of patterns - including the one from the issue summary - is supported. Fixing that to properly support all filename patterns is not within the scope of this issue in my opinion.

  3. The change to FileTranslation could and should be tested by a dedicated kernel test. That is not done as of now.
tstoeckler’s picture

StatusFileSize
new12.89 KB
tstoeckler’s picture

Fixed the tests so this will hopefully be green. The "to-review" part for this issue can be seen here: https://git.drupalcode.org/issue/drupal-3182660/-/compare/5838f78c5d5a65...

Not uploading a new 8.9.x patch because the changes are cosmetic only. The test fails before just trigger the newly introduced deprecation, they don't expose any breakage.

The tests that triggered those deprecations show that we do actually have some test coverage of the FileTranslation class, which I was not aware before. (I had just blindly searched for a test class called "FileTranslationTest"...). So on top of just fixing the deprecation notice, I expanded the two tests to cover the functionality added here, so this should cover the need for additional test coverage mentioned in #3.3

Note that InstallTranslationFilePatternTest is somewhat of a strange test in that it's a kernel test, but it "unit tests" the FileTranslation::getTranslationFilesPattern() method via setting it to public via reflection. The reason it needs to be a kernel test in its current form is that it uses the file system service from the container. So it would be better to mock that service and turn the test into a kernelunit test. However, it could also be argued that it basically provides duplicate test coverage of InstallerTranslationFilenameTest so maybe it can also just be removed, in particular because there are people (including me) who are not very fond of testing protected methods via reflection. So for now just leaving as is (with the expanded coverage) as (hopefully) the least controversial change, but absolutely open to either removing it or turning it into a unit test.

tstoeckler’s picture

Issue summary: View changes
tstoeckler’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nod_’s picture

Status: Needs review » Needs work

The MR doesn't apply anymore unfortunately, and probably needs a refresh for D10

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.