You are here

stringoverrides.module in String Overrides 5

Configuration interface to provide a quick and easy way of replacing text.

File

stringoverrides.module
View source
<?php

/**
 * @file
 * Configuration interface to provide a quick and easy way of replacing text.
 */

/**
 * Implementation of hook_help()
 */
function stringoverrides_help($path) {
  $output = '';
  if ($path == 'admin/help#stringoverrides') {
    $output = '<p>' . t('The <strong>String Overrides</strong> module provides a quick and easy way of replacing text.') . '</p>';
    $output .= '<p>' . t('To replace a string, enter what you find when the string is passed through the <a href="@t">t()</a> function. String Overrides cannot translate user-defined content, it can only replace strings wrapped in the t() function. To find the strings you can actually change, open up a module and look for t() function calls. Places where %, @, or ! are used means that the translation contains dynamic information (such as the node type or title in the above examples), these are not translated while the text around them are.', array(
      '@t' => 'http://api.drupal.org/api/function/t',
    )) . '</p>';
    $output .= '<p>' . t('For example:') . '</p>';
    $output .= theme('item_list', array(
      'The %post has been updated.',
      'Are you sure you want to delete %title?',
      'Screenshot for %theme theme',
    ));
  }
  else {
    if (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) == 'stringoverrides') {
      if (arg(3) == 'import') {
        $output = '<p>' . t('Upload a *.po file here to import a collection of strings.') . '</p>';
      }
      else {
        if (arg(3) == 'export') {
          $output = '<p>' . t('The following is a generated *.po file. You can use this feature to backup the current String Overrides.') . '</p>';
        }
        else {
          $output = '<p>' . t('The following provides quick and easy way of replacing text.') . '</p>';
        }
      }
    }
  }
  return $output;
}

/**
 * Implementation of hook_perm()
 */
function stringoverrides_perm() {
  return array(
    'administer string overrides',
  );
}

// function stringoverrides_perm

/**
 * Implementation of hook_menu()
 */
function stringoverrides_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/stringoverrides',
      'title' => t('String overrides'),
      'description' => t('Provides a quick and easy way of replacing text on the site.'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'stringoverrides_admin',
      ),
      'access' => user_access('administer string overrides'),
      'type' => MENU_NORMAL_ITEM,
    );
    $items[] = array(
      'path' => 'admin/settings/stringoverrides/overrides',
      'title' => t('Overrides'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'stringoverrides_admin',
      ),
      'access' => user_access('administer string overrides'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );
    $items[] = array(
      'path' => 'admin/settings/stringoverrides/import',
      'title' => t('Import'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'stringoverrides_admin_import',
      ),
      'access' => user_access('administer string overrides'),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/settings/stringoverrides/export',
      'title' => t('Export'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'stringoverrides_admin_export',
      ),
      'access' => user_access('administer string overrides'),
      'type' => MENU_LOCAL_TASK,
      'weight' => 1,
    );
  }
  elseif (strpos($_GET['q'], 'admin/settings/stringoverrides') === 0) {
    include_once drupal_get_path('module', 'stringoverrides') . '/stringoverrides.admin.inc';
  }
  return $items;
}

/**
 * Check that locale module is disabled before enabling this module.
 */
function stringoverrides_enable() {
  if (module_exists('locale')) {
    drupal_set_message(t('String overrides module is not compatible with Locale module. Please disable it before using String overrides.'), 'error');
    module_disable(array(
      'stringoverrides',
    ));
  }
}

/**
 * Fake the locale function.
 */
if (!function_exists('locale')) {
  function locale_supported_languages($reset = FALSE, $getall = FALSE) {
    $language = variable_get('stringoverrides_language', 'en-US');
    return array(
      'name' => array(
        $language => 'String Overrides',
      ),
      'formula' => array(
        $language => '',
      ),
    );
  }
  function locale($string) {
    static $strings = array();
    $strings = variable_get('locale_custom_strings_en', array());
    if (isset($strings[$string])) {
      return $strings[$string];
    }
    else {
      return $string;
    }
  }
}

Functions

Namesort descending Description
stringoverrides_enable Check that locale module is disabled before enabling this module.
stringoverrides_help Implementation of hook_help()
stringoverrides_menu Implementation of hook_menu()
stringoverrides_perm Implementation of hook_perm()