function locale

cis7 locale.module locale($string = NULL, $context = NULL, $langcode = NULL)
cle7 locale.module locale($string = NULL, $context = NULL, $langcode = NULL)
elmsmedia7 locale.module locale($string = NULL, $context = NULL, $langcode = NULL)
icor7 locale.module locale($string = NULL, $context = NULL, $langcode = NULL)
meedjum_blog7 locale.module locale($string = NULL, $context = NULL, $langcode = NULL)
mooc7 locale.module locale($string = NULL, $context = NULL, $langcode = NULL)

Provides interface translation services.

This function is called from t() to translate a string if needed.


$string: A string to look up translation for. If omitted, all the cached strings will be returned in all languages already used on the page.

$context: The context of this string.

$langcode: Language code to use for the lookup.

1 call to locale()
t in includes/
Translates a string to the current language or to a given language.
86 string references to 'locale'
adaptivetheme_preprocess_block in sites/all/themes/ulmus/adaptivetheme/at_core/inc/
Preprocess variables for block.tpl.php
advagg_current_hooks_hash_array in sites/all/modules/ulmus/advagg/advagg.module
Get an array of all hooks and settings that affect aggregated files contents.
advagg_mod_admin_settings_form in sites/all/modules/ulmus/advagg/advagg_mod/
Form builder; Configure advagg settings.
at_generate_html_classes in sites/all/themes/ulmus/adaptivetheme/at_core/inc/
Return an array of classes to be used for body classes in html.tpl.php
bakery_form_alter in sites/all/modules/ulmus/bakery/bakery.module
Implements hook_form_alter().

... See full list


modules/locale/locale.module, line 668
Add language handling functionality and enables the translation of the user interface to languages other than English.


function locale($string = NULL, $context = NULL, $langcode = NULL) {
  global $language;

  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['locale'] = &drupal_static(__FUNCTION__);
  $locale_t = &$drupal_static_fast['locale'];

  if (!isset($string)) {
    // Return all cached strings if no string was specified
    return $locale_t;

  $langcode = isset($langcode) ? $langcode : $language->language;

  // Store database cached translations in a static variable. Only build the
  // cache after $language has been set to avoid an unnecessary cache rebuild.
  if (!isset($locale_t[$langcode]) && isset($language)) {
    $locale_t[$langcode] = array();
    // Disabling the usage of string caching allows a module to watch for
    // the exact list of strings used on a page. From a performance
    // perspective that is a really bad idea, so we have no user
    // interface for this. Be careful when turning this option off!
    if (variable_get('locale_cache_strings', 1) == 1) {
      if ($cache = cache_get('locale:' . $langcode, 'cache')) {
        $locale_t[$langcode] = $cache->data;
      elseif (lock_acquire('locale_cache_' . $langcode)) {
        // Refresh database stored cache of translations for given language.
        // We only store short strings used in current version, to improve
        // performance and consume less memory.
        $result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < :length", array(':language' => $langcode, ':version' => VERSION, ':length' => variable_get('locale_cache_length', 75)));
        foreach ($result as $data) {
          $locale_t[$langcode][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation);
        cache_set('locale:' . $langcode, $locale_t[$langcode]);
        lock_release('locale_cache_' . $langcode);

  // If we have the translation cached, skip checking the database
  if (!isset($locale_t[$langcode][$context][$string])) {

    // We do not have this translation cached, so get it from the DB.
    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
      ':language' => $langcode,
      ':source' => $string,
      ':context' => (string) $context,
    if ($translation) {
      // We have the source string at least.
      // Cache translation string or TRUE if no translation exists.
      $locale_t[$langcode][$context][$string] = (empty($translation->translation) ? TRUE : $translation->translation);

      if ($translation->version != VERSION) {
        // This is the first use of this string under current Drupal version. Save version
        // and clear cache, to include the string into caching next time. Saved version is
        // also a string-history information for later pruning of the tables.
        db_update('locales_source')->fields(array('version' => VERSION))->condition('lid', $translation->lid)->execute();
        cache_clear_all('locale:', 'cache', TRUE);
    else {
      // We don't have the source string, cache this as untranslated.
        'location' => request_uri(),
        'version' => VERSION,
        'source' => $string,
        'context' => (string) $context,
        'textgroup' => 'default',
      $locale_t[$langcode][$context][$string] = TRUE;
      // Clear locale cache so this string can be added in a later request.
      cache_clear_all('locale:', 'cache', TRUE);

  return ($locale_t[$langcode][$context][$string] === TRUE ? $string : $locale_t[$langcode][$context][$string]);



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.