function locale in Drupal 5
Same name and namespace in other branches
- 4 modules/locale.module \locale()
- 6 modules/locale/locale.module \locale()
- 7 modules/locale/locale.module \locale()
Provides interface translation services.
This function is called from t() to translate a string if needed.
1 call to locale()
- t in includes/
common.inc - Translate strings to the current locale.
11 string references to 'locale'
- drupal_verify_profile in includes/
install.inc - Verify a profile for installation.
- install_select_locale_form in ./
install.php - locale_admin_manage_delete_form_submit in modules/
locale/ locale.module - Process language deletion submissions.
- locale_initialize in includes/
common.inc - Initialize the localization system.
- t in includes/
common.inc - Translate strings to the current locale.
File
- modules/
locale/ locale.module, line 164 - Enables administrators to manage the site interface languages.
Code
function locale($string) {
global $locale;
static $locale_t;
// Store database cached translations in a static var.
if (!isset($locale_t)) {
$cache = cache_get("locale:{$locale}", 'cache');
if (!$cache) {
locale_refresh_cache();
$cache = cache_get("locale:{$locale}", 'cache');
}
$locale_t = unserialize($cache->data);
}
// We have the translation cached (if it is TRUE, then there is no
// translation, so there is no point in checking the database)
if (isset($locale_t[$string])) {
$string = $locale_t[$string] === TRUE ? $string : $locale_t[$string];
}
else {
$result = db_query("SELECT s.lid, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.source = '%s' AND t.locale = '%s'", $string, $locale);
// Translation found
if ($trans = db_fetch_object($result)) {
if (!empty($trans->translation)) {
$locale_t[$string] = $trans->translation;
$string = $trans->translation;
}
}
else {
$result = db_query("SELECT lid, source FROM {locales_source} WHERE source = '%s'", $string);
// We have no such translation
if ($obj = db_fetch_object($result)) {
if ($locale) {
db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '')", $obj->lid, $locale);
}
}
else {
db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", request_uri(), $string);
if ($locale) {
$lid = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $string));
db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '')", $lid->lid, $locale);
}
}
// Clear locale cache in DB
cache_clear_all("locale:{$locale}", 'cache');
}
}
return $string;
}