summaryrefslogtreecommitdiff
path: root/modules/locale
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-06-17 17:41:40 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-06-17 17:41:40 +0000
commit64707c09e9ae2eb6a388c2c3c081c848555cc2b3 (patch)
tree68c883a8370c747437282cc3366ac7a8584e0deb /modules/locale
parent9350f5e6cf08bd4381c133478a2161702da75c18 (diff)
downloadbrdo-64707c09e9ae2eb6a388c2c3c081c848555cc2b3.tar.gz
brdo-64707c09e9ae2eb6a388c2c3c081c848555cc2b3.tar.bz2
#150521 by myself: streamline locale runtime performance and clean up code by not storing empty translations
Diffstat (limited to 'modules/locale')
-rw-r--r--modules/locale/locale.install9
-rw-r--r--modules/locale/locale.module39
2 files changed, 22 insertions, 26 deletions
diff --git a/modules/locale/locale.install b/modules/locale/locale.install
index 540efb83b..2dabbe8a4 100644
--- a/modules/locale/locale.install
+++ b/modules/locale/locale.install
@@ -101,6 +101,15 @@ function locale_update_6003() {
}
/**
+ * Remove empty translations, we don't need these anymore.
+ */
+function locale_update_6004() {
+ $ret = array();
+ $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''");
+ return $ret;
+}
+
+/**
* @} End of "defgroup updates-5.x-to-6.x"
*/
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index d0ca4e743..86831fa6c 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -327,33 +327,20 @@ function locale($string = NULL, $langcode = NULL) {
// We do not have this translation cached, so get it from the DB.
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.language = '%s' AND s.textgroup = 'default'", $string, $langcode);
- // Translation found
- if ($trans = db_fetch_object($result)) {
- if (!empty($trans->translation)) {
- $locale_t[$langcode][$string] = $trans->translation;
- $string = $trans->translation;
+ $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 WHERE s.source = '%s' AND t.language = '%s' AND s.textgroup = 'default'", $string, $langcode));
+ if ($translation) {
+ // We have the source string at least.
+ if ($translation->lid) {
+ // Cache translation string or TRUE if no translation exists.
+ $translation = (empty($translation->translation) ? TRUE : $translation->translation);
+ $locale_t[$langcode][$string] = $translation;
}
}
-
- // Either we have no such source string, or no translation
else {
- $result = db_query("SELECT lid, source FROM {locales_source} WHERE source = '%s' AND textgroup = 'default'", $string);
- // We have no such translation
- if ($obj = db_fetch_object($result)) {
- if ($langcode) {
- db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $obj->lid, $langcode);
- }
- }
- // We have no such source string
- else {
- db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', 'default')", request_uri(), $string);
- if ($langcode) {
- $lid = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = 'default'", $string));
- db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES (%d, '%s', '')", $lid->lid, $langcode);
- }
- }
- // Clear locale cache in DB
+ // 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);
+ $locale_t[$langcode][$string] = TRUE;
+ // Clear locale cache so this string can be added in a later request.
cache_clear_all('locale:'. $langcode, 'cache');
}
}
@@ -371,7 +358,7 @@ function locale_refresh_cache() {
$languages = $languages['1'];
foreach ($languages as $language) {
- $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE t.language = '%s' AND 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 WHERE t.language = '%s' AND s.textgroup = 'default' AND LENGTH(s.source) < 75", $language->language);
$t = array();
while ($data = db_fetch_object($result)) {
$t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
@@ -502,7 +489,7 @@ function _locale_batch_import($filepath, &$context) {
// we can extract the language code to use for the import from the end.
if (preg_match('!(/|\.)([^\.]+)\.po$!', $filepath, $langcode)) {
$file = (object) array('filename' => basename($filepath), 'filepath' => $filepath);
- _locale_import_read_po('db-store', $file, 'keep', $langcode[2]);
+ _locale_import_read_po('db-store', $file, LOCALE_IMPORT_KEEP, $langcode[2]);
$context['results'][] = $filepath;
}
}