Translations directory not autocreated

Created on 13 November 2018, about 6 years ago
Updated 21 September 2024, 2 months ago

Problem/Motivation

In some situations the translations directory (where downloaded translation files get stored; e.g. sites/default/files/translations) is missing. This may happen for example in a development process, where a site is re-created on a dev machine from git and a live DB but without populating the files directory (as you use StageFileProxy).

Simplified steps to reproduce in a normally working site (translations directory = sites/default/files/translations)

$ rm -r sites/default/files/translations
$ drush locale-update

or on browser at admin/config/regional/translate/import and trying to import the .po file.

Example error messages:

 [notice] File temporary://filejmiMlj could not be moved/copied because the destination directory translations:// is not configured correctly.
 [error]  Unable to download translation file https://ftp.drupal.org/files/translations/8.x/admin_toolbar/admin_toolbar-8.x-1.24.de.po. 
 [warning] fopen(translations://admin_toolbar-8.x-1.24.de.po): failed to open stream: "Drupal\locale\StreamWrapper\TranslationsStream::stream_open" call failed PoStreamReader.php:154
 [warning] fgets() expects parameter 1 to be resource, boolean given PoStreamReader.php:248
 [notice] Unable to import translations file: translations://admin_toolbar-8.x-1.24.de.po

Screenshot of error message on translation import form:

Processes that will profit from a fix:

  • Update translation via user interface
  • Upload a translation via the Translation import page
  • Adding a language

Proposed resolution

  • Auto-create the directory if at the start of the batch check/update process.
  • Auto-create the directory when importing a translation via the Translation import page.

Remaining tasks

User interface changes

none

API changes

none

Data model changes

none

๐Ÿ› Bug report
Status

Needs review

Version

11.0 ๐Ÿ”ฅ

Component
Localeย  โ†’

Last updated about 4 hours ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany geek-merlin Freiburg, Germany

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland Lukas von Blarer

    Just ran into this issue once again. It would be great to fix this, since it can be pretty annoying such as breaking CI pipelines when installing modules.

    Could we move this issue forward? I guess the comments in #25 are still valid?

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    29,722 pass, 2 fail
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    Patch Failed to Apply
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States adam-delaney

    Re rolling patch 30 for latest Drupal 10.2.x

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States adam-delaney

    I made a mistake re-rolling 35, so I've re-rolled a new patch to resolve the issue which should apply cleanly against latest 10.2.x

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 11 months ago
    Build Successful
  • First commit to issue fork.
  • First commit to issue fork.
  • Merge request !8320Autocreate translations directory โ†’ (Open) created by sokru
  • Pipeline finished with Failed
    6 months ago
    Total: 166s
    #192718
  • Pipeline finished with Failed
    6 months ago
    Total: 1809s
    #192726
  • Pipeline finished with Failed
    6 months ago
    Total: 609s
    #192828
  • Pipeline finished with Failed
    6 months ago
    Total: 617s
    #192882
  • Pipeline finished with Failed
    6 months ago
    Total: 510s
    #192910
  • Pipeline finished with Success
    6 months ago
    Total: 3016s
    #193282
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

    The MR !8320 should address the feedback from #25.3 and #25.5, but I wonder what action (if any) should be taken for other comments on #25, so marking this "Needs review".

    I feel the priority should be raised, because this issue is typical for causing frustration, since the the UI doesn't give a proper indication of what is wrong with settings.

  • Status changed to RTBC 6 months ago
  • ivnish Kazakhstan

    MR works fine. Tested drush locale-update and translations update via UI

  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    I have mixed feelings about this issue.

    I think the missing translation directory in your dev situation for example is a lack of syncing files in your development workflow. Other critical files may also be missing. Eg. the JS translation files may get regenerated locally and that may end up leading to a mismatch in your live site when the updates get pushed (depending on what you push).

    At the same time I understand the developer experience improvement that instead of an error, you get an empty directory at least. I am not sure though if that does not lead to unwanted side effects.

    How are other files missing handled by Drupal? Eg. if your site logo is missing or other key files that you don't have on the dev environment?

    One MR specific comment: How is the locale/src/Plugin/QueueWorker/LocaleTranslation.php change related?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Should this be in PNMI ?

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    To address some of the questions in #42

  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

    How are other files missing handled by Drupal? Eg. if your site logo is missing or other key files that you don't have on the dev environment?

    I don't think its recommended to include files from sites/default/files to version control. If the theme build assets are not included in version control and the build process fails, at least there's visual cue that the files are missing. When translation directory missing, the error message on UI/watchdog doesn't give guidance how to resolve the issue. I added the screenshot of the error message on UI to issue summary.

    For code specific discussion I think the comments on merge request would be preferred, but locale/src/Plugin/QueueWorker/LocaleTranslation.php change is needed because LocaleTranslation::processItem() provides zero $args. The tests where failing without this change.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    Indeed that error message is not helpful. Could the error be more specific and tell the user the directory does not exist? What can the user then do to get the directory created? (Save the file settings config form?) At least if we let the user know this, they have a chance to sync their translation files if they wish so without silently getting them into a different situation.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Thanks so much for taking a look @gรกbor hojtsy moving to NW to address the feedback.

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sokru

    re: #46
    Asking users to go to separate form to resolve this issue does not help the command-line use cases (CI pipelines, syncing database from different environment, etc.).

    IMHO automatically creating the missing translation directory gives the best DX/UX. We could add some message to inform about autocreation.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada gordonio

    I have run into this a few times with CI pipelines and it is a bit of an annoyance. I agree with sokru that we should handle it automatically if it doesn't exist. I can't see a downside to having it there, even if it is empty.

  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • First commit to issue fork.
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany tobiasb Berlin

    MR updated + missing typehints.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    We could add some message to inform about autocreation.

    Think would be a good compromise

Production build 0.71.5 2024