In Drupal 6:
function saladtheme_preprocess_page(&$vars, $hook)
And in Drupal 7:
function saladtheme_preprocess_html(&$variables, $hook)
}Consider the order in which you load the JS ﬁles, as the ﬁles loaded ﬁrst will appear ﬁrst in the HTML head section2.
Now that we have our JS ﬁles loaded up correctly, we might might want to translate some of the strings that they contain.
If you add Drupal’s t() function to a php page, you can have the text translated into multiple languages, with each new text entry stored in the database, via a call to locale(); if the string has already been translated, then the translated version is returned.
As with t(), we can use replacement values in Drupal.t(). This shows a clear example.
On the other hand, one noticeable difference between t() and Drupal.t() is that Drupal.t() does not insert the run time value of variables into the database, which is something you can do with t(). We might add t($dynamic_variable); we can use variables when necessary, but it’s something to avoid in the case of user speciﬁed content, as Gábor Hojtsy points out. My hunch is that php variables don’t work with Drupal.t(), and locale_parse_js_file(), because the ﬁle is parsed as plain text. There are work-arounds, however, such as using nodes to store the translations, and thus avoiding the use of Drupal.t().
- If the JS ﬁle is loaded on every page, you can just use: scripts = js/script.js, in your mytheme.info
- Drupal 7 allows you to set the weight in drupal_add_js(), which could come in useful if JS ﬁles, are getting loaded from other locations, such as modules.