diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-05-27 11:45:00 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-05-27 11:45:00 +0000 |
commit | 352a8e43341f85e1c7045f0cde2bb5455d185c7e (patch) | |
tree | 0e4bb7402c03e9eff70563c6304bbb388250b716 /modules/locale | |
parent | 66108c34acf55a5cd38dca6c6e6aeb63dd61c678 (diff) | |
download | brdo-352a8e43341f85e1c7045f0cde2bb5455d185c7e.tar.gz brdo-352a8e43341f85e1c7045f0cde2bb5455d185c7e.tar.bz2 |
- Patch #473366 by Berdir: convert locale module to the new database abstraction layer.
Diffstat (limited to 'modules/locale')
-rw-r--r-- | modules/locale/locale.install | 14 | ||||
-rw-r--r-- | modules/locale/locale.module | 23 | ||||
-rw-r--r-- | modules/locale/locale.test | 7 |
3 files changed, 35 insertions, 9 deletions
diff --git a/modules/locale/locale.install b/modules/locale/locale.install index 7febbba9a..3eac012f3 100644 --- a/modules/locale/locale.install +++ b/modules/locale/locale.install @@ -17,7 +17,17 @@ function locale_install() { // Create tables. drupal_install_schema('locale'); - db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1', '0', '')"); + db_insert('languages') + ->fields(array( + 'language' => 'en', + 'name' => 'English', + 'native' => 'English', + 'direction' => 0, + 'enabled' => 1, + 'weight' => 0, + 'javascript' => '', + )) + ->execute(); } /** @@ -217,7 +227,7 @@ function locale_uninstall() { // Delete all JavaScript translation files. $locale_js_directory = file_create_path(variable_get('locale_js_directory', 'languages')); $files = db_query('SELECT language, javascript FROM {languages}'); - while ($file = db_fetch_object($files)) { + foreach ($files as $file) { if (!empty($file->javascript)) { file_unmanaged_delete(file_create_path($locale_js_directory . '/' . $file->language . '_' . $file->javascript . '.js')); } diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 6b1e3a62c..b60366cec 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -377,8 +377,8 @@ function locale($string = NULL, $langcode = NULL, $reset = FALSE) { // Refresh database stored cache of translations for given language. // We only store short strings used in current version, to improve // performance and consume less memory. - $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", $langcode, VERSION); - while ($data = db_fetch_object($result)) { + $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 = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < 75", array(':language' => $langcode, ':version' => VERSION)); + foreach ($result as $data) { $locale_t[$langcode][$data->source] = (empty($data->translation) ? TRUE : $data->translation); } cache_set('locale:' . $langcode, $locale_t[$langcode]); @@ -390,7 +390,10 @@ function locale($string = NULL, $langcode = NULL, $reset = FALSE) { 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, 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)); + $translation = 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 = :language WHERE s.source = :source AND s.textgroup = 'default'", array( + ':language' => $langcode, + ':source' => $string, + ))->fetchObject(); if ($translation) { // We have the source string at least. // Cache translation string or TRUE if no translation exists. @@ -400,13 +403,23 @@ function locale($string = NULL, $langcode = NULL, $reset = FALSE) { // 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", VERSION, $translation->lid); + db_update('locales_source') + ->fields(array('version' => VERSION)) + ->condition('lid', $translation->lid) + ->execute(); cache_clear_all('locale:', 'cache', TRUE); } } else { // We don't have the source string, cache this as untranslated. - db_query("INSERT INTO {locales_source} (location, source, textgroup, version) VALUES ('%s', '%s', 'default', '%s')", request_uri(), $string, VERSION); + db_insert('locales_source') + ->fields(array( + 'location' => request_uri(), + 'source' => $string, + 'textgroup' => 'default', + 'version' => VERSION, + )) + ->execute(); $locale_t[$langcode][$string] = TRUE; // Clear locale cache so this string can be added in a later request. cache_clear_all('locale:', 'cache', TRUE); diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 9e793dffb..e1020a398 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -906,11 +906,14 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase { $user = $this->drupalCreateUser(array('translate interface', 'access administration pages')); $this->drupalLogin($user); $this->drupalGet('admin/international/translate/translate'); - $string = db_fetch_object(db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE \'%.js%\' AND textgroup = \'default\'')); + $string = db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE :location AND textgroup = :textgroup', array( + ':location' => '%.js%', + ':textgroup' => 'default', + ))->fetchObject(); $edit = array('translations[fr]' => 'french translation'); $this->drupalPost('admin/international/translate/edit/' . $string->lid, $edit, t('Save translations')); _locale_rebuild_js('fr'); - $file = db_fetch_object(db_query('SELECT javascript FROM {languages} WHERE language = \'fr\'')); + $file = db_query('SELECT javascript FROM {languages} WHERE language = :language', array(':language' => 'fr'))->fetchObject(); $js_file = file_create_path(variable_get('locale_js_directory', 'languages')) . '/fr_' . $file->javascript . '.js'; $this->assertTrue($result = file_exists($js_file), t('JavaScript file created: %file', array('%file' => $result ? $js_file : t('none')))); |