summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Reyero2011-05-14 11:00:36 (GMT)
committer Jose Reyero2011-05-14 11:00:36 (GMT)
commit587f7c6d646ae403a948253dcce9f64bdedc94b6 (patch)
treefb53c038819ee17edd038374aba2735e4acc7ef8
parent8e80dab25bd9355a3c3cca50af1303051d3c2cae (diff)
Issue #1154364 by Berdir: Add consistent translation tab for objects
-rw-r--r--i18n_string/i18n_string.pages.inc22
-rw-r--r--i18n_taxonomy/i18n_taxonomy.admin.inc34
2 files changed, 26 insertions, 30 deletions
diff --git a/i18n_string/i18n_string.pages.inc b/i18n_string/i18n_string.pages.inc
index 20756e9..f7e254b 100644
--- a/i18n_string/i18n_string.pages.inc
+++ b/i18n_string/i18n_string.pages.inc
@@ -15,6 +15,28 @@ 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 0f26500..d6e7c2b 100644
--- a/i18n_taxonomy/i18n_taxonomy.admin.inc
+++ b/i18n_taxonomy/i18n_taxonomy.admin.inc
@@ -45,24 +45,11 @@ function i18n_taxonomy_term_translation_tab_page($term, $language = NULL) {
module_load_include('inc', 'i18n_string', 'i18n_string.pages');
$form_meta = array(
'#page_title' => t('Translate term'),
- '#item_title_key' => array('taxonomy', 'term', $term->tid, 'name'),
- '#item_title_default' => $term->name,
'#edit' => 'taxonomy/term/' . $term->tid . '/edit',
'#translate' => 'taxonomy/term/' . $term->tid . '/translate',
- '#items' => array(),
+ '#type' => 'taxonomy_term',
+ '#object' => $term,
);
- $form_meta['#items'][] = array(
- '#title' => t('Name'),
- '#string_key' => array('taxonomy', 'term', $term->tid, 'name'),
- '#default_value' => $term->name,
- );
- if (!empty($term->description)) {
- $form_meta['#items'][] = array(
- '#title' => t('Description'),
- '#string_key' => array('taxonomy', 'term', $term->tid, 'description'),
- '#default_value' => $term->description
- );
- }
return i18n_string_translate_page($form_meta, $language);
}
}
@@ -306,23 +293,10 @@ function i18n_taxonomy_translation_vocabulary_page($vocabulary, $language = NULL
module_load_include('inc', 'i18n_string', 'i18n_string.pages');
$form_meta = array(
'#page_title' => t('Translate vocabulary'),
- '#item_title_key' => array('taxonomy', 'vocabulary', $vocabulary->vid, 'name'),
- '#item_title_default' => $vocabulary->name,
'#edit' => 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/edit',
'#translate' => 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/translate',
- '#items' => array(),
+ '#type' => 'taxonomy_vocabulary',
+ '#object' => $vocabulary,
);
- $form_meta['#items'][] = array(
- '#title' => t('Name'),
- '#string_key' => array('taxonomy', 'vocabulary', $vocabulary->vid, 'name'),
- '#default_value' => $vocabulary->name,
- );
- if (!empty($vocabulary->description)) {
- $form_meta['#items'][] = array(
- '#title' => t('Description'),
- '#string_key' => array('taxonomy', 'vocabulary', $vocabulary->vid, 'description'),
- '#default_value' => $vocabulary->description
- );
- }
return i18n_string_translate_page($form_meta, $language);
}