summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Reyero2011-05-14 18:26:46 (GMT)
committer Jose Reyero2011-05-14 18:26:46 (GMT)
commit2f61b0162000fa13ac4e6a16599c40ee2322e1d7 (patch)
tree6e51d35399ec5a049f7ed1404712b4303f19412d
parent0d48680e281bf672c5b407a9c26a47dea53a4c3a (diff)
Issue #1154364 by reyero, berdir: Translation tabs
-rw-r--r--i18n_string/i18n_string.inc22
-rw-r--r--i18n_string/i18n_string.module34
-rw-r--r--i18n_string/i18n_string.pages.inc22
-rw-r--r--i18n_taxonomy/i18n_taxonomy.admin.inc10
-rw-r--r--i18n_taxonomy/i18n_taxonomy.inc38
-rw-r--r--i18n_taxonomy/i18n_taxonomy.module11
6 files changed, 100 insertions, 37 deletions
diff --git a/i18n_string/i18n_string.inc b/i18n_string/i18n_string.inc
index c93e103..d045d3e 100644
--- a/i18n_string/i18n_string.inc
+++ b/i18n_string/i18n_string.inc
@@ -692,6 +692,28 @@ class i18n_string_default {
$this->save_string($string);
}
}
+
+ /**
+ * Get edit path for object
+ *
+ * @param $type
+ * Object type in this text group, like 'vocabulary', 'term', etc..
+ * @param $object
+ * The Drupal object itself
+ */
+ public function get_edit_path($type, $object) {
+ }
+
+ /**
+ * Get translate path for object
+ *
+ * @param $type
+ * Object type in this text group, like 'vocabulary', 'term', etc..
+ * @param $object
+ * The Drupal object itself
+ */
+ public function get_translate_path($type, $object) {
+ }
}
/**
diff --git a/i18n_string/i18n_string.module b/i18n_string/i18n_string.module
index e606cd9..4f68a40 100644
--- a/i18n_string/i18n_string.module
+++ b/i18n_string/i18n_string.module
@@ -696,3 +696,37 @@ function i18n_string_object_update($type, $object) {
return i18n_string_textgroup($info['string translation']['textgroup'])->update_object($type, $object);
}
}
+
+/**
+ * Generic translation page for i18n_strings objects.
+ */
+function i18n_string_object_translate_page($object_type, $object, $langcode = NULL) {
+ $info = i18n_object_info($object_type);
+ $textgroup = i18n_string_textgroup($info['string translation']['textgroup']);
+
+ // Build the form meta from object type
+ $type = $info['string translation']['type'];
+ $form_meta = array(
+ '#page_title' => t('Translate @name', array('@name' => $info['title'])),
+ '#edit' => $textgroup->get_edit_path($type, $object),
+ '#translate' => $textgroup->get_translate_path($type, $object),
+ );
+
+ foreach ($info['string translation']['properties'] as $key => $title) {
+ if (!empty($object->{$key})) {
+ $form_meta['#items'][] = array(
+ '#title' => is_array($title) ? $title['title'] : $title,
+ '#string_key' => array($info['string translation']['textgroup'], $info['string translation']['type'], $object->{$info['key']}, $key),
+ '#default_value' => $object->{$key},
+ );
+ }
+ }
+
+ // Set the default item key, assume it's the first.
+ $default_item = reset($form_meta['#items']);
+ $form_meta['#item_title_key'] = $default_item['#string_key'];
+ $form_meta['#item_title_default'] = $default_item['#default_value'];
+
+ module_load_include('inc', 'i18n_string', 'i18n_string.pages');
+ return i18n_string_translate_page($form_meta, $langcode);
+} \ No newline at end of file
diff --git a/i18n_string/i18n_string.pages.inc b/i18n_string/i18n_string.pages.inc
index f7e254b..20756e9 100644
--- a/i18n_string/i18n_string.pages.inc
+++ b/i18n_string/i18n_string.pages.inc
@@ -15,28 +15,6 @@ function i18n_string_translate_page($form_meta, $langcode = NULL) {
'#item_title_header' => t('Title'),
);
- // If there is an object property, get the items from there.
- if (!empty($form_meta['#type']) && !empty($form_meta['#object'])) {
- $info = i18n_object_info($form_meta['#type']);
-
- foreach ($info['string translation']['properties'] as $key => $title) {
- if (!empty($form_meta['#object']->{$key})) {
- $form_meta['#items'][] = array(
- '#title' => is_array($title) ? $title['title'] : $title,
- '#string_key' => array($info['string translation']['textgroup'], $info['string translation']['type'], $form_meta['#object']->{$info['key']}, $key),
- '#default_value' => $form_meta['#object']->{$key},
- );
- }
- }
- }
-
- // If not set, assume that the default item is the first one.
- if ((empty($form_meta['#item_title_key']))) {
- $default_item = reset($form_meta['#items']);
- $form_meta['#item_title_key'] = $default_item['#string_key'];
- $form_meta['#item_title_default'] = $default_item['#default_value'];
- }
-
if (empty($langcode)) {
drupal_set_title($form_meta['#page_title']);
return i18n_string_translate_page_overview($form_meta);
diff --git a/i18n_taxonomy/i18n_taxonomy.admin.inc b/i18n_taxonomy/i18n_taxonomy.admin.inc
index d6e7c2b..9211878 100644
--- a/i18n_taxonomy/i18n_taxonomy.admin.inc
+++ b/i18n_taxonomy/i18n_taxonomy.admin.inc
@@ -42,15 +42,7 @@ function i18n_taxonomy_term_translation_tab_page($term, $language = NULL) {
return $translation_overview += $translation_term_form;
}
elseif (i18n_taxonomy_vocabulary_mode($term->vid, I18N_MODE_LOCALIZE)) {
- module_load_include('inc', 'i18n_string', 'i18n_string.pages');
- $form_meta = array(
- '#page_title' => t('Translate term'),
- '#edit' => 'taxonomy/term/' . $term->tid . '/edit',
- '#translate' => 'taxonomy/term/' . $term->tid . '/translate',
- '#type' => 'taxonomy_term',
- '#object' => $term,
- );
- return i18n_string_translate_page($form_meta, $language);
+ return i18n_string_object_translate_page('taxonomy_term', $term, $language);
}
}
diff --git a/i18n_taxonomy/i18n_taxonomy.inc b/i18n_taxonomy/i18n_taxonomy.inc
index c3ad30f..c08de9f 100644
--- a/i18n_taxonomy/i18n_taxonomy.inc
+++ b/i18n_taxonomy/i18n_taxonomy.inc
@@ -10,4 +10,42 @@ class i18n_taxonomy_translation_set extends i18n_translation_set {
public function load_translations() {
return i18n_translation_set_index(taxonomy_term_load_multiple(array(), array('i18n_tsid' => $this->tsid)));
}
+}
+
+/**
+ * Taxonomy textgroup handler
+ */
+class i18n_taxonomy_textgroup extends i18n_string_default {
+ /**
+ * Get edit path for object
+ *
+ * @param $type
+ * Object type in this text group, like 'vocabulary', 'term', etc..
+ * @param $object
+ * The Drupal object itself
+ */
+ public function get_edit_path($type, $object) {
+ switch ($type) {
+ case 'term':
+ return 'taxonomy/term/' . $object->tid . '/edit';
+ case 'vocabulary':
+ return 'admin/structure/taxonomy/' . $object->machine_name . '/edit';
+ }
+ }
+ /**
+ * Get translate path for object
+ *
+ * @param $type
+ * Object type in this text group, like 'vocabulary', 'term', etc..
+ * @param $object
+ * The Drupal object itself
+ */
+ public function get_translate_path($type, $object) {
+ switch ($type) {
+ case 'term':
+ return 'taxonomy/term/' . $object->tid . '/translate';
+ case 'vocabulary':
+ return 'admin/structure/taxonomy/' . $object->machine_name . '/translate';
+ }
+ }
} \ No newline at end of file
diff --git a/i18n_taxonomy/i18n_taxonomy.module b/i18n_taxonomy/i18n_taxonomy.module
index abc9b07..a00f226 100644
--- a/i18n_taxonomy/i18n_taxonomy.module
+++ b/i18n_taxonomy/i18n_taxonomy.module
@@ -72,22 +72,20 @@ function _i18n_taxonomy_vocabulary_options() {
function i18n_taxonomy_menu() {
$items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/translate'] = array(
'title' => 'Translate',
- 'page callback' => 'i18n_taxonomy_translation_vocabulary_page',
- 'page arguments' => array(3),
+ 'page callback' => 'i18n_string_object_translate_page',
+ 'page arguments' => array('taxonomy_vocabulary', 3),
'access callback' => 'i18n_taxonomy_vocabulary_translation_tab_access',
'access arguments' => array(3),
'type' => MENU_LOCAL_TASK,
- //'parent' => 'admin/content/taxonomy/%taxonomy_vocabulary',
- 'file' => 'i18n_taxonomy.admin.inc',
);
$items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/translate/%language'] = array(
'title' => 'Translate',
- 'page callback' => 'i18n_taxonomy_translation_vocabulary_page',
+ 'page callback' => 'i18n_string_object_translate_page',
+ 'page arguments' => array('taxonomy_vocabulary', 3, 5),
'page arguments' => array(3, 5),
'access callback' => 'i18n_taxonomy_vocabulary_translation_tab_access',
'access arguments' => array(3),
'type' => MENU_CALLBACK,
- 'file' => 'i18n_taxonomy.admin.inc',
);
$items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/list/list'] = array(
'title' => 'Terms',
@@ -431,6 +429,7 @@ function i18n_taxonomy_i18n_string_info() {
'format' => FALSE, // This group doesn't have strings with format
'list' => FALSE, // This group cannot list all strings
'refresh callback' => 'i18n_taxonomy_i18n_string_refresh',
+ 'class' => 'i18n_taxonomy_textgroup',
);
return $groups;
}