"Trying to get property of non-object in locale_translation_source_check_file()" when checking manually for translation updates

Created on 7 June 2018, almost 7 years ago
Updated 26 February 2023, about 2 years ago

Problem/Motivation

Unfortunately, I'm not sure how to reproduce this; I expect the specific circumstances have something to do with my particular setup, although maybe somebody who is better versed in the code might know what could trigger this condition. One important bit of information is that I just moved the location of the translations directory, so that probably has something to do with it.

Unfortunately I have not been able to get to the root of this problem, but when I try to check for translation updates (manually), the batch process fails with an ajax error, resulting from this notice: "Trying to get property of non-object in locale_translation_source_check_file()". This is on line 173 of locale.translation.inc. The function looks like this:

function locale_translation_source_check_file($source) {
  if (isset($source->files[LOCALE_TRANSLATION_LOCAL])) {
    $source_file = $source->files[LOCALE_TRANSLATION_LOCAL];
    $directory = $source_file->directory;
    $filename = '/' . preg_quote($source_file->filename) . '$/';

    if ($files = file_scan_directory($directory, $filename, ['key' => 'name', 'recurse' => FALSE])) {
      $file = current($files);
      $source_file->uri = $file->uri;
      $source_file->timestamp = filemtime($file->uri);
      return $source_file;
    }
  }
  return FALSE;
}

The source of the problem is the first check, because when things fall over, the key checked for ($source->files['local']) is set to the value FALSE. Line 173 is the one saying $directory = $source_file->directory;; $source_file is FALSE, by then.

Proposed resolution

Change the check to if (!empty($source->files[LOCALE_TRANSLATION_LOCAL])) {

Remaining tasks

confirm the problem. try to update translations after moving the translation directory.

  1. Create patch
  2. Add tests?
  3. Review
  4. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

9.5

Component
LocaleΒ  β†’

Last updated 1 day ago

Created by

πŸ‡³πŸ‡±Netherlands eelkeblok Netherlands πŸ‡³πŸ‡±

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    @eelkeblok, Thank you for reporting this problem. We rely on issue reports like this one to resolve bugs and improve Drupal core.

    Have you resolved this? If so, what did you do?

    This needs manual testing to confirm if the problem still exists.

    Thanks!

  • Status changed to Closed: outdated 3 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    It has been 2 years since more information was asked for and there hasn't been a response. There haven't been other reports of this problem, so I am closing this.

    If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue β†’ starting from "Install Drupal core".

    Thanks!

Production build 0.71.5 2024