summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Reyero2009-10-19 14:02:03 (GMT)
committer Jose Reyero2009-10-19 14:02:03 (GMT)
commit4d34c53b3759a91ef95b3fe93d911fe56a2a2713 (patch)
tree86d7d1d5e7a6396bca7fc96359e0225c68adb51b
parentc61e9fe038c4a08e7a7fc4dcd72b6f2a409e32ef (diff)
- Fixed buggy taxonomy synchronization, #365606, #365606, #379306
- Cleaning some module dependencies and old code.
-rw-r--r--CHANGELOG.txt2
-rw-r--r--i18n.module57
-rw-r--r--i18ncontent/i18ncontent.info1
-rw-r--r--i18nsync/i18nsync.module10
-rw-r--r--i18ntaxonomy/i18ntaxonomy.module73
5 files changed, 73 insertions, 70 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index aa52c08..676cc42 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -2,6 +2,8 @@
6.x-1.1 to .......
------------------
+- Fixed buggy taxonomy synchronization, #365606, #365606, #379306
+- Cleaning some module dependencies and old code.
- Fixed: Select translations autocomplete wrong filtering by hass, #557980
- Added: Translated taxonomy tokens by Hugo Wetterberg, googletorp, #344794
- Fixed: Global variable corruption by etzel, #580280
diff --git a/i18n.module b/i18n.module
index 34ab4c0..8b13b07 100644
--- a/i18n.module
+++ b/i18n.module
@@ -131,63 +131,6 @@ function i18n_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
}
}
-/*
-function i18n_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
- if (variable_get("i18n_node_$node->type", 0)) {
- switch ($op) {
- case 'load':
- return db_fetch_array(db_query("SELECT trid, language, status AS i18n_status FROM {i18n_node} WHERE nid=%d", $node->nid));
-
- case 'insert':
- case 'update':
- db_query("DELETE FROM {i18n_node} WHERE nid=%d",$node->nid);
- if ($node->language){
- // Assign a trid from the beginning
- db_query("INSERT INTO {i18n_node} (nid, trid, language, status) VALUES(%d, '%d', '%s', '%d')", $node->nid, $node->trid, $node->language, $node->i18n_status);
- }
- // Handle menu items. Fixes duplication issue and language for menu items which happens when editing nodes in languages other than current.
- if (isset($node->menu) && !$node->menu['delete'] && $node->menu['title']) {
- $item = $node->menu;
- $item['path'] = ($item['path']) ? $item['path'] : "node/$node->nid";
- $item['type'] = $item['type'] | MENU_MODIFIED_BY_ADMIN;
- if ($item['mid']) {
- // Update menu item.
- db_query("UPDATE {menu} SET pid = %d, path = '%s', title = '%s', description = '%s', weight = %d, type = %d, language = '%s' WHERE mid = %d", $item['pid'], $item['path'], $item['title'], $item['description'], $item['weight'], $item['type'], $node->language, $item['mid']);
- drupal_set_message(t('The menu item %title has been updated with node language.', array('%title' => $item['title'])));
- }
- elseif (SAVED_NEW == menu_save_item($item)) {
- // Creating new menu item with node language.
- db_query("UPDATE {menu} SET language = '%s' WHERE mid = %d", $node->language, $item['mid']);
- drupal_set_message(t('The menu item %title has been added with node language.', array('%title' => $item['title'])));
- }
- menu_rebuild();
- unset($node->menu); // Avoid further processing by menu module.
- }
- // Pathauto integration. Dynamic replacement of variables to allow different patterns per language.
- if (module_exists('path') && module_exists('pathauto')) {
- // Language for pathauto variables is either node language or default language.
- $language = $node->language ? $node->language : i18n_default_language();
- if ($language != i18n_get_lang()) {
- i18n_variable_init($language, 'pathauto_node');
- }
- }
- break;
-
- case 'delete':
- db_query('DELETE FROM {i18n_node} WHERE nid=%d', $node->nid);
- break;
-
- case 'prepare':
- // Book pages, set the right language nodes and outlines.
- if (arg(3) == 'parent' && is_numeric(arg(4)) && ($parent = node_load(arg(4))) && $parent->language) {
- $node->language = $parent->language;
- i18n_selection_mode('node', $parent->language);
- }
- break;
- }
- }
-}*/
-
/**
* Implementation of hook_alter_translation_link().
*
diff --git a/i18ncontent/i18ncontent.info b/i18ncontent/i18ncontent.info
index f98065c..ab9f67e 100644
--- a/i18ncontent/i18ncontent.info
+++ b/i18ncontent/i18ncontent.info
@@ -1,7 +1,6 @@
; $Id$
name = Content type translation
description = Translates content type related strings: name, description, help text...
-dependencies[] = i18n
dependencies[] = i18nstrings
package = Multilanguage
core = 6.x
diff --git a/i18nsync/i18nsync.module b/i18nsync/i18nsync.module
index 5423e9a..52e53f6 100644
--- a/i18nsync/i18nsync.module
+++ b/i18nsync/i18nsync.module
@@ -223,7 +223,7 @@ function i18nsync_prepare_translation(&$node, $source, $field_list) {
if (empty($source->$field)) continue;
switch ($field) {
case 'taxonomy':
- i18nsync_taxonomyfield($node, $source);
+ i18nsync_node_taxonomy($node, $source);
break;
default:
@@ -285,7 +285,7 @@ function i18nsync_node_translation($node, $translation, $fields, $op) {
else {
switch ($field) {
case 'taxonomy': // Do nothing it has already been syncd.
- i18nsync_taxonomyfield($translation, $node);
+ i18nsync_node_taxonomy($translation, $node);
break;
case 'parent': // Book outlines, translating parent page if exists.
@@ -339,9 +339,9 @@ function i18nsync_node_translation($node, $translation, $fields, $op) {
*
* Translate translatable terms, just copy over the rest.
*/
-function i18nsync_taxonomyfield(&$node, $source) {
- if (module_exists('i18ntaxonomy')) {
- $node->taxonomy = i18ntaxonomy_translate_terms($source->taxonomy, $node->language);
+function i18nsync_node_taxonomy(&$node, $source) {
+ if (module_exists('i18ntaxonomy') && is_array($source->taxonomy)) {
+ $node->taxonomy = i18ntaxonomy_translate_terms($source->taxonomy, $node->language, FALSE);
}
else {
// If not multilingual taxonomy enabled, just copy over.
diff --git a/i18ntaxonomy/i18ntaxonomy.module b/i18ntaxonomy/i18ntaxonomy.module
index 9d3fc4e..1136ca0 100644
--- a/i18ntaxonomy/i18ntaxonomy.module
+++ b/i18ntaxonomy/i18ntaxonomy.module
@@ -632,7 +632,6 @@ function i18ntaxonomy_nodeapi(&$node, $op, $teaser, $page) {
if (array_key_exists('taxonomy', $node)) {
$node->taxonomy = i18ntaxonomy_localize_terms($node->taxonomy);
}
-
if ($node->type == 'forum' && ($vid = variable_get('forum_nav_vocabulary', '')) && i18ntaxonomy_vocabulary($vid)) {
if ($page && taxonomy_node_get_terms_by_vocabulary($node, $vid) && $tree = taxonomy_get_tree($vid)) {
// Get the forum terms from the (cached) tree
@@ -674,20 +673,56 @@ function i18ntaxonomy_nodeapi(&$node, $op, $teaser, $page) {
* Translate an array of taxonomy terms.
*
* Translates all terms with language, just passing over terms without it.
+ * Filter out terms with a different language
+ *
+ * @param $taxonomy
+ * Array of term objects or tids or multiple arrays or terms indexed by vid
+ * @param $langcode
+ * Language code of target language
+ * @param $fullterms
+ * Whether to return full $term objects, returns tids otherwise
+ * @return
+ * Array with translated terms: tid -> $term
+ * Array with vid and term array
*/
-function i18ntaxonomy_translate_terms($taxonomy, $langcode) {
+function i18ntaxonomy_translate_terms($taxonomy, $langcode, $fullterms = TRUE) {
$translation = array();
- if (is_array($taxonomy)) {
- foreach ($taxonomy as $index => $term) {
+ if (is_array($taxonomy) && $taxonomy) {
+ foreach ($taxonomy as $index => $tdata) {
+ if (is_array($tdata)) {
+ // Case 1: Index is vid, $tdata is an array of terms
+ $mode = i18ntaxonomy_vocabulary($index);
+ // We translate just some vocabularies: translatable, fixed language
+ // Fixed language ones may have terms translated, though the UI doesn't support it
+ if ($mode == I18N_TAXONOMY_LANGUAGE || $mode == I18N_TAXONOMY_TRANSLATE) {
+ $translation[$index] = i18ntaxonomy_translate_terms($tdata, $langcode, $filter, $fullterms);
+ }
+ elseif ($fullterms) {
+ $translation[$index] = array_map('_i18ntaxonomy_filter_terms', $tdata);
+ }
+ else {
+ $translation[$index] = array_map('_i18ntaxonomy_filter_tids', $tdata);
+ }
+ continue;
+ }
+ elseif (is_object($tdata)) {
+ // Case 2: This is a term object
+ $term = $tdata;
+ }
+ else {
+ // Case 3: This is a term tid, load the full term
+ $term = taxonomy_get_term((int)$tdata);
+ }
if ($term->language && $term->language != $langcode) {
$translated_terms = i18ntaxonomy_term_get_translations(array('tid' => $term->tid));
- if ($translated_terms && $newterm = $translated_terms[$langcode]) {
- $translation[$newterm->tid] = $newterm;
+ if ($translated_terms && !empty($translated_terms[$langcode])) {
+ $newterm = $translated_terms[$langcode];
+ $translation[$newterm->tid] = $fullterms ? $newterm : $newterm->tid;
}
}
else {
// Term has no language. Should be ok.
- $translation[$index] = $term;
+ $translation[$index] = $fullterms ? $term : $term->tid;
}
}
}
@@ -944,4 +979,28 @@ function i18ntaxonomy_preprocess_forums(&$variables) {
$breadcrumb[] = l(tt("taxonomy:vocabulary:$vid:name", $vocabulary->name), 'forum');
drupal_set_breadcrumb($breadcrumb);
}
+}
+
+/**
+ * Recursive array filtering, convert all terms to 'tid'.
+ */
+function _i18ntaxonomy_filter_tids($tid) {
+ if (is_array($tid)) {
+ return array_map('_i18n_taxonomy_filter_tids', $tid);
+ }
+ else {
+ return is_object($tid) ? $tid->tid : (int)$tid;
+ }
+}
+
+/**
+ * Recursive array filtering, convert all terms to 'term object'
+ */
+function _i18ntaxonomy_filter_terms($term) {
+ if (is_array($term)) {
+ return array_map('_i18n_taxonomy_filter_terms', $term);
+ }
+ else {
+ return is_object($term) ? $term : taxonomy_get_term($term);
+ }
} \ No newline at end of file