#171646 by JirkaRybka: store version usage information for every source string, optimize caching and prune the initially unused strings
parent
e310d9e4a4
commit
b5331d0859
|
|
@ -105,6 +105,15 @@ function locale_update_6004() {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune strings with no translations (will be automatically re-registered if still in use)
|
||||
*/
|
||||
function locale_update_6005() {
|
||||
$ret = array();
|
||||
$ret[] = update_sql("DELETE s FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE t.lid IS NULL");
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "defgroup updates-5.x-to-6.x"
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -335,15 +335,23 @@ function locale($string = NULL, $langcode = NULL) {
|
|||
if (!isset($locale_t[$langcode][$string])) {
|
||||
|
||||
// We do not have this translation cached, so get it from the DB.
|
||||
$translation = db_fetch_object(db_query("SELECT s.lid, t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.source = '%s' AND s.textgroup = 'default'", $langcode, $string));
|
||||
$translation = db_fetch_object(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 = '%s' WHERE s.source = '%s' AND s.textgroup = 'default'", $langcode, $string));
|
||||
if ($translation) {
|
||||
// We have the source string at least.
|
||||
// Cache translation string or TRUE if no translation exists.
|
||||
$locale_t[$langcode][$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_query("UPDATE {locales_source} SET version = '%s' WHERE lid = %d LIMIT 1", VERSION, $translation->lid);
|
||||
cache_clear_all('locale:'. $langcode, 'cache');
|
||||
}
|
||||
}
|
||||
else {
|
||||
// We don't have the source string, cache this as untranslated.
|
||||
db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', 'default')", request_uri(), $string);
|
||||
db_query("INSERT INTO {locales_source} (location, source, textgroup, version) VALUES ('%s', '%s', 'default', '%s')", request_uri(), $string, VERSION);
|
||||
$locale_t[$langcode][$string] = TRUE;
|
||||
// Clear locale cache so this string can be added in a later request.
|
||||
cache_clear_all('locale:'. $langcode, 'cache');
|
||||
|
|
@ -356,7 +364,7 @@ function locale($string = NULL, $langcode = NULL) {
|
|||
/**
|
||||
* Refreshes database stored cache of translations.
|
||||
*
|
||||
* We only store short strings to improve performance and consume less memory.
|
||||
* We only store short strings used in current version, to improve performance and consume less memory.
|
||||
*/
|
||||
function locale_refresh_cache() {
|
||||
$languages = language_list('enabled');
|
||||
|
|
@ -364,7 +372,7 @@ function locale_refresh_cache() {
|
|||
unset($languages['en']);
|
||||
|
||||
foreach ($languages as $language) {
|
||||
$result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.textgroup = 'default' AND LENGTH(s.source) < 75", $language->language);
|
||||
$result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.textgroup = 'default' AND s.version = '%s' AND LENGTH(s.source) < 75", $language->language, VERSION);
|
||||
$t = array();
|
||||
while ($data = db_fetch_object($result)) {
|
||||
$t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ function locale_schema() {
|
|||
'textgroup' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'),
|
||||
// The original string in English.
|
||||
'source' => array('type' => 'text', 'mysql_type' => 'blob', 'not null' => TRUE),
|
||||
// Drupal core version, which last used the string.
|
||||
'version' => array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
'indexes' => array
|
||||
|
|
|
|||
|
|
@ -768,6 +768,7 @@ function update_fix_d6_requirements() {
|
|||
}
|
||||
if (db_table_exists('locales_source')) {
|
||||
db_add_field($ret, 'locales_source', 'textgroup', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'));
|
||||
db_add_field($ret, 'locales_source', 'version', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'));
|
||||
}
|
||||
variable_set('update_d6_requirements', TRUE);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue