? .indexes.swp
? l10n_fix_2.patch
? l10n_tables.patch
Index: ajax.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/ajax.inc,v
retrieving revision 1.1.2.18.2.2
diff -u -p -r1.1.2.18.2.2 ajax.inc
--- ajax.inc	22 Oct 2008 20:28:18 -0000	1.1.2.18.2.2
+++ ajax.inc	29 Oct 2008 07:53:21 -0000
@@ -25,6 +25,8 @@ function l10n_community_string_details($
   // List of project releases, where this string is used.
   $result = db_query('SELECT p.pid, p.title project_title, r.rid, r.title release_title, COUNT(l.lineno) as occurance_count FROM {l10n_community_project} p INNER JOIN {l10n_community_release} r ON p.pid = r.pid INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid WHERE s.sid = %d GROUP BY r.rid ORDER by p.pid, r.rid', $sid);
   
+  $translation_table = l10n_community_translation_table($langcode);
+
   $list = array();
   $output = array();
   $previous_project = '';
@@ -45,7 +47,7 @@ function l10n_community_string_details($
   
   // Information about translator and translation timestamp.
   $translation_info = '';
-  $translation = db_fetch_object(db_query("SELECT translation, uid_entered, time_entered FROM {l10n_community_translation} WHERE language = '%s' AND sid = %d AND is_active = 1 AND is_suggestion = 0", $langcode, $sid));
+  $translation = db_fetch_object(db_query("SELECT translation, uid_entered, time_entered FROM {" . $translation_table . "} WHERE language = '%s' AND sid = %d AND is_active = 1 AND is_suggestion = 0", $langcode, $sid));
   if (!empty($translation->translation)) {
     $account = user_load(array('uid' => $translation->uid_entered));
     $translation_info = t('<strong>Translated by:</strong><br /> %username at %date', array('%username' => $account->name, '%date' => format_date($translation->time_entered)));
@@ -58,7 +60,8 @@ function l10n_community_string_details($
 function l10n_community_string_suggestions($langcode = NULL, $sid = 0) {
   // Existing, "unresolved" suggestions.
   $suggestions = array();
-  $result = db_query("SELECT t.tid, t.sid, t.translation, t.uid_entered, t.time_entered, u.name FROM {l10n_community_translation} t LEFT JOIN {users} u ON u.uid = t.uid_entered WHERE t.language = '%s' AND t.sid = %d AND t.is_active = 1 AND t.is_suggestion = 1 ORDER BY t.time_entered", $langcode, $sid);
+  $translation_table = l10n_community_translation_table($langcode);
+  $result = db_query("SELECT t.tid, t.sid, t.translation, t.uid_entered, t.time_entered, u.name FROM {" . $translation_table . "} t LEFT JOIN {users} u ON u.uid = t.uid_entered WHERE t.language = '%s' AND t.sid = %d AND t.is_active = 1 AND t.is_suggestion = 1 ORDER BY t.time_entered", $langcode, $sid);
 
   $perm = l10n_community_get_permission($langcode);
   while ($suggestion = db_fetch_object($result)) {    
@@ -116,13 +119,14 @@ function l10n_community_string_approve($
   global $user;
   
   if ($suggestion = l10n_community_string_ajax_suggestion($tid)) {
+    $translation_table = l10n_community_translation_table($suggestion->language);
     // Mark existing translations and suggestions as inactive in this language.
-    db_query("UPDATE {l10n_community_translation} SET is_active = 0 WHERE sid = %d AND language = '%s'", $suggestion->sid, $suggestion->language);
+    db_query("UPDATE {" . $translation_table . "} SET is_active = 0 WHERE sid = %d AND language = '%s'", $suggestion->sid, $suggestion->language);
     // Remove placeholder translation record (which was there if
     // first came suggestions, before an actual translation).
-    db_query("DELETE FROM {l10n_community_translation} WHERE sid = %d AND translation = '' AND language = '%s'", $suggestion->sid, $suggestion->language);
+    db_query("DELETE FROM {" . $translation_table . "} WHERE sid = %d AND translation = '' AND language = '%s'", $suggestion->sid, $suggestion->language);
     // Mark this exact suggestion as active, and set approval time.
-    db_query("UPDATE {l10n_community_translation} SET time_approved = %d, uid_approved = %d, has_suggestion = 0, is_suggestion = 0, is_active = 1 WHERE tid = %d;", time(), $user->uid, $suggestion->tid);
+    db_query("UPDATE {" . $translation_table . "} SET time_approved = %d, uid_approved = %d, has_suggestion = 0, is_suggestion = 0, is_active = 1 WHERE tid = %d;", time(), $user->uid, $suggestion->tid);
     // Return something so the client sees we are OK.
     print 'done';
     exit;
Index: l10n_community.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.install,v
retrieving revision 1.1.2.11.2.7
diff -u -p -r1.1.2.11.2.7 l10n_community.install
--- l10n_community.install	26 Oct 2008 20:56:42 -0000	1.1.2.11.2.7
+++ l10n_community.install	29 Oct 2008 07:53:21 -0000
@@ -504,3 +504,128 @@ function l10n_community_update_6004() {
   db_add_index($ret, 'l10n_community_translation', 'sid_language_suggestion', array('sid', 'language', 'is_suggestion'));
   return $ret;
 }
+
+/**
+ * Move all translations from global translation table to separate per-language tables.
+ * Determine languages for all translated strings, check if this language is
+ * enabled, enable it, create tables for it and move it's translations. All
+ * translations table are named following: l10n_community_translation_LANGCODE.
+ */
+function l10n_community_update_6005() {
+  $t = get_t();
+  $schema = $ret = array();
+
+  $schema['l10n_community_translation'] = array(
+    'fields' => array(
+      'tid' => array(
+        'description' => $t('Internal numeric identifier for a translation.'),
+        'type' => 'serial',
+        'not null' => TRUE,
+        'disp-width' => '11'
+      ),
+      'sid' => array(
+        'description' => $t('Reference to the {l10n_community_string}.sid which is being translated.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'disp-width' => '11'
+      ),
+      'language' => array(
+        'description' => $t('Reference to the {languages}.language to which the string is being translated.'),
+        'type' => 'varchar',
+        'length' => '12',
+        'not null' => TRUE
+      ),
+      'translation' => array(
+        'description' => $t('The actual translation or suggestion.'),
+        'type' => 'text',
+        'not null' => TRUE
+      ),
+      'uid_entered' => array(
+        'description' => $t('Reference to the {users}.uid who entered this translation or suggestion.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '11'
+      ),
+      'uid_approved' => array(
+        'description' => $t('Reference to the {users}.uid who approved this translation or suggestion.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '11'
+      ),
+      'time_entered' => array(
+        'description' => $t('Unix timestamp of time when the translation or suggestion was entered.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '11'
+      ),
+      'time_approved' => array(
+        'description' => $t('Unix timestamp of time when the translation or suggestion was approved.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '11'
+      ),
+      'has_suggestion' => array(
+        'description' => $t('Cached flag of whether there is at least one other row in the table where is_suggestion = 1, is_active = 1 and sid and language is the same as this one. Only applicable to rows where is_suggestion = 0.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '11'
+      ),
+      'is_suggestion' => array(
+        'description' => $t('Flag of whether this is a suggestion (1) or not (0). If 0, *_approved fields should also be 0.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '11'
+      ),
+      'is_active' => array(
+        'description' => $t('Flag of whether this is an active (1) suggestion or translation. Older suggestions and translations are kept (0). Unprocessed suggestions and active translations have this as 1.'),
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '11'
+      )
+    ),
+    'primary key' => array('tid'),
+    'indexes' => array(
+      'is_active' => array('is_active'),
+      'is_suggestion' => array('is_suggestion'),
+      'language' => array('language'),
+      'suggestion_active' => array('is_suggestion', 'is_active'),
+      'uid_entered' => array('uid_entered'),
+      'sid_language_suggestion' => array('sid', 'language', 'is_suggestion'),
+      'sid' => array('sid')
+      ),
+    );
+
+
+  $enabled_languages = locale_language_list('native', TRUE);
+  $languages = language_list();
+  // We need to support all languages having at least one translated string.
+  // Prior to this version, the language didn't have to be enabled.
+  $res = db_query("SELECT language FROM {l10n_community_translation} GROUP BY language");
+  while ($row = db_fetch_object($res)) {
+    if (!isset($enabled_languages[$row->language])) {
+      // This language is not enabled.
+      if (!isset($languages[$row->language])) {
+        // This language is not even added.
+        language_add($row->language);
+      } else {
+        $ret[] = update_sql("UPDATE {languages} SET enabled = 1 WHERE language = '%s'", $row->language);
+      }
+    } 
+    // Create translation tables and move data
+    $table_name = l10n_community_translation_table($row->language);
+    if (!db_table_exists($table_name)) {
+      // Create translation table for this language based on schema above.
+      db_create_table($ret, $table_name, $schema['l10n_community_translation']);
+    }
+    // Move data to it's tables.
+    $ret[] = update_sql("INSERT INTO {" . $table_name . "} SELECT * FROM {l10n_community_translation} WHERE language = '" . db_escape_string($row->language) . "'");
+  } 
+  return $ret;
+}
Index: l10n_community.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.module,v
retrieving revision 1.1.2.23.2.11
diff -u -p -r1.1.2.23.2.11 l10n_community.module
--- l10n_community.module	28 Oct 2008 22:44:26 -0000	1.1.2.23.2.11
+++ l10n_community.module	29 Oct 2008 07:53:21 -0000
@@ -292,6 +292,67 @@ function l10n_community_menu() {
 }
 
 /**
+ * Implementation of hook_form_alter().
+ *
+ * Hooks a new submit function to Languages administration screen in Drupal core.
+ */
+function l10n_community_form_alter(&$form, $form_state, $form_id) {
+  switch ($form_id) {
+    case 'locale_languages_overview_form':
+      $form['#submit'][] = 'l10n_community_locale_languages_form_submit';
+      break;
+
+    case 'locale_languages_delete_form':
+      if (db_table_exists(l10n_community_translation_table($form['langcode']['#value']))) {
+        $form['#submit'][] = 'l10n_community_locale_languages_delete_form_submit';
+        $form['description']['#value'] .= '<p>' . t('All translation tables and translations made using l10n_server will be deleted too. This action cannot be undone.') . '</p>';
+      }
+      break;
+  }
+}
+
+/**
+ * Submission handler for locale_languages_overview_form().
+ * React upon enabling/disabling a language and create translations tables.
+ * Scan all enabled languages and create tables for those not having
+ * translation tables.
+ */
+function l10n_community_locale_languages_form_submit($form, &$form_state) { 
+  $languages = locale_language_list('native');
+  foreach ($languages as $langcode => $language) {
+    $table_name = l10n_community_translation_table($langcode);
+    if(!db_table_exists($table_name)) {
+      $schema = drupal_get_schema('l10n_community_translation', TRUE);
+      db_create_table($ret, $table_name, $schema);
+      drupal_set_message(t('Created l10n_server translation table for @language.', array('@language' => $language)));
+    }
+  }
+}
+
+/**
+ * Submission handler for locale_languages_delete_form().
+ * Will drop translation tables for this language.
+ */
+function l10n_community_locale_languages_delete_form_submit($form, &$form_state) {
+  $table_name = l10n_community_translation_table($form['langcode']['#value']);
+  if (db_table_exists($table_name)) {
+    db_drop_table($ret, $table_name);
+    drupal_set_message(t('Deleted l10n_server translation table for @language.', array('@language' => $form['langcode']['#value'])));
+  }
+}
+
+
+/**
+ * Helper function to determine translation table for a language.
+ *
+ * @param $langcode
+ *   Language code.
+ */
+function l10n_community_translation_table($langcode) {
+  return 'l10n_community_translation_' . preg_replace('/[\W|-]/', '_', $langcode);
+}
+
+/**
  * Menu loader function for %l10n_community_language to validate language code.
  */
 function l10n_community_language_load($langcode) {
@@ -1036,7 +1097,7 @@ function l10n_community_get_stats($langc
       
       // Cache results for next time. Not setting a timestamp as cache validity
       // time, we would like to retain control of recalculating these values.
-      cache_set('l10n:stats:'. $langcode, $stats, $cache, CACHE_PERMANENT);
+      cache_set('l10n:stats:'. $langcode, $stats, 'cache', CACHE_PERMANENT);
       return $stats;
     }
   }
Index: translate.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/translate.inc,v
retrieving revision 1.1.2.7.2.5
diff -u -p -r1.1.2.7.2.5 translate.inc
--- translate.inc	26 Oct 2008 22:29:09 -0000	1.1.2.7.2.5
+++ translate.inc	29 Oct 2008 07:53:22 -0000
@@ -585,17 +585,19 @@ function l10n_community_get_strings($lan
   
   $sql = $sql_count = '';
   $sql_args = array();
+
+  $translation_table = l10n_community_translation_table($langcode);
   
   if (!isset($project)) {
     // No project based filtering.
-    $sql = "SELECT DISTINCT s.sid, s.value, t.tid, t.language, t.translation, t.uid_entered, t.uid_approved, t.time_entered, t.time_approved, t.has_suggestion, t.is_suggestion, t.is_active FROM {l10n_community_string} s LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE";
-    $sql_count = "SELECT COUNT(DISTINCT(s.sid)) FROM {l10n_community_string} s LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE";
+    $sql = "SELECT DISTINCT s.sid, s.value, t.tid, t.language, t.translation, t.uid_entered, t.uid_approved, t.time_entered, t.time_approved, t.has_suggestion, t.is_suggestion, t.is_active FROM {l10n_community_string} s LEFT JOIN {" . $translation_table . "} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE";
+    $sql_count = "SELECT COUNT(DISTINCT(s.sid)) FROM {l10n_community_string} s LEFT JOIN {" . $translation_table . "} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE";
     $sql_args = array($langcode);
   }
   else {
     // Project based filtering and language based filtering built in.
-    $sql = "SELECT DISTINCT s.sid, s.value, t.tid, t.language, t.translation, t.uid_entered, t.uid_approved, t.time_entered, t.time_approved, t.has_suggestion, t.is_suggestion, t.is_active FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE r.pid = %d";
-    $sql_count = "SELECT COUNT(DISTINCT(s.sid)) FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE r.pid = %d";
+    $sql = "SELECT DISTINCT s.sid, s.value, t.tid, t.language, t.translation, t.uid_entered, t.uid_approved, t.time_entered, t.time_approved, t.has_suggestion, t.is_suggestion, t.is_active FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {" . $translation_table . "} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE r.pid = %d";
+    $sql_count = "SELECT COUNT(DISTINCT(s.sid)) FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {" . $translation_table . "} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE r.pid = %d";
     $sql_args = array($langcode, $project->pid);
   }
 
