function locale in Drupal 4
Same name and namespace in other branches
- 5 modules/locale/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.
7 string references to 'locale'
- locale_admin_manage_delete_form_submit in modules/
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.
- _locale_add_language in includes/
locale.inc - Helper function to add a language
- _locale_admin_import_submit in includes/
locale.inc - Process the locale import form submission.
File
- modules/
locale.module, line 171 - 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}");
if ($cache == 0) {
locale_refresh_cache();
$cache = cache_get("locale:{$locale}");
}
$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}");
}
}
return $string;
}