summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--i18n_block/i18n_block.inc28
-rw-r--r--i18n_field/i18n_field.inc8
-rw-r--r--i18n_menu/i18n_menu.i18n.inc2
-rw-r--r--i18n_object.inc26
-rw-r--r--i18n_string/i18n_string.inc19
-rw-r--r--i18n_taxonomy/i18n_taxonomy.i18n.inc5
-rw-r--r--i18n_taxonomy/i18n_taxonomy.inc30
7 files changed, 38 insertions, 80 deletions
diff --git a/i18n_block/i18n_block.inc b/i18n_block/i18n_block.inc
index 6f09e46..1c7e8ac 100644
--- a/i18n_block/i18n_block.inc
+++ b/i18n_block/i18n_block.inc
@@ -8,34 +8,6 @@
*/
class i18n_block_object extends i18n_string_object {
/**
- * Get base path for object
- */
- protected function get_base_path() {
- return 'admin/structure/block/manage/' . $this->object->module . '/' . $this->object->delta;
- }
- /**
- * 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() {
- return $this->get_base_path() . '/configure';
- }
- /**
- * 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($language = NULL) {
- return $this->get_base_path() . '/translate' . ($language ? '/' . $language->language : '');
- }
- /**
* Get base keys for translating this object
*/
public function get_string_context() {
diff --git a/i18n_field/i18n_field.inc b/i18n_field/i18n_field.inc
index 339c564..b944939 100644
--- a/i18n_field/i18n_field.inc
+++ b/i18n_field/i18n_field.inc
@@ -22,8 +22,8 @@ class i18n_field extends i18n_string_object {
/**
* Get translate path for object
*/
- public function get_translate_path($language = NULL) {
- return $this->get_edit_path() . '/translate/field' . ($language ? '/' . $language->language : '');
+ public function get_translate_path($langcode = NULL) {
+ return $this->get_edit_path() . '/translate/field' . ($langcode ? '/' . $$langcode : '');
}
/**
* Get string context
@@ -69,8 +69,8 @@ class i18n_field_instance extends i18n_string_object {
/**
* Get translate path for object
*/
- public function get_translate_path($language = NULL) {
- return $this->get_edit_path() . '/translate/instance' . ($language ? '/' . $language->language : '');
+ public function get_translate_path($langcode = NULL) {
+ return $this->get_edit_path() . '/translate/instance' . ($langcode ? '/' . $$langcode : '');
}
/**
* Get string context
diff --git a/i18n_menu/i18n_menu.i18n.inc b/i18n_menu/i18n_menu.i18n.inc
index 245ec6a..a92b379 100644
--- a/i18n_menu/i18n_menu.i18n.inc
+++ b/i18n_menu/i18n_menu.i18n.inc
@@ -25,7 +25,6 @@ function i18n_menu_i18n_object_info() {
'title' => t('Title'),
'description' => t('Description'),
),
- 'translate path' => 'admin/structure/menu/manage/%menu/translate/%language',
),
'translation container' => array(
'name' => t('menu'),
@@ -53,7 +52,6 @@ function i18n_menu_i18n_object_info() {
'title' => t('Title'),
'description' => t('Description'),
),
- 'translate path' => 'admin/structure/menu/item/%menu_link/translate/%language',
),
'translation set' => array(
'class' => 'i18n_menu_link_translation_set',
diff --git a/i18n_object.inc b/i18n_object.inc
index 4afc2f4..2588d5e 100644
--- a/i18n_object.inc
+++ b/i18n_object.inc
@@ -19,12 +19,7 @@ class i18n_object_wrapper {
* Get edit path for object
*/
function get_edit_path() {
- if ($path = $this->get_info('edit path')) {
- return strtr($path, $this->get_placeholders());
- }
- else {
- return NULL;
- }
+ return $this->path_replace($this->get_info('edit path'));
}
/**
@@ -122,6 +117,25 @@ class i18n_object_wrapper {
}
/**
+ * Replace path with placeholders
+ *
+ * @param $path
+ * Path to replace
+ * @param $replacements
+ * Replacement variables to override or add to placeholders
+ */
+ protected function path_replace($path, $replacements = array()) {
+ if ($path) {
+ $path = strtr($path, $replacements + $this->get_placeholders());
+ // Clean up duplicated and final '/' (empty placeholders)
+ $path = strtr($path, array('//' => '/'));
+ return trim($path, '/');
+ }
+ else {
+ return '';
+ }
+ }
+ /**
* Get object info
*/
public function get_info($property) {
diff --git a/i18n_string/i18n_string.inc b/i18n_string/i18n_string.inc
index fa3b47f..ae4c07b 100644
--- a/i18n_string/i18n_string.inc
+++ b/i18n_string/i18n_string.inc
@@ -739,17 +739,18 @@ class i18n_string_object extends i18n_object_wrapper {
/**
* Get translate path for object
*
- * @param $type
- * Object type in this text group, like 'vocabulary', 'term', etc..
- * @param $object
- * The Drupal object itself
+ * @param $langcode
+ * Language code if we want ti for a specific language
*/
- public function get_translate_path($language = NULL) {
+ public function get_translate_path($langcode = NULL) {
+ $replacements = array('%language' => $langcode ? $langcode : '');
if ($path = $this->get_string_info('translate path')) {
- $replace = $this->get_placeholders();
- $replace['%language'] = $language ? $language->language : '';
- return trim(strtr($path, $replace), '/');
- }
+ return $this->path_replace($path, $replacements);
+ }
+ elseif ($path = $this->get_info('translate tab')) {
+ // If we've got a translate tab path, we just add language to it
+ return $this->path_replace($path . '/%language', $replacements);
+ }
}
/**
diff --git a/i18n_taxonomy/i18n_taxonomy.i18n.inc b/i18n_taxonomy/i18n_taxonomy.i18n.inc
index f5473ee..497e87b 100644
--- a/i18n_taxonomy/i18n_taxonomy.i18n.inc
+++ b/i18n_taxonomy/i18n_taxonomy.i18n.inc
@@ -16,6 +16,8 @@ function i18n_taxonomy_i18n_object_info() {
'placeholders' => array(
'%taxonomy_term' => 'tid',
),
+ // Auto generate edit path
+ 'edit path' => 'taxonomy/term/%taxonomy_term/edit',
// Auto-generate translate tab
'translate tab' => 'taxonomy/term/%taxonomy_term/translate',
'translation set' => array(
@@ -43,12 +45,13 @@ function i18n_taxonomy_i18n_object_info() {
);
$info['taxonomy_vocabulary'] = array(
'title' => t('Vocabulary'),
- 'class' => 'i18n_taxonomy_vocabulary',
'entity' => 'taxonomy_vocabulary',
'key' => 'vid',
'placeholders' => array(
'%taxonomy_vocabulary_machine_name' => 'machine_name',
),
+ // Auto generate edit path
+ 'edit path' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/edit',
// Auto-generate translate tab
'translate tab' => 'admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/translate',
'string translation' => array(
diff --git a/i18n_taxonomy/i18n_taxonomy.inc b/i18n_taxonomy/i18n_taxonomy.inc
index 8102c26..0da29d6 100644
--- a/i18n_taxonomy/i18n_taxonomy.inc
+++ b/i18n_taxonomy/i18n_taxonomy.inc
@@ -31,18 +31,6 @@ class i18n_taxonomy_translation_set extends i18n_translation_set {
*/
class i18n_taxonomy_term extends i18n_string_object {
/**
- * Get edit path for object
- */
- public function get_edit_path() {
- return 'taxonomy/term/' . $this->object->tid . '/edit';
- }
- /**
- * Get translate path for object
- */
- public function get_translate_path($language = NULL) {
- return 'taxonomy/term/' . $this->object->tid . '/translate' . ($language ? '/' . $language->language : '');
- }
- /**
* Translation mode for object
*/
public function get_translate_mode() {
@@ -61,21 +49,3 @@ class i18n_taxonomy_term extends i18n_string_object {
return taxonomy_term_edit_access($this->object) && $this->get_langcode() && user_access('translate interface');
}
}
-
-/**
- * Taxonomy textgroup handler
- */
-class i18n_taxonomy_vocabulary extends i18n_string_object {
- /**
- * Get edit path for object
- */
- public function get_edit_path() {
- return 'admin/structure/taxonomy/' . $this->object->machine_name . '/edit';
- }
- /**
- * Get translate path for object
- */
- public function get_translate_path($language = NULL) {
- return 'admin/structure/taxonomy/' . $this->object->machine_name . '/translate' . ($language ? '/' . $language->language : '');
- }
-} \ No newline at end of file