If you define a different directory to hold the files, for instance a non-web accessible one, and do some translation inline the system adds the wrong path to the file.

Correct one if you use the "traditional" way:
<script type="text/javascript" src="/sites/l10n.drupal-pt.org/files/languages/pt-pt_ca194e9c5842a160eafd29ece4acc98f.js?p"></script>

The one if you choose a non-web dir:
<script type="text/javascript" src="//home/drupaleiros/drupal-pt.org/ficheiros/languages/pt-pt_ca194e9c5842a160eafd29ece4acc98f.js?p"></script>

This last one causes the site to hang trying to load (in my case) http://www.home.pt/drupaleiros/drupal-pt.org/ficheiros/languages/pt-pt_c... which, of course, is not the idea intended.

The code in question is at locale.module, line 541

  // Add the translation JavaScript file to the page.
  if ($files && !empty($language->javascript)) {
    drupal_add_js($dir .'/'. $language->language .'_'. $language->javascript .'.js', 'core');
  }

Locale JS file is generated at locale.inc, line

  // Construct the filepath where JS translation files are stored.
  // There is (on purpose) no front end to edit that variable.
  $dir = file_create_path(variable_get('locale_js_directory', 'languages'));

  // Delete old file, if we have no translations anymore, or a different file to be saved.
  if (!empty($language->javascript) && (!$data || $language->javascript != $data_hash)) {
    file_delete(file_create_path($dir .'/'. $language->language .'_'. $language->javascript .'.js'));
    $language->javascript = '';
    $status = 'deleted';
  }

  // Only create a new file if the content has changed.
  if ($data && $language->javascript != $data_hash) {
    // Ensure that the directory exists and is writable, if possible.
    file_check_directory($dir, TRUE);

    // Save the file.
    $dest = $dir .'/'. $language->language .'_'. $data_hash .'.js';
    if (file_save_data($data, $dest)) {
      $language->javascript = $data_hash;
      $status = ($status == 'deleted') ? 'updated' : 'created';
    }
    else {
      $language->javascript = '';
      $status = 'error';
    }
  }

I expect that this specific file should be hosted at the /sites/all/files/languages to be globally available.

Comments

gábor hojtsy’s picture

Status: Active » Closed (duplicate)

Duplicate of #250451: locale.module adds wrong js path. Please add your feedback there and help fix it as soon as possible. It is indeed a pretty critical bug.