function i18nstrings_prefetch in Internationalization 6
Prefetch a number of object strings.
File
- i18nstrings/
i18nstrings.module, line 836 - Internationalization (i18n) package - translatable strings.
Code
function i18nstrings_prefetch($context, $langcode = NULL, $join = array(), $conditions = array()) {
global $language;
$langcode = $langcode ? $langcode : $language->language;
// Add language condition.
$conditions['t.language'] = $langcode;
// Get context conditions.
$context = (array) i18nstrings_context($context);
foreach ($context as $key => $value) {
if ($value) {
if ($key == 'textgroup') {
$conditions['s.textgroup'] = $value;
}
else {
$conditions['i.' . $key] = $value;
}
}
}
// Prepare where clause
$where = $params = array();
foreach ($conditions as $key => $value) {
if (is_array($value)) {
$where[] = $key . ' IN (' . db_placeholders($value, is_int($value[0]) ? 'int' : 'string') . ')';
$params = array_merge($params, $value);
}
else {
$where[] = $key . ' = ' . is_int($value) ? '%d' : "'%s'";
$params[] = $value;
}
}
$sql = "SELECT s.textgroup, s.source, i.type, i.objectid, i.property, t.translation FROM {locales_source} s";
$sql .= " INNER JOIN {i18n_strings} i ON s.lid = i.lid INNER JOIN {locales_target} t ON s.lid = t.lid ";
$sql .= implode(' ', $join) . ' ' . implode(' AND ', $where);
$result = db_query($sql, $params);
// Fetch all rows and store in cache.
while ($t = db_fetch_object($result)) {
i18nstrings_cache($t, $langcode, $t->source, $t->translation);
}
}