Sometimes, randomly, I get this very annoying error on all pages.
Warning: file_get_contents(xxxx.js) [function.file-get-contents]: failed to open stream: No such file or directory in _locale_parse_js_file() (line 1472 of xxxx\includes\locale.inc).

The 'xxxx.js' is a javascript file, located in a subfolder in my theme folder. When I disable the locale module, the error message disappears, so it's clear this is a problem with this module.
I am not familiar with module coding so I don't know how to start solving this problem.

Comments

Anonymous’s picture

I found something that looks interesting in locale.module.

Line 833-895:

/**
 * Implements hook_js_alter().
 *
 * This function checks all JavaScript files currently added via drupal_add_js()
 * and invokes parsing if they have not yet been parsed for Drupal.t()
 * and Drupal.formatPlural() calls. Also refreshes the JavaScript translation
 * file if necessary, and adds it to the page.
 */
function locale_js_alter(&$javascript) {
.............I think this lines produce the errors.................
}

I think this is my problem. All my javascript is added by drupal_add_js()!
But, I'm no developer and I have NO insight in this.

Jaypan’s picture

Are you sure you have set the correct path when adding your javascript file? Because the system isn't finding the file at the location you've given. You may want to check permissions on the file as well.

Anonymous’s picture

Yes, the permissions are OK and I double-checked the file path wich is also correct.
But this couldn't be the problem because it does get the files (because no javascript file is broken) while the system keeps giving me these errors. Often when I refresh the window the error disappears. It appears randomly.

EDIT: when I completely remove the function mentioned in my first comment the error message is completely gone, with the locale module still working! So it's clearly this part that is causing the error. But I don't want to 'solve' it this dirty way because I don't know if this function is essential to the module (wich seems logical to me).

Jaypan’s picture

Change this:

Open up includes/locale.inc, and look for this code (the function _locale_parse_js_file)

function _locale_parse_js_file($filepath) {
  global $language;

  // The file path might contain a query string, so make sure we only use the
  // actual file.
  $parsed_url = drupal_parse_url($filepath);
  $filepath = $parsed_url['path'];

Change it to the following:

function _locale_parse_js_file($filepath) {
  global $language;

  // The file path might contain a query string, so make sure we only use the
  // actual file.
  $parsed_url = drupal_parse_url($filepath);
  $filepath = $parsed_url['path'];
  if(!is_file($filepath))
  {
    die('The filepath is: ' . $filepath);
  }

Next time that happens, check that the filepath is actually the same as your javascript file. Change the code back to the original code when you are finished.

Anonymous’s picture

Thanks for your time. Your reply made me look at the paths again. For some reason base_path() messed everything up.
I used this:

<?php 
drupal_add_js(base_path() . path_to_theme() . '/js/xxx.js');
?>

And for some reason it did cause these errors. Now I use only path_to_theme() without base_path() and all errors are gone! Now my other problem is also solved.
Thanks again.

Jaypan’s picture

In the documentation, it says:

'file': Path to the file relative to base_path().

You were adding the path WITH the base path, rather than relative to it. This meant that when Drupal was looking for the file, it wasn't finding it in the location you were telling it.