From 4c275b9d124a15c577a8cfb4c269ce4b8ab25604 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 23 Apr 2011 17:59:24 +0200
Subject: [PATCH] Issue #1115956 by Berdir: Added reversed and capitalized
 relationship type names.

---
 tests/user_relationships.api.test                  |   52 +++++
 .../templates/user_relationships-block.tpl.php     |   10 +-
 .../user_relationships-pending_block.tpl.php       |    8 +-
 .../user_relationship_blocks.module                |   16 +-
 .../user_relationship_defaults.module              |   11 +-
 .../user_relationship_implications.module          |    9 +-
 .../user_relationship_invites.module               |    2 +-
 .../user_relationship_node_access.module           |    6 +-
 .../user_relationship_privatemsg.module            |    4 +-
 .../user_relationship_views.module                 |    2 +-
 user_relationships.admin.inc                       |  193 +++++++++++++-----
 user_relationships.author-pane.inc                 |    8 +-
 user_relationships.install                         |   74 +++++++-
 user_relationships.module                          |  212 ++++++++++++++-----
 .../user_relationships_ui.forms.inc                |   24 +--
 user_relationships_ui/user_relationships_ui.module |   27 ++-
 .../user_relationships_ui.pages.inc                |    8 +-
 .../user_relationships_ui.theme.inc                |    2 +-
 18 files changed, 486 insertions(+), 182 deletions(-)

diff --git a/tests/user_relationships.api.test b/tests/user_relationships.api.test
index 3626106..0d57451 100644
--- a/tests/user_relationships.api.test
+++ b/tests/user_relationships.api.test
@@ -278,3 +278,55 @@ class UserRelationshipsTestCase extends DrupalWebTestCase {
     $this-> assertFalse($rtype->is_reciprocal);
   }
 }
