2

I am using the Fivestar module for rating purpose in my project.
In that module there is a function called fivestar_add_js(), which is used to add the necessary terms to Javascript. The function is given below:

function fivestar_add_js() {
  static $js_added = FALSE;

  // Add necessary javascript only once per page.
  if (!$js_added) {
    $settings = array(
      'titleUser' => t('Your rating') .': ',
      'titleAverage' => t('Average') .': ',
      'feedbackSavingVote' => t('Saving your vote...'),
      'feedbackVoteSaved' => t('Your vote has been saved.'),
      'feedbackDeletingVote' => t('Deleting your vote...'),
      'feedbackVoteDeleted' => t('Your vote has been deleted.'),
    );

    drupal_add_js(drupal_get_path('module', 'fivestar') .'/js/fivestar.js');
    drupal_add_js(array('fivestar' => $settings), 'setting');
    $js_added = TRUE;
  }
}

In that function I need to replace the word from vote to rating.
How can I do this?

4
  • is there any other way to do by NOT USING settings.php.. For example: by working with custom modules. Just need an info...
    – Fero
    Sep 15, 2011 at 13:12
  • Did you look at the module I mentioned in my answer?
    – mpdonadio
    Sep 15, 2011 at 13:13
  • Yes.. I do.. but just for only this case i need to use that module.. Is that fine or any performance issues will arise if we use lot of modules for small purposes. I am just a beginner. If anything wrong then correct me...
    – Fero
    Sep 15, 2011 at 13:44
  • You have three choices. 1. Edit the Fivestar module. 2. Use the settings overrides, like mentioned below. 3. Use a contrib module, like mentioned below. You really have no other options. I wouldn't worry about performance for things like this unless you are getting serious, serious traffic.
    – mpdonadio
    Sep 15, 2011 at 13:59

2 Answers 2

2

Ok, the title is a little misleading here. You actually want to override a JavaScript setting, not a file. The difference is that settings are inline on a page.

The strings are processed through t() so there are "proper" ways to do replacement.

Putting this in your "settings.php" file should work.

$conf["locale_custom_strings_en"] = array(
  "Saving your vote..." => "Saving your rating...",
  "Your vote has been saved." => "Your rating has been saved.", 
  "Deleting your vote..." => "Deleting rating vote...", 
  "Your vote has been deleted." => "Your rating has been deleted.", 
);

In Drupal 7, I think you need to change the first line to

$conf["locale_custom_strings_en"][""] = array(

I believe you can also use String Overrides to accomplish the same thing, but I don't have direct experience with this module.

1
  • +1 for suggesting string overrides module. And i used it instead of using settings.php... thanks :-)
    – Fero
    Sep 16, 2011 at 10:10
2

As those strings are passed to t() the faster way to rewrite those strings is to overwrite then in the settings.php file, using something similar to the following code (write only the code for the Drupal version you are using):

// Drupal 6.
$conf['locale_custom_strings_en'] = array(
  'Saving your vote' => 'Saving your rating',
  'Your vote has been saved' => 'Your rating has been saved',
  'Deleting your vote...' => 'Deleting your rating...',
  'Your vote has been deleted.' => 'Your rating has been deleted.'
);

// Drupal 7.
$conf['locale_custom_strings_en'][''] = array(
  'Saving your vote' => 'Saving your rating',
  'Your vote has been saved' => 'Your rating has been saved',
  'Deleting your vote...' => 'Deleting your rating...',
  'Your vote has been deleted.' => 'Your rating has been deleted.'
);
1
  • Override of Javascript strings using $conf['locale_custom_strings_en'][''] doesn't work, does it? Aug 24, 2016 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.