*/
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() {
/**
* 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
/**
* 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
'title' => t('Title'),
'description' => t('Description'),
),
- 'translate path' => 'admin/structure/menu/manage/%menu/translate/%language',
),
'translation container' => array(
'name' => t('menu'),
'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',
* 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'));
}
/**
}
/**
+ * 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) {
/**
* 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);
+ }
}
/**
'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(
);
$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(
*/
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() {
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