+
+/**
+ * User Relationship type tests.
+ */
+class UserRelationshipsTypesTestCase extends DrupalWebTestCase {
+
+  /**
+   * Implements getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('User Relationships Types'),
+      'description' => t('Checks various user relationship types functions.'),
+      'group' => t('User Relationships'),
+    );
+  }
+
+  /**
+   * Enable modules.
+   */
+  function setUp() {
+    parent::setUp('user_relationships');
+  }
+
+  function testNames() {
+    // Create relationship type.
+    $relationship_type = (object)array(
+      'name' => $this->randomName(),
+      'plural_name' => $this->randomName(),
+      'reverse_name' => $this->randomName(),
+      'reverse_plural_name' => $this->randomName(),
+      'name_capitalized' => $this->randomName(),
+      'plural_name_capitalized' => $this->randomName(),
+      'reverse_name_capitalized' => $this->randomName(),
+      'reverse_plural_name_capitalized' => $this->randomName(),
+      'requires_approval' => FALSE,
+      'expires_val' => 0,
+    );
+
+    // First, check all names.
+    $this->assertEqual($relationship_type->name, user_relationships_type_get_name($relationship_type));
+    $this->assertEqual($relationship_type->plural_name, user_relationships_type_get_name($relationship_type, TRUE));
+    $this->assertEqual($relationship_type->reverse_name, user_relationships_type_get_name($relationship_type, FALSE, TRUE));
+    $this->assertEqual($relationship_type->reverse_plural_name, user_relationships_type_get_name($relationship_type, TRUE, TRUE));
+    $this->assertEqual($relationship_type->name_capitalized, user_relationships_type_get_name($relationship_type, FALSE, FALSE, TRUE));
+    $this->assertEqual($relationship_type->plural_name_capitalized, user_relationships_type_get_name($relationship_type, TRUE, FALSE, TRUE));
+    $this->assertEqual($relationship_type->reverse_name_capitalized, user_relationships_type_get_name($relationship_type, FALSE, TRUE, TRUE));
+    $this->assertEqual($relationship_type->reverse_plural_name_capitalized, user_relationships_type_get_name($relationship_type, TRUE, TRUE, TRUE));
+
+    // @todo: Test fallback strategy.
+  }
+}
diff --git a/user_relationship_blocks/templates/user_relationships-block.tpl.php b/user_relationship_blocks/templates/user_relationships-block.tpl.php
index 25a0449..88b25f8 100644
--- a/user_relationship_blocks/templates/user_relationships-block.tpl.php
+++ b/user_relationship_blocks/templates/user_relationships-block.tpl.php
@@ -8,16 +8,16 @@ if ($relationships) {
   $showing_all_types = $settings->rtid == UR_BLOCK_ALL_TYPES;
   $rows = array();
   foreach ($relationships as $rtid => $relationship) {
-    $tt_rel_name = ur_tt("user_relationships:rtid:$rtid:name", $relationship->name);
-    $tt_rel_plural_name = ur_tt("user_relationships:rtid:$rtid:plural_name", $relationship->plural_name); 
+    $tt_rel_name = user_relationships_type_get_name($relationship);
+    $tt_rel_plural_name = user_relationships_type_get_name($relationship, TRUE);
     if ($the_other_uid == $relationship->requester_id) {
       $rtype_heading = $relationship->is_oneway ? 
-        t("@rel_name of", array('@rel_name' => $tt_rel_name, '@rel_plural_name' => $tt_rel_plural_name)) : 
-        t("@rel_plural_name", array('@rel_name' => $tt_rel_name, '@rel_plural_name' => $tt_rel_plural_name));
+        t("@rel_name of", user_relationships_type_translations($relationship)) :
+        t("@rel_plural_name", user_relationships_type_translations($relationship));
       $relatee = $relationship->requestee;
     }
     else {
-      $rtype_heading = t("@rel_plural_name", array('@rel_name' => $tt_rel_name, '@rel_plural_name' => $tt_rel_plural_name));
+      $rtype_heading = t("@rel_plural_name", user_relationships_type_translations($relationship));
       $relatee = $relationship->requester;
     }
 
diff --git a/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php b/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php
index 383add5..5b046e1 100644
--- a/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php
+++ b/user_relationship_blocks/templates/user_relationships-pending_block.tpl.php
@@ -7,12 +7,12 @@
 if ($relationships) {
   $list = array();
   foreach ($relationships as $rtid => $relationship) {
-    $tt_rel_name = ur_tt("user_relationships:rtid:$rtid:name", $relationship->name);
-    $tt_rel_plural_name = ur_tt("user_relationships:rtid:$rtid:plural_name", $relationship->plural_name);
+    $tt_rel_name = user_relationships_type_get_name($relationship);
+    $tt_rel_plural_name = user_relationships_type_get_name($relationship, TRUE);
     if ($user->uid == $relationship->requester_id) {
       $relation_to =& $relationship->requestee;
       $controls = theme('user_relationships_pending_request_cancel_link', array('uid' => $account->uid, 'rid' => $relationship->rid));
-      $line = t('@rel_name to !username (!controls)', array('@rel_name' => $tt_rel_name, '!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls));
+      $line = t('@rel_name to !username (!controls)', array('!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls) + user_relationships_type_translations($relationship));
       $key = t('Sent requests');
     }
     else {
@@ -20,7 +20,7 @@ if ($relationships) {
       $controls =
         theme('user_relationships_pending_request_approve_link', array('uid' => $account->uid, 'rid' => $relationship->rid)).'|'.
         theme('user_relationships_pending_request_disapprove_link', array('uid' => $account->uid, 'rid' => $relationship->rid));
-      $line = t('@rel_name from !username (!controls)', array('@rel_name' => $tt_rel_name, '!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls));
+      $line = t('@rel_name from !username (!controls)', array('!username' => theme('username', array('account' => $relation_to)), '!controls' => $controls) + user_relationships_type_translations($relationship));
       $key = t('Received requests');
     }
     $list[$key][] = $line;
diff --git a/user_relationship_blocks/user_relationship_blocks.module b/user_relationship_blocks/user_relationship_blocks.module
index 6318851..77432e9 100644
--- a/user_relationship_blocks/user_relationship_blocks.module
+++ b/user_relationship_blocks/user_relationship_blocks.module
@@ -81,10 +81,10 @@ function theme_user_relationship_block_subject($variables) {
     global $user;
     $rtype = user_relationships_type_load($rtid);
     if ($account->uid == $user->uid) {
-      return t('I am a @rel_name of', array('@rel_name' => ur_tt("user_relationships:rtid:$rtid:name", $rtype->name), '@rel_plural_name' => $rtype->plural_name));
+      return t('I am a @rel_name of', user_relationships_type_translations($rtype));
     }
     else {
-      return t('@username is a @rel_name of', array('@username' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$rtid:name", $rtype->name), '@rel_plural_name' => $rtype->plural_name));
+      return t('@username is a @rel_name of', array('@username' => format_username($account)) + user_relationships_type_translations($rtype));
     }
   }
   else {
@@ -95,8 +95,8 @@ function theme_user_relationship_block_subject($variables) {
     else {
       $rtype = user_relationships_type_load($rtid);
       $output = ($account->uid == $user->uid)
-                ? t('My @relationships', array('@relationships' => ur_tt("user_relationships:rtid:$rtid:plural_name", $rtype->plural_name)))
-                : t("@username's @relationships", array('@username' => format_username($account), '@relationships' => ur_tt("user_relationships:rtid:$rtid:plural_name", $rtype->plural_name)));
+                ? t('My @rel_name', user_relationships_type_translations($rtype))
+                : t("@username's @rel_name", array('@username' => format_username($account)) + user_relationships_type_translations($rtype));
     }
     return $output;
   }
@@ -139,7 +139,7 @@ function user_relationship_blocks_block_configure($delta) {
     }
     else {
       $type = user_relationships_type_load($rtid);
-      $relationship_name = ur_tt("user_relationships:rtid:$rtid:name", $type->name);
+      $relationship_name = user_relationships_type_get_name($type);
     }
 
     $form['size'] = array(
@@ -156,7 +156,7 @@ function user_relationship_blocks_block_configure($delta) {
     );
 
     $user_identifier = ($block == UR_BLOCK_MY) ? t('currently logged in user') : t('author whose node is being viewed');
-    $msg = t("NOTE: This block displays @relationship_name relationships of the @user_identifier.", array('@relationship_name' => ur_tt("user_relationships:rtid:$rtid:name", $relationship_name), '@user_identifier' => $user_identifier));
+    $msg = t("NOTE: This block displays @rel_name relationships of the @user_identifier.", array('@rel_name' => $relationship_name, '@user_identifier' => $user_identifier));
 
     if ($extra) {
       $relation = $extra == 'you_to_them' ? t('requester') : t('requestee');
@@ -290,8 +290,8 @@ function user_relationship_blocks_block_info() {
 
     foreach ($extras as $token => $extra) {
       $block_types = array(
-        "{$my_delta}{$token}"   => t('My Relationships: @type @extra', array('@type' => $type->plural_name, '@extra' => $extra)),
-        "{$usr_delta}{$token}"  => t('User Relationships: @type @extra', array('@type' => $type->plural_name, '@extra' => $extra)),
+        "{$my_delta}{$token}"   => t('My Relationships: @rel_name_plural @extra', array('@extra' => $extra) + user_relationships_type_translations($type)),
+        "{$usr_delta}{$token}"  => t('User Relationships: @rel_name_plural @extra', array('@extra' => $extra) + user_relationships_type_translations($type)),
       );
       foreach ($block_types as $bid => $title) {
         $blocks[$bid] = array(
diff --git a/user_relationship_defaults/user_relationship_defaults.module b/user_relationship_defaults/user_relationship_defaults.module
index 49290dd..f580ac1 100644
--- a/user_relationship_defaults/user_relationship_defaults.module
+++ b/user_relationship_defaults/user_relationship_defaults.module
@@ -175,7 +175,7 @@ function user_relationship_defaults_add_form_submit($form, &$form_state) {
 
   $message_p = array(
     '%username'           => $user->name,
-    '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name),
+    '%relationship_name'  => user_relationships_type_get_name($relationship_type),
   );
   drupal_set_message(t('Default relationship %relationship_name of %username has been added.', $message_p));
   watchdog('u_relationship', 'Default relationship %relationship_name of %username has been added.', $message_p, WATCHDOG_NOTICE, l(t('view'), 'admin/config/people/relationships'));
@@ -195,10 +195,7 @@ function user_relationship_defaults_delete_form($form, &$form_state, $default_re
 
   $form = confirm_form(
     $form,
-    t('Are you sure you want to delete the default relationship %relationship of %name?', array(
-      '%relationship' => ur_tt('user_relationships:rtid:' . $default_relationship->relationship_type->rtid . ':name', $default_relationship->relationship_type->name),
-      '%name'         => $default_relationship->user->name,
-    )),
+    t('Are you sure you want to delete the default relationship %rel_name of %name?', array('%name' => $default_relationship->user->name) + user_relationships_type_translations($default_relationship)),
     'admin/config/people/relationships',
     t('This action cannot be undone.'),
     t('Delete'), t('Cancel')
@@ -218,7 +215,7 @@ function user_relationship_defaults_delete_form_submit($form, &$form_state) {
     ->execute();
   $message_p = array(
     '%name'         => $default_relationship->user_name,
-    '%relationship' => ur_tt("user_relationships:rtid:$default_relationship->rtid:name", $default_relationship->name),
+    '%relationship' => user_relationships_type_get_name($default_relationship),
   );
   drupal_set_message(t('Default relationship %relationship of %name has been deleted.', $message_p));
   watchdog('u_relationship', 'Default relationship %relationship of %name has been deleted.', $message_p, WATCHDOG_NOTICE);
@@ -264,7 +261,7 @@ function user_relationship_defaults_user_relationships_types_list_alter(&$page)
   $default_rows = array();
   foreach ($defaults as $default) {
     $default_rows[] = array(
-      $default->relationship_type->name,
+      user_relationships_type_get_name($default->relationship_type),
       theme('username', array('account' => $default->user)),
       l(t('delete'), "admin/config/people/relationships/defaults/{$default->rdid}/delete"),
     );
diff --git a/user_relationship_implications/user_relationship_implications.module b/user_relationship_implications/user_relationship_implications.module
index b08d25d..14c9478 100644
--- a/user_relationship_implications/user_relationship_implications.module
+++ b/user_relationship_implications/user_relationship_implications.module
@@ -50,7 +50,7 @@ function user_relationship_implications_form_user_relationships_admin_type_edit_
     if (!isset($relationship_type) || $type->rtid != $relationship_type->rtid && !in_array($type->rtid, $implied_by)) {
       $imp_name = "implies_{$type->rtid}";
       $form['implications']['opts'][$type->rtid][$imp_name] = array(
-        '#title'          => t('@type_name', array('@type_name' => $type->name)),
+        '#title'          => t('@rel_name', user_relationships_type_translations($type)),
         '#type'           => 'checkbox',
         '#return_value'   => $type->rtid,
         '#default_value'  => isset($form['#post'][$imp_name]) || isset($values[$type->rtid]),
@@ -321,10 +321,7 @@ function theme_user_relationship_implications_page($variables) {
 
   $output .= theme('pager');
 
-  drupal_set_title(t("%username's %relationships", array(
-    '%username' => $viewed_user->name,
-    '%relationships' => $relationship->plural_name ? $relationship->plural_name : t('relationships')
-  )));
+  drupal_set_title(t("%username's @rel_name_plural", array('%username' => format_username($viewed_user)) + user_relationships_type_translations($relationship)));
 
   return $output;
 }
@@ -336,7 +333,7 @@ function _user_relationship_implications_load_relationship_names($relationships,
   $output = array();
   foreach ($relationships as $relationship) {
     if ($relationship->requester_id == $uid || $relationship->requestee_id == $uid) {
-      $output[] = $relationship->name;
+      $output[] = user_relationships_type_get_name($relationship);
     }
   }
   return $output;
diff --git a/user_relationship_invites/user_relationship_invites.module b/user_relationship_invites/user_relationship_invites.module
index c38374d..26ced71 100644
--- a/user_relationship_invites/user_relationship_invites.module
+++ b/user_relationship_invites/user_relationship_invites.module
@@ -83,7 +83,7 @@ function user_relationship_invites_form_user_register_form_alter(&$form, &$form_
     if (!$relationship_type->is_oneway || $relationship_type->requires_approval) {
       $form['relationship_invite_approve'] = array(
         '#type' => 'radios',
-        '#title' => t('Please confirm the %relationship_name request from !name', array('!name' => theme('username', array('account' => $inviter)), '%relationship_name' => $relationship_type->name)),
+        '#title' => t('Please confirm the @rel_name request from !name', array('!name' => theme('username', array('account' => $inviter))) + user_relationships_type_translations($relationship_type)),
         '#default_value' => 'approve',
         '#options' => array(
           'approve' => t('Yes'),
diff --git a/user_relationship_node_access/user_relationship_node_access.module b/user_relationship_node_access/user_relationship_node_access.module
index 991e6c1..37318e5 100644
--- a/user_relationship_node_access/user_relationship_node_access.module
+++ b/user_relationship_node_access/user_relationship_node_access.module
@@ -100,11 +100,11 @@ function user_relationship_node_access_form_node_form_alter(&$form, &$form_state
   foreach ($types as $rtid => $type) {
     unset($types[$rtid]);
     if ($type->is_oneway) {
-      $types["{$rtid}_yt"] = t('Post to @type (you to them)', array('@type' => $type->plural_name));
-      $types["{$rtid}_ty"] = t('Post to @type (them to you)', array('@type' => $type->plural_name));
+      $types["{$rtid}_yt"] = t('Post to @rel_name', user_relationships_type_translations($type));
+      $types["{$rtid}_ty"] = t('Post to @rel_name_reverse', user_relationships_type_translations($type));
     }
     else {
-      $types[$rtid] = t('Post to @type', array('@type' => $type->plural_name));
+      $types[$rtid] = t('Post to @rel_name', user_relationships_type_translations($type));
     }
   }
   asort($types);
diff --git a/user_relationship_privatemsg/user_relationship_privatemsg.module b/user_relationship_privatemsg/user_relationship_privatemsg.module
index 74980cf..2c2a709 100644
--- a/user_relationship_privatemsg/user_relationship_privatemsg.module
+++ b/user_relationship_privatemsg/user_relationship_privatemsg.module
@@ -83,9 +83,9 @@ function theme_user_relationship_privatemsg_format($variables) {
 
   if ($relationship->account->uid == $user->uid) {
 
-    return t('your <a href="@url">%relationship</a>', array('%relationship' => $relationship->plural_name, '@url' => url('relationships/' . $relationship->rtid)));
+    return t('your <a href="@url">@rel_name_plural</a>', array('@url' => url('relationships/' . $relationship->rtid)) + user_relationships_type_translations($relationship));
   }
-  $name = t('%relationship of @username', array('%relationship' => $relationship->plural_name, '@username' => format_username($relationship->account)));
+  $name = t('@rel_name_plural of @username', array('@username' => format_username($relationship->account)) + user_relationships_type_translations($relationship));
   if (user_relationships_ui_check_access(array('user'), $relationship->account)) {
     return l($name, 'user/' . $relationship->account->uid . '/relationships/' . $relationship->rtid, array('html' => TRUE));
   }
diff --git a/user_relationship_views/user_relationship_views.module b/user_relationship_views/user_relationship_views.module
index 33b8215..254d446 100644
--- a/user_relationship_views/user_relationship_views.module
+++ b/user_relationship_views/user_relationship_views.module
@@ -53,7 +53,7 @@ function user_relationship_views_ajax_autocomplete_relationships_type($string =
         if (strpos($rtype->name, ',') !== FALSE || strpos($rtype->name, '"') !== FALSE) {
           $n = '"'. str_replace('"', '""', $rtype->name) .'"';
         }
-        $matches[$prefix . $n] = check_plain(ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name));
+        $matches[$prefix . $n] = check_plain(user_relationships_type_get_name($rtype));
       }
     }
   }
diff --git a/user_relationships.admin.inc b/user_relationships.admin.inc
index a031e34..2ec114b 100644
--- a/user_relationships.admin.inc
+++ b/user_relationships.admin.inc
@@ -155,12 +155,6 @@ function user_relationships_admin_settings() {
 function user_relationships_admin_type_edit($form, &$form_state, $relationship_type = NULL) {
   if (!$relationship_type) {
     drupal_set_title(t('Add relationship type'));
-    $relationship_type = (object) array(
-      'name' => '',
-      'plural_name' => '',
-      'is_oneway' => FALSE,
-      'is_reciprocal' => FALSE,
-    );
   }
   else {
     drupal_set_title(t('Edit @name relationship type', array('@name' => $relationship_type->name)));
@@ -179,15 +173,6 @@ function user_relationships_admin_type_edit($form, &$form_state, $relationship_t
     '#required'       => TRUE,
     '#weight'         => -10,
   );
-  $form['plural_name'] = array(
-    '#type'           => 'textfield',
-    '#title'          => t('Plural name'),
-    '#maxlength'      => 255,
-    '#default_value'  => isset($relationship_type) ? $relationship_type->plural_name : NULL,
-    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
-    '#required'       => TRUE,
-    '#weight'         => -9,
-  );
   $form['requires_approval'] = array(
     '#type'           => 'checkbox',
     '#title'          => t('Requires Approval'),
@@ -229,6 +214,91 @@ function user_relationships_admin_type_edit($form, &$form_state, $relationship_t
     ),
   );
 
+  $form['branding'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Branding'),
+    '#group' => 'tabs',
+  );
+
+  $form['branding']['plural_name'] = array(
+    '#type'           => 'textfield',
+    '#title'          => t('Plural name'),
+    '#maxlength'      => 255,
+    '#default_value'  => isset($relationship_type->plural_name) ? $relationship_type->plural_name : NULL,
+    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
+    '#weight'         => 2,
+  );
+
+  $form['branding']['name_capitalized'] = array(
+    '#type'           => 'textfield',
+    '#title'          => t('Capitalized name'),
+    '#maxlength'      => 255,
+    '#default_value'  => isset($relationship_type) ? $relationship_type->name_capitalized : NULL,
+    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
+    '#weight'         => 6,
+  );
+
+  $form['branding']['plural_name_capitalized'] = array(
+    '#type'           => 'textfield',
+    '#title'          => t('Capitalized plural name'),
+    '#maxlength'      => 255,
+    '#default_value'  => isset($relationship_type) ? $relationship_type->plural_name_capitalized : NULL,
+    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
+    '#weight'         => 10,
+  );
+
+  // #states doesn't work on a vertical tab fieldset, hide each input element
+  // separately.
+  $form['reverse_branding'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('One-way reverse branding'),
+    '#group' => 'tabs',
+    '#description' => t('One-way reversed branding is only used when this relationship type only goes one way. Then, these names are used when displaying relationships initiated by other users.'),
+    // Doesn't work properly yet.
+    '#states'         => array(
+      'visible'         => array(
+        ':input[name=is_oneway]' => array('checked' => TRUE),
+      ),
+    ),
+  );
+
+  $form['reverse_branding']['reverse_name'] = array(
+    '#type'           => 'textfield',
+    '#title'          => t('Name'),
+    '#maxlength'      => 255,
+    '#default_value'  => isset($relationship_type) ? $relationship_type->reverse_name : NULL,
+    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
+    '#weight'         => 0,
+  );
+
+  $form['reverse_branding']['reverse_plural_name'] = array(
+    '#type'           => 'textfield',
+    '#title'          => t('Plural name'),
+    '#maxlength'      => 255,
+    '#default_value'  => isset($relationship_type) ? $relationship_type->reverse_plural_name : NULL,
+    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
+    '#weight'         => 4,
+  );
+
+  $form['reverse_branding']['reverse_name_capitalized'] = array(
+    '#type'           => 'textfield',
+    '#title'          => t('Capitalized name'),
+    '#maxlength'      => 255,
+    '#default_value'  => isset($relationship_type) ? $relationship_type->reverse_name_capitalized : NULL,
+    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
+    '#weight'         => 8,
+  );
+
+  $form['reverse_branding']['reverse_plural_name_capitalized'] = array(
+    '#type'           => 'textfield',
+    '#title'          => t('Capitalized plural name'),
+    '#maxlength'      => 255,
+    '#default_value'  => isset($relationship_type) ? $relationship_type->reverse_plural_name_capitalized : NULL,
+    '#description'    => t("Example: buddies, friends, coworkers, spouses."),
+    '#weight'         => 12,
+  );
+
+
   $form['rtid'] = array(
     '#type'   => 'value',
     '#value'  => isset($relationship_type->rtid) ? (int)$relationship_type->rtid : NULL,
@@ -238,11 +308,21 @@ function user_relationships_admin_type_edit($form, &$form_state, $relationship_t
     '#value'  => (isset($relationship_type->rtid) ? 'edit' : 'add'),
   );
 
-  $form['submit'] = array(
+  $form['actions'] = array('#type' => 'actions');
+  $form['actions']['submit'] = array(
     '#type'   => 'submit',
     '#value'  => (isset($relationship_type->rtid) ? t('Save relationship type') : t('Add relationship type')),
-    '#weight' => 10,
+    '#weight' => 0,
   );
+  if (module_exists('i18n_string')) {
+    $form['actions']['translate'] = array(
+      '#type'   => 'submit',
+      '#name'   => 'save_translate',
+      '#value'  => (isset($relationship_type->rtid) ? t('Save and translate') : t('Add and translate')),
+      '#weight' => 5,
+    );
+  }
+
 
   return $form;
 }
@@ -260,7 +340,7 @@ function user_relationships_admin_type_delete($form, &$form_state, $relationship
 
     return confirm_form(
       $form,
-      t('Are you sure you want to delete %name?', array('%name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name))),
+      t('Are you sure you want to delete %rel_name?', user_relationships_type_translations($relationship_type)),
       'admin/config/people/relationships',
       t('This action cannot be undone.'),
       t('Delete'), t('Cancel')
@@ -317,19 +397,10 @@ function user_relationships_setting_validation($element, $validations) {
  */
 function user_relationships_admin_type_edit_submit($form, &$form_state) {
   $relationship_type = (object)$form_state['values'];
-  if ($form_state['values']['action'] == 'add') {
-    //#348025 when editing a type, make sure that two-way relationships are not left as reciprocal, just in case, as the UI allows it.
-    if (!$relationship_type->is_oneway) {
-      $relationship_type->is_reciprocal = 0;
-    }
-    drupal_write_record('user_relationship_types', $relationship_type);
 
-    // Update strings for translation
-    _user_relationships_update_translations($relationship_type);
-
-    $form_state['values']['rtid'] = $relationship_type->rtid;
-    module_invoke_all('user_relationships_type_insert', $relationship_type);
+  user_relationships_type_save($relationship_type);
 
+  if ($form_state['values']['action'] == 'add') {
     drupal_set_message(t('Relationship %name has been added.', array('%name' => $relationship_type->name)));
     watchdog(
       'u_relationship',
@@ -339,16 +410,6 @@ function user_relationships_admin_type_edit_submit($form, &$form_state) {
     );
   }
   else {
-    //#348025 when editing a type, make sure that two-way relationships are not left as reciprocal, just in case, as the UI allows it.
-    if (!$relationship_type->is_oneway) {
-      $relationship_type->is_reciprocal = 0;
-    }
-    drupal_write_record('user_relationship_types', $relationship_type, 'rtid');
-
-    // Update strings for translation
-    _user_relationships_update_translations($relationship_type);
-    module_invoke_all('user_relationships_type_update', $relationship_type);
-
     drupal_set_message(t('Relationship %name has been updated.', array('%name' => $relationship_type->name)));
     watchdog(
       'u_relationship',
@@ -358,10 +419,9 @@ function user_relationships_admin_type_edit_submit($form, &$form_state) {
     );
   }
 
-  user_relationships_types_load(TRUE);
-  menu_rebuild();
+  $translate = module_exists('i18n_string') && $form_state['triggering_element']['#name'] == 'save_translate' ? TRUE : FALSE;
 
-  $form_state['redirect'] = 'admin/config/people/relationships';
+  $form_state['redirect'] = $translate ? 'admin/config/people/relationships/' . $relationship_type->rtid . '/translate' : 'admin/config/people/relationships';
 }
 
 
@@ -388,17 +448,6 @@ function user_relationships_admin_type_delete_submit($form, &$form_state) {
 }
 
 /**
- * Make relationship type available to translation by i18nstrings.module
- */
-function _user_relationships_update_translations(&$relationship_type) {
-  if (function_exists('i18nstrings_update') && $relationship_type->rtid) {
-    i18nstrings_update("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name);
-    i18nstrings_update("user_relationships:rtid:$relationship_type->rtid:plural_name", $relationship_type->plural_name);
-  }
-}
-
-
-/**
  * Relationship Types List
  */
 function user_relationships_admin_types_list_page() {
@@ -481,3 +530,41 @@ function _user_relationships_message_settings_form(&$form, $defaults = array())
     }
   }
 }
+
+/**
+ * Build a translation page for the given relationship type.
+ */
+function user_relationships_translate_tab_page($type, $language = NULL) {
+  module_load_include('inc', 'i18n_string', 'i18n_string.pages');
+  $form_meta = array(
+    '#page_title' => t('Translate relationship type'),
+    '#item_title_header' => t('Relationship type'),
+    '#item_title_key' => array('user_relationships', 'rtid', $type->rtid, 'name'),
+    '#item_title_default' => $type->name,
+    '#edit' => 'admin/config/people/relationships/' . $type->rtid . '/edit',
+    '#translate' => 'admin/config/people/relationships/' . $type->rtid . '/translate/',
+    '#items' => array(),
+  );
+  $form_meta['#items'][] = array(
+    '#title' => t('Name'),
+    '#string_key' => array('user_relationships', 'rtid', $type->rtid, 'name'),
+    '#default_value' => $type->name,
+  );
+  $form_meta['#items'][] = array(
+    '#title' => t('Plural name'),
+    '#string_key' => array('user_relationships', 'rtid', $type->rtid, 'plural_name'),
+    '#default_value' => $type->plural_name,
+  );
+  $form_meta['#items'][] = array(
+    '#title' => t('Capitalized name'),
+    '#string_key' => array('user_relationships', 'rtid', $type->rtid, 'name_capitalized'),
+    '#default_value' => $type->name_capitalized,
+  );
+  $form_meta['#items'][] = array(
+    '#title' => t('Plural capitalized name'),
+    '#string_key' => array('user_relationships', 'rtid', $type->rtid, 'plural_name_capitalized'),
+    '#default_value' => $type->plural_name_capitalized,
+  );
+  $form = i18n_string_translate_page($form_meta, $language);
+  return $form;
+}
\ No newline at end of file
diff --git a/user_relationships.author-pane.inc b/user_relationships.author-pane.inc
index 14582c8..087365e 100644
--- a/user_relationships.author-pane.inc
+++ b/user_relationships.author-pane.inc
@@ -44,7 +44,7 @@ function user_relationships_preprocess_author_pane(&$variables) {
       // Existing relationship; need remove icon/link. (Despite the foreach,
       // there should only be one.)
       foreach ($relationships as $relationship) {
-        $link_label = t('Remove @name from @rel_plural_name', array('@name' => format_username($account), '@rel_plural_name' => $relationship->plural_name));
+        $link_label = t('Remove @name from @rel_plural_name', array('@name' => format_username($account)) + user_relationships_type_translations($relationship));
         $css_class = array(str_replace(' ', '-', $relationship->name), 'author-pane-link', 'user_relationships_popup_link', 'author-relationship-remove-icon');
         //link to remove
         if (!isset($variables['user_relationships'])) {
@@ -52,7 +52,7 @@ function user_relationships_preprocess_author_pane(&$variables) {
         }
         $variables['user_relationships'] .= '<div class="author-pane-ur-link-item">';
         $variables['user_relationships'] .=
-          l('<span>' . t('Remove @rel_name', array('@name' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name))) . '</span>',
+          l('<span>' . t('Remove @rel_name', array('@name' => format_username($account)) + user_relationships_type_translations($relationship)) . '</span>',
           "user/{$user->uid}/relationships/{$relationship->rid}/remove",
           array(
                 'query' => drupal_get_destination(),
@@ -74,13 +74,13 @@ function user_relationships_preprocess_author_pane(&$variables) {
       }
       $variables['user_relationships'] .= '<div class="author-pane-ur-link-item">';
       $variables['user_relationships'] .=
-        l('<span>' . t('Add @rel_name', array('@name' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name))) . '</span>',
+        l('<span>' . t('Add @rel_name', array('@name' => format_username($account)) + user_relationships_type_translations($relationship)) . '</span>',
           "relationship/{$account->uid}/request/{$rtype->rtid}",
           array(
             'query' => drupal_get_destination(),
             'html' => TRUE,
             'attributes'  => array(
-              'title' => t('Become @name\'s @rel_name', array('@name' => format_username($account), '@rel_name' => ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name))),
+              'title' => t('Become @name\'s @rel_name', array('@name' => format_username($account)) + user_relationships_type_translations($rtype)),
               'class' => $css_class
             ),
           )
diff --git a/user_relationships.install b/user_relationships.install
index 16b76c1..94310ec 100644
--- a/user_relationships.install
+++ b/user_relationships.install
@@ -33,11 +33,41 @@ function user_relationships_schema() {
     'fields' => array(
       'rtid'              => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
       'name'              => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
-      'plural_name'       => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+      'plural_name'       => array('type' => 'varchar', 'length' => 255, 'default' => ''),
       'is_oneway'         => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
       'is_reciprocal'     => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
       'requires_approval' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'),
       'expires_val'       => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
+      'reverse_name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'default' => '',
+      ),
+      'name_capitalized'  => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'default' => '',
+      ),
+      'plural_name_capitalized' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'default' => '',
+      ),
+      'reverse_name_capitalized' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'default' => '',
+      ),
+      'reverse_plural_name' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'default' => '',
+      ),
+      'reverse_plural_name_capitalized' => array(
+        'type' => 'varchar',
+        'length' => 255,
+        'default' => '',
+      ),
     ),
     'unique keys' => array(
       'name'  => array('name'),
@@ -101,3 +131,45 @@ function user_relationships_update_7001() {
 function user_relationships_update_7002() {
   db_change_field('user_relationships', 'rid', 'rid', array('type' => 'int', 'not null' => TRUE));
 }
+
+/**
+ * Add table columns for reversed and capitalized names.
+ */
+function user_relationships_update_7003() {
+  $fields = array(
+    'reverse_name' => array(
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => '',
+    ),
+    'name_capitalized'  => array(
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => '',
+    ),
+    'plural_name_capitalized' => array(
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => '',
+    ),
+    'reverse_name_capitalized' => array(
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => '',
+    ),
+    'reverse_plural_name' => array(
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => '',
+    ),
+    'reverse_plural_name_capitalized' => array(
+      'type' => 'varchar',
+      'length' => 255,
+      'default' => '',
+    ),
+  );
+
+  foreach ($fields as $field => $definition) {
+    db_add_field('user_relationship_types', $field, $definition);
+  }
+}
diff --git a/user_relationships.module b/user_relationships.module
index 8d15e6d..8e6b51c 100644
--- a/user_relationships.module
+++ b/user_relationships.module
@@ -11,6 +11,10 @@
 define('UR_OK', 0x0);
 define('UR_BANNED', 0x1);
 
+define('USER_RELATIONSHIPS_NAME_PLURAL', 1);
+define('USER_RELATIONSHIPS_NAME_CAPITAL', 2);
+define('USER_RELATIONSHIPS_NAME_REVERSE', 4);
+
 function user_relationships_menu() {
   $items['admin/config/people/relationships'] = array(
     'title' => 'Relationships',
@@ -43,6 +47,25 @@ function user_relationships_menu() {
     'file' => 'user_relationships.admin.inc',
     'weight' => 5,
   );
+  if (module_exists('i18n_string')) {
+    $items['admin/config/people/relationships/%user_relationships_type/translate'] = array(
+      'title' => 'Translate',
+      'access callback' => 'user_relationships_translate_tab_access',
+      'page callback' => 'user_relationships_translate_tab_page',
+      'file' => 'user_relationships.admin.inc',
+      'page arguments' => array(4),
+      'type' => MENU_LOCAL_TASK,
+      'weight' => 10,
+    );
+    $items['admin/config/people/relationships/%user_relationships_type/translate/%language'] = array(
+      'title' => 'Translate',
+      'access callback' => 'user_relationships_translate_tab_access',
+      'page callback' => 'user_relationships_translate_tab_page',
+      'file' => 'user_relationships.admin.inc',
+      'page arguments' => array(4, 6),
+      'type' => MENU_CALLBACK,
+    );
+  }
   $items['admin/config/people/relationships/%user_relationships_type/delete'] = array(
     'title' => 'Delete type',
     'type' => MENU_LOCAL_TASK,
@@ -50,7 +73,7 @@ function user_relationships_menu() {
     'page arguments' => array('user_relationships_admin_type_delete', 4),
     'access arguments' => array('administer user relationships'),
     'file' => 'user_relationships.admin.inc',
-    'weight' => 10,
+    'weight' => 15,
   );
   $items['admin/config/people/relationships/settings'] = array(
     'title' => 'Settings',
@@ -72,6 +95,14 @@ function user_relationships_menu() {
 }
 
 /**
+ * Menu access callback function.
+ */
+function user_relationships_translate_tab_access() {
+  return user_access('translate interface') && user_access('administer user relationships');
+}
+
+
+/**
  * Helper function to generate the main and count queries from a list of parameters and options
  */
 function _user_relationships_generate_query($param = array(), $options = array()) {
@@ -213,11 +244,11 @@ function user_relationships_permission() {
   $permissions = array();
   foreach (user_relationships_types_load() as $type) {
     $permissions['can have ' . $type->name . ' relationships'] = array(
-      'title' => t('Can have @name relationships', array('@name' => $type->name)),
+      'title' => t('Can have @rel_name relationships', user_relationships_type_translations($type)),
       'description' => t('The user is allowed to have and accept relationships of that type.'),
     );
     $permissions['can request ' . $type->name . ' relationships'] = array(
-      'title' => t('Can request @name relationships', array('@name' => $type->name)),
+      'title' => t('Can request @rel_name relationships', user_relationships_type_translations($type)),
       'description' => t('The user is allowed to request relationships of that type.'),
     );
   }
@@ -273,18 +304,6 @@ function user_relationships_user_cancel($edit, $account, $method) {
 }
 
 /**
- * Wrapper function for tt() if i18nstrings enabled.
- */
-function ur_tt($name, $string, $langcode = NULL, $update = FALSE) {
-  if (module_exists('i18nstrings')) {
-    return tt($name, $string, $langcode, $update);
-  }
-  else {
-    return $string;
-  }
-}
-
-/**
  * Implements hook_activity_info().
  */
 function user_relationships_activity_info() {
@@ -383,28 +402,40 @@ function user_relationships_types_load($reset = FALSE) {
  *   A User Relationship type object
  */
 function user_relationships_type_save($rtype) {
+
+  // #348025 when editing a type, make sure that two-way relationships are not
+  // left as reciprocal, just in case, as the UI allows it.
+  if (empty($rtype->is_oneway)) {
+    $rtype->is_reciprocal = 0;
+  }
+
+  // Ensure "expires_val" is numeric and not negative.
+  if (!isset($rtype->expires_val) || !is_numeric($rtype->expires_val) || $rtype->expires_val < 0) {
+    $rtype->expires_val = 0;
+  }
+
   module_invoke_all('user_relationships_type_presave', $rtype);
 
   $op = (isset($rtype->rtid) && $rtype->rtid) ? 'update' : 'insert';
 
-  // find a relationship type with the name we're trying to save
+  // Find a relationship type with the name we're trying to save
   // if it's an update action check to see that the rtypes match
-  // otherwise it's just invalid
-  if (
-    ($found_rt = user_relationships_type_load(array('name' => $rtype->name))) &&
-    ($op == 'update' ? $found_rt->rtid != $rtype->rtid : TRUE)
-  ) {
+  // otherwise it's just invalid.
+  $found_rt = user_relationships_type_load(array('name' => $rtype->name));
+  if ($found_rt && (($op == 'update' && $found_rt->rtid != $rtype->rtid) || $op == 'insert')) {
     return FALSE;
   }
 
-  // ensure "expires_val" is numeric and not negative
-  if (!is_numeric($rtype->expires_val) || $rtype->expires_val < 0) {
-    $rtype->expires_val = 0;
-  }
-
   drupal_write_record('user_relationship_types', $rtype, ($op == 'update' ? 'rtid' : array()));
 
   module_invoke_all('user_relationships_type_' . $op, $rtype);
+
+  user_relationships_types_load(TRUE);
+
+  // Update strings for translation.
+  _user_relationships_update_translations($rtype);
+
+  menu_rebuild();
 }
 
 
@@ -466,14 +497,14 @@ function user_relationships_request_relationship($requester, $requestee = NULL,
 
   //check requester is allowed to create this rtype
   if (!user_relationships_can_request($requester, $type)) {
-    watchdog('user_relationships', 'User %user has no suitable roles to request a %rtype relationship', array('%user' => format_username($requester), '%rtype' => $type->name), WATCHDOG_WARNING);
+    watchdog('user_relationships', 'User %user has no suitable roles to request a %rtype relationship', array('%user' => format_username($requester), '%rtype' => user_relationships_type_get_name($type)), WATCHDOG_WARNING);
     //it would be good to return a reason why save is denied, but it's the API portion, it does not expose anything user-visible
     return FALSE;
   }
 
   //check requestee is allowed to receive this rtype
   if (!user_relationships_can_receive($requestee, $type)) {
-    watchdog('user_relationships', 'User %user has no suitable roles to receive a %rtype relationship', array('%user' => format_username($requestee), '%rtype' => $type->name), WATCHDOG_WARNING);
+    watchdog('user_relationships', 'User %user has no suitable roles to receive a %rtype relationship', array('%user' => format_username($requestee), '%rtype' => user_relationships_type_get_name($type)), WATCHDOG_WARNING);
     //it would be good to return a reason why save is denied, but it's the API portion, it does not expose anything user-visible
     return FALSE;
   }
@@ -837,19 +868,10 @@ function user_relationships_get_message($key, $relationship = NULL, $replacement
     if (!isset($relationship->requestee)) {
       $relationship->requestee = user_load($relationship->requestee_id);
     }
-    if (!(isset($relationship->name) || isset($relationship->type))) {
-      $relationship->type = user_relationships_type_load($relationship->rtid);
-    }
 
-    $replaceables = array(
+    $replaceables = user_relationships_type_translations(user_relationships_type_load($relationship->rtid)) + array(
       '!requester'                => theme('username', array('account' => $relationship->requester)),
       '!requestee'                => theme('username', array('account' => $relationship->requestee)),
-      '%relationship_name'        => isset($relationship->name)
-                                     ? ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name)
-                                     : ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->type->name),
-      '%relationship_plural_name' => isset($relationship->plural_name)
-                                     ? ur_tt("user_relationships:rtid:$relationship->rtid:plural_name", $relationship->plural_name)
-                                     : ur_tt("user_relationships:rtid:$relationship->rtid:plural_name", $relationship->type->plural_name),
     );
     $replacements = array_merge($replaceables, $replacements);
   }
@@ -873,27 +895,27 @@ function user_relationships_get_message($key, $relationship = NULL, $replacement
 function _user_relationships_default_messages($replacements) {
   return array(
     'informational' => array(
-      'submitted'     => t('Your %relationship_name request has been sent to !requestee.', $replacements),
-      'accepted'      => t("!requester's %relationship_name request has been approved.", $replacements),
-      'disapproved'   => t("!requester has declined your %relationship_name request.", $replacements),
-      'disapprove'   => t("!requester's %relationship_name request has been declined.", $replacements),
-      'cancel'        => t('Your %relationship_name request to !requestee has been canceled.', $replacements),
+      'submitted'     => t('Your @rel_name request has been sent to !requestee.', $replacements),
+      'accepted'      => t("!requester's @rel_name request has been approved.", $replacements),
+      'disapproved'   => t("!requester has declined your @rel_name request.", $replacements),
+      'disapprove'   => t("!requester's @rel_name request has been declined.", $replacements),
+      'cancel'        => t('Your @rel_name request to !requestee has been canceled.', $replacements),
       'default'       => t('No action has been taken.'),
-      'removed'       => t('The %relationship_name relationship between !requester and !requestee has been deleted.', $replacements),
-      'pending'       => t('!requester has requested to be your %relationship_name. View your !pending_relationship_requests to approve or decline.', $replacements),
-      'pre_approved'  => t("You are !requestee's newest %relationship_name.", $replacements),
+      'removed'       => t('The @rel_name relationship between !requester and !requestee has been deleted.', $replacements),
+      'pending'       => t('!requester has requested to be your @rel_name. View your !pending_relationship_requests to approve or decline.', $replacements),
+      'pre_approved'  => t("You are !requestee's newest @rel_name.", $replacements),
     ),
     'error' => array(
       'too_many_relationships'  => t('You are not permitted to create any more relationships with this user.'),
-      'existing_request'        => t('There is already an earlier %relationship_name request sent to !requestee.', $replacements),
-      'existing_relationship'   => t('There is already an existing %relationship_name relationship with !requestee.', $replacements),
+      'existing_request'        => t('There is already an earlier @rel_name request sent to !requestee.', $replacements),
+      'existing_relationship'   => t('There is already an existing @rel_name relationship with !requestee.', $replacements),
       'not_accepting_requests'  => t('This user does not accept relationship requests.'),
       'self_request'            => t('You cannot create a relationship with yourself.'),
       'non_existent_user'       => t('This user does not exist.'),
       'non_existent_type'       => t('This relationship type does not exist.'),
       'unknown_error'           => t('An error has occurred. Please contact the site administrator.'),
       'relationship_type_not_set' => t('Please choose the type of relationship.'),
-      'relationship_type_not_allowed' => t('You may not create %relationship_name relationships.', $replacements),
+      'relationship_type_not_allowed' => t('You may not create @rel_name relationships.', $replacements),
     ),
   );
 }
@@ -944,16 +966,76 @@ function _user_relationships_get_from_array($needle, &$haystack) {
 }
 
 /**
- * Implements hook_locale().
+ * Implements hook_i18n_string_info().
  */
-function user_relationships_ui_locale($op = 'groups') {
-  switch ($op) {
-    case 'groups':
-      return array('user_relationships' => t('User Relationships'));
+function user_relationships_i18n_string_info() {
+  return array(
+    'user_relationships' => array(
+      'title' => t('User Relationships'),
+      'description' => t('Translations for relationship type names'),
+      'format' => FALSE,
+      'list' => TRUE,
+    ),
+  );
+}
+
+function user_relationships_i18n_string_list($group) {
+  if ($group == 'all' || $group == 'user_relationships') {
+    $strings = array();
+    foreach (user_relationships_types_load() as $type) {
+      $strings['user_relationships']['rtid'][$type->rtid]['name'] = $type->name;
+      $strings['user_relationships']['rtid'][$type->rtid]['plural_name'] = $type->plural_name;
+      $strings['user_relationships']['rtid'][$type->rtid]['name_capitalized'] = $type->name_capitalized;
+      $strings['user_relationships']['rtid'][$type->rtid]['plural_name_capitalized'] = $type->plural_name_capitalized;
+      $strings['user_relationships']['rtid'][$type->rtid]['reverse_name'] = $type->reverse_name;
+      $strings['user_relationships']['rtid'][$type->rtid]['reverse_plural_name'] = $type->reverse_plural_name;
+      $strings['user_relationships']['rtid'][$type->rtid]['reverse_name_capitalized'] = $type->reverse_name_capitalized;
+      $strings['user_relationships']['rtid'][$type->rtid]['reverse_plural_name_capitalized'] = $type->reverse_plural_name_capitalized;
+    }
+    return $strings;
   }
 }
 
 /**
+ * Gets the relationship type name.
+ */
+function user_relationships_type_get_name($type, $plural = FALSE, $reversed = FALSE, $capitalized = FALSE) {
+  if (is_string($type)) {
+    $type = user_relationships_type_load($type);
+  }
+
+  // Start with just name as the name and then add suffixes and prefixes
+  // according to the given flags.
+  $name  = 'name';
+  if ($plural) {
+    $name = 'plural_' . $name;
+  }
+
+  if ($reversed) {
+    $name = 'reverse_' . $name;
+  }
+
+  if ($capitalized) {
+    $name .= '_capitalized';
+  }
+
+  $name_value = !empty($type->$name) ? $type->$name : $type->name;
+  if (function_exists('i18n_string_translate')) {
+    $name_value = i18n_string_translate(array('user_relationships', 'rtid', $type->rtid, $name), $name_value);
+  }
+  return $name_value;
+}
+
+function user_relationships_type_translations($relationship_type) {
+  return array(
+    '@rel_name' => user_relationships_type_get_name($relationship_type),
+    '@rel_name_plural' => user_relationships_type_get_name($relationship_type, TRUE),
+    '@Rel_name' => user_relationships_type_get_name($relationship_type, FALSE, FALSE, TRUE),
+    '@Rel_name_plural' => user_relationships_type_get_name($relationship_type, TRUE, FALSE, TRUE),
+  );
+}
+
+/**
  * Adds autocompletion capability
  */
 function user_relationships_autocomplete_types($string = '') {
@@ -961,7 +1043,7 @@ function user_relationships_autocomplete_types($string = '') {
   if ($string) {
     $result = db_query_range("SELECT rtid, name FROM {user_relationship_types} WHERE LOWER(name) LIKE LOWER(:string)", 0, 10, array(':string' => '%' . strtolower($string) . '%'));
     foreach ($result as $relationship) {
-      $matches[$relationship->name] = check_plain(ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name));
+      $matches[$relationship->name] = check_plain(user_relationships_type_get_name($relationship));
    }
   }
   print drupal_json_output($matches);
@@ -1014,7 +1096,7 @@ function user_relationships_get_requestable_rtypes($requester, $requestee, $retu
       }
     }
     if ($return == 'name') {
-      $relationships[$rtype->rtid] = ur_tt("user_relationships:rtid:$rtype->rtid:name", $rtype->name);
+      $relationships[$rtype->rtid] = user_relationships_type_get_name($rtype);
     }
     else {
       $relationships[$rtype->rtid] = $rtype;
@@ -1022,3 +1104,21 @@ function user_relationships_get_requestable_rtypes($requester, $requestee, $retu
   }
   return $relationships;
 }
+
+/**
+ * Make relationship type available to translation by i18n_string.module
+ */
+function _user_relationships_update_translations($relationship_type) {
+  if (function_exists('i18n_string_update') && $relationship_type->rtid) {
+    $rtid = $relationship_type->rtid;
+    i18n_string_update("user_relationships:rtid:$rtid:name", $relationship_type->name);
+    i18n_string_update("user_relationships:rtid:$rtid:plural_name", $relationship_type->plural_name);
+    i18n_string_update("user_relationships:rtid:$rtid:name_capitalized", $relationship_type->name_capitalized);
+    i18n_string_update("user_relationships:rtid:$rtid:plural_name_capitalized", $relationship_type->plural_name_capitalized);
+    i18n_string_update("user_relationships:rtid:$rtid:reverse_name", $relationship_type->reverse_name);
+    i18n_string_update("user_relationships:rtid:$rtid:reverse_plural_name", $relationship_type->reverse_plural_name);
+    i18n_string_update("user_relationships:rtid:$rtid:reverse_name_capitalized", $relationship_type->reverse_name_capitalized);
+    i18n_string_update("user_relationships:rtid:$rtid:reverse_plural_name_capitalized", $relationship_type->reverse_plural_name_capitalized);
+  }
+}
+
diff --git a/user_relationships_ui/user_relationships_ui.forms.inc b/user_relationships_ui/user_relationships_ui.forms.inc
index d15ce41..6052531 100644
--- a/user_relationships_ui/user_relationships_ui.forms.inc
+++ b/user_relationships_ui/user_relationships_ui.forms.inc
@@ -128,8 +128,8 @@ function user_relationships_ui_request($form, &$form_state, $requestee) {
       "user/$requestee->uid",
       isset($relationship) ?
       ($relationship->requires_approval
-       ? t('Are you sure you want to send a new %rel_name request to !name?', array('%rel_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name), '%rel_plural_name' => ur_tt("user_relationships:rtid:$relationship->rtid:plural_name", $relationship->plural_name), '!name' => theme('username', array('account' => $requestee))))
-       : t("Are you sure you want to become !name's %rel_name?", array('!name' => theme('username', array('account' => $requestee)), '%rel_name' => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name)))) :
+       ? t('Are you sure you want to send a new @rel_name request to !name?', array('!name' => theme('username', array('account' => $requestee))) + user_relationships_type_translations($relationship))
+       : t("Are you sure you want to become !name's @rel_name?", array('!name' => theme('username', array('account' => $requestee))) + user_relationships_type_translations($relationship))) :
       '',
       t('Send'), t('Cancel'),
       'user_relationships_request_confirm'
@@ -175,29 +175,26 @@ function user_relationships_ui_pending_requested($form, &$form_state, $action, $
   //pick the correct question message: approve and disapprove are requests to current user, cancel is a request from current user
   switch ($action) {
     case 'approve':
-      $confirmation_message = t('Are you sure you want to approve the %relationship_name relationship request from !name?', array(
+      $confirmation_message = t('Are you sure you want to approve the @rel_name relationship request from !name?', array(
         '@action'             => $action,
-        '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
         '!name'               => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
-      ));
+      ) + user_relationships_type_translations($relationship));
       $action_message = t('Approve relationship');
       $request_url = 'relationships/received';
       break;
     case 'disapprove':
-      $confirmation_message = t('Are you sure you want to decline the %relationship_name relationship request from !name?', array(
+      $confirmation_message = t('Are you sure you want to decline the @rel_name relationship request from !name?', array(
         '@action'             => $action,
-        '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
         '!name'               => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
-      ));
+      ) + user_relationships_type_translations($relationship));
       $action_message = t('Decline relationship');
       $request_url = 'relationships/received';
       break;
     default:
-      $confirmation_message = t('Are you sure you want to cancel your %relationship_name relationship request to !name?', array(
+      $confirmation_message = t('Are you sure you want to cancel your @rel_name relationship request to !name?', array(
         '@action'             => $action,
-        '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
         '!name'               => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
-      ));
+      ) + user_relationships_type_translations($relationship));
       $action_message = t('Cancel relationship');
       $request_url = 'relationships/sent';
   }
@@ -265,10 +262,9 @@ function user_relationships_ui_remove($form, &$form_state, $account, $relationsh
     t('Remove relationship'),
     ($viewed_id == $user->uid ? 'relationships' : "user/{$viewed_id}/relationships/"),
 
-    t("Are you sure you want to delete the %relationship_name relationship with !name?", array(
-      '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
+    t("Are you sure you want to delete the @rel_name relationship with !name?", array(
       '!name'               => theme('username', array('account' => user_load(($viewed_id == $relationship->requester_id ? $relationship->requestee_id : $relationship->requester_id))))
-    )),
+    ) + user_relationships_type_translations($relationship)),
     t('Yes'), t('No'),
     'user_relationships_remove_confirm'
   );
diff --git a/user_relationships_ui/user_relationships_ui.module b/user_relationships_ui/user_relationships_ui.module
index 3d9de09..63a14e5 100644
--- a/user_relationships_ui/user_relationships_ui.module
+++ b/user_relationships_ui/user_relationships_ui.module
@@ -63,20 +63,18 @@ function user_relationships_ui_actions_between($viewer, $viewed, $action_types =
   if (isset($action_types['requested'])) {
     $relationships = user_relationships_load(array('requester_id' => $viewer->uid, 'requestee_id' => $viewed->uid, 'approved' => FALSE));
     foreach ($relationships as $relationship) {
-      $list[] = t('You have sent a new %relationship_name request to this user. (!pending_requests)', array(
-        '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
+      $list[] = t('You have sent a new @rel_name request to this user. (!pending_requests)', array(
         '!pending_requests'   => l(t('pending requests'), "relationships/sent"),
-      ));
+      ) + user_relationships_type_translations($relationship));
     }
   }
 
   if (isset($action_types['received'])) {
     $relationships = user_relationships_load(array('requester_id' => $viewed->uid, 'requestee_id' => $viewer->uid, 'approved' => FALSE));
     foreach ($relationships as $relationship) {
-      $list[] = t('This user has requested to be your %relationship_name. (!pending_requests)', array(
-        '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name),
+      $list[] = t('This user has requested to be your @rel_name. (!pending_requests)', array(
         '!pending_requests'   => l(t('pending requests'), "user/{$viewer->uid}/relationships/received"),
-      ));
+      ) + user_relationships_type_translations($relationship));
     }
   }
 
@@ -101,8 +99,8 @@ function user_relationships_ui_actions_between($viewer, $viewed, $action_types =
     $relationships = user_relationships_load(array('between' => array($viewer->uid, $viewed->uid)));
     foreach ($relationships as $relationship) {
       if ($relationship->approved && !isset($list[$relationship->rid])) {
-        $list[$relationship->rid] = t('%relationship_name (!remove_link)', array(
-          '%relationship_name'  => ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name) . ($relationship->is_oneway ? ($relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)')) : NULL),
+        $list[$relationship->rid] = t('@rel_name (!remove_link)', array(
+          '@rel_name'  => user_relationships_type_get_name($relationship) . ($relationship->is_oneway ? ($relationship->requester_id == $viewer->uid ? t(' (You to Them)') : t(' (Them to You)')) : NULL),
           '!remove_link'        => theme('user_relationships_remove_link', array('uid' => $viewer->uid, 'rid' => $relationship->rid)),
         ));
       }
@@ -112,7 +110,6 @@ function user_relationships_ui_actions_between($viewer, $viewed, $action_types =
   return $list;
 }
 
-
 /**********************************
  *          CALLBACKS
  **********************************/
@@ -280,7 +277,8 @@ function user_relationships_ui_menu() {
   foreach (user_relationships_types_load() as $rtid => $relationship) {
     if (isset($show_tabs[$rtid])) {
       $items["relationships/{$rtid}"] = array(
-        'title' => $relationship->plural_name ? $relationship->plural_name : $relationship->name,
+        'title' => $relationship->rtid,
+        'title callback' => 'user_relationships_ui_title_callback',
         'type' => MENU_LOCAL_TASK,
         'access callback' => 'user_relationships_ui_check_access',
         'access arguments' => array('edit'),
@@ -357,7 +355,8 @@ function user_relationships_ui_menu() {
   );
   foreach (user_relationships_types_load() as $rtid => $relationship) {
     $items["user/%user/relationships/{$rtid}"] = array(
-      'title' => $relationship->plural_name ? $relationship->plural_name : $relationship->name,
+      'title' => $relationship->rtid,
+      'title callback' => 'user_relationships_ui_title_callback',
       'type' => MENU_LOCAL_TASK,
       'access callback' => 'user_relationships_ui_check_access',
       'access arguments' => array(array('user'), 1),
@@ -390,6 +389,10 @@ function user_relationships_ui_menu() {
   return $items;
 }
 
+function user_relationships_ui_title_callback($rtid) {
+  return user_relationships_type_get_name(user_relationships_type_load($rtid), TRUE, FALSE, TRUE);
+}
+
 /**
  * Title callback to display the amount of pending requests.
  * @param $column
@@ -498,7 +501,7 @@ function user_relationships_ui_form_alter(&$form, &$form_state, $form_id) {
         $options = array();
         foreach ($relationships as $relationship) {
           if ($relationship->requires_approval) {
-            $options[$relationship->rtid] = ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name);
+            $options[$relationship->rtid] = user_relationships_type_get_name($relationship);
           }
         }
 
diff --git a/user_relationships_ui/user_relationships_ui.pages.inc b/user_relationships_ui/user_relationships_ui.pages.inc
index 0c57d78..af4ec03 100644
--- a/user_relationships_ui/user_relationships_ui.pages.inc
+++ b/user_relationships_ui/user_relationships_ui.pages.inc
@@ -41,12 +41,12 @@ function user_relationships_page($account = NULL, $rtid = NULL) {
 
   if ($account->uid == $user->uid) {
     $msg = isset($relationship_type)
-           ? t("My %relationships", array('%relationships' => $relationship_type->plural_name ? ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":plural_name", $relationship_type->plural_name) : ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":name", $relationship_type->name)))
+           ? t("My @rel_name_plural", user_relationships_type_translations($relationship_type))
            : t("My relationships");
   }
   else {
     $msg = isset($relationship_type)
-           ? t("%username's %relationships", array('%username' => format_username($account), '%relationships' => $relationship_type->plural_name ? ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":plural_name", $relationship_type->plural_name) : ur_tt("user_relationships:rtid:" . $relationship_type->rtid . ":name", $relationship_type->name)))
+           ? t("%username's @rel_name", array('%username' => format_username($account)) + user_relationships_type_translations($relationship_type))
            : t("%username's relationships", array('%username' => format_username($account)));
   }
   drupal_set_title($msg, PASS_THROUGH);
@@ -60,7 +60,7 @@ function user_relationships_page($account = NULL, $rtid = NULL) {
   $header = user_relationships_ui_get_table_header($edit_access);
 
   if (!empty($rtid)) {
-    $empty = t('You do not have any %plural_name.', array('%plural_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:plural_name", $relationship_type->plural_name)));
+    $empty = t('You do not have any %rel_plural_name.', user_relationships_type_translations($relationship_type));
   }
   else {
     $empty = t('You do not have any relationships with other users.');
@@ -169,7 +169,7 @@ function user_relationships_ui_get_table_row($relationship, $account) {
 
   $row = array(
     theme('username', array('account' => $this_user)),
-    ur_tt("user_relationships:rtid:$relationship->rtid:name", $relationship->name) . ($relationship->is_oneway ? ($this_user_str == 'requestee' ? t(' (You to Them)') : t(' (Them to You)')) : NULL),
+    user_relationships_type_get_name($relationship, FALSE, $relationship->is_oneway && $this_user_str == 'requester'),
   );
   if ($edit_access) {
     $links = array();
diff --git a/user_relationships_ui/user_relationships_ui.theme.inc b/user_relationships_ui/user_relationships_ui.theme.inc
index 648e4b2..858b58e 100644
--- a/user_relationships_ui/user_relationships_ui.theme.inc
+++ b/user_relationships_ui/user_relationships_ui.theme.inc
@@ -39,7 +39,7 @@ function theme_user_relationships_request_relationship_direct_link($variables) {
     return theme('user_relationships_request_relationship_link', array('relate_to' => $relate_to));
   }
   return l(
-    t("Become %name's %rel_name", array('%name' => format_username($relate_to), '%rel_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:name", $relationship_type->name), '%rel_plural_name' => ur_tt("user_relationships:rtid:$relationship_type->rtid:plural_name", $relationship_type->plural_name))),
+    t("Become %name's @rel_name", array('%name' => format_username($relate_to)) + user_relationships_type_translations($relationship_type)),
     "relationship/{$relate_to->uid}/request/{$relationship_type->rtid}",
     array(
       'query' => drupal_get_destination(),
-- 
1.7.5.4

