Translate relationships (as 'friend')

emi_bcn - May 24, 2009 - 15:56
Project:User Relationships
Version:6.x-1.0-rc2
Component:Code
Category:support request
Priority:normal
Assigned:aufumy
Status:closed
Description

Hi there!!
I've been looking for relationship translation method and I was unable to find it anywhere. I mean, how do I translate the 'friend' string? It seems like it's not possible. May be some t() missing?

Thanks a lot!!

#1

alex.k - May 24, 2009 - 18:18
Category:bug report» support request

Please post screenshots. Thanks.

#2

brainski - July 6, 2009 - 12:41

Thats true. I'm not able to translate it as well:

F.ex.
"Become username's friend" in Relationship Actions Block is not translatable.

#3

alex.k - July 6, 2009 - 20:28
Assigned to:Anonymous» alex.k

Hmm it sounds like 'friend' is what you have called your relationship type... in that case that is probably not translatable, you are right. The options are:
* If this is your only type defined, then translate "Become %name's %rel_name" which is used in function theme_user_relationships_request_relationship_direct_link(&$relate_to, &$relationship_type)
* If it isn't, override this function in your theme to output proper link titles...
This behavior is rooted pretty deeply in UR so ideas on how to apply translation across the board are welcome.

#4

aufumy - September 21, 2009 - 21:09
Version:6.x-1.0-beta10» 6.x-1.0-rc2
Status:active» needs review

Added some t() 's around the display of the relationship type.

AttachmentSize
471546.patch 8.79 KB

#5

alex.k - September 23, 2009 - 01:05
Status:needs review» needs work

Very nice, thank you!

Could you just also translate the plural names where given:

<?php
'%rel_plural_name' => $relationship_type->plural_name)
?>

to
<?php
'%rel_plural_name' => t($relationship_type->plural_name))
?>

A parallel question, a reality check more than anything... would it make sense to use another text group for translating relationship names? Similarly to how menus, block titles, etc are different from the "built-in interface" text group. This will help disambiguate some names like 'parent' which can be seen as verbs or nouns out of context.

#6

aufumy - September 22, 2009 - 14:01

That makes a lot of sense, to use a different group.

Will do.

#7

aufumy - September 23, 2009 - 00:39
Status:needs work» needs review

This patch:
* implements hook_locale() in user_relationships_ui.module to define a new group
* uses function tt() from i18nstrings module to get the translated strings from the right group
* implements a degrade path if i18nstrings module is not enabled.

AttachmentSize
471546.patch 22.05 KB

#8

alex.k - September 23, 2009 - 00:58
Status:needs review» reviewed & tested by the community

Great stuff, thank you!

#9

aufumy - September 23, 2009 - 15:24
Status:reviewed & tested by the community» fixed

Committed the following patch to branch DRUPAL-6--1

AttachmentSize
471546.patch 27.21 KB

#10

aufumy - September 28, 2009 - 15:10

A few more missing tt()'s committed to cvs

AttachmentSize
471546.patch 5.46 KB

#11

Kars-T - October 1, 2009 - 11:38
Status:fixed» needs work

The patch itself is a great thing but please think about this:

+++ user_relationships_api/user_relationships_api.module 23 Sep 2009 00:35:26 -0000
@@ -247,3 +247,12 @@ function user_relationships_api_user($ty
+
+/**
+ * provide a degrade path for function tt found in module i18nstrings
+ */
+if (! module_exists('i18nstrings')) {
+  function tt($name, $string, $langcode = NULL, $update = FALSE) {
+    return t($string, array(), $langcode);
+  }
+}

Even if this might be a good idea what will happen if all modules that want to use tt() do this?
I don't think it is wise to do this!

Maybe provide a real wrapper like

<?php
/**
* provide a degrade path for function tt found in module i18nstrings
*/
function ur_tt($name, $string, $langcode = NULL, $update = FALSE) {

  static
$i18nstrings;
 
  if(!isset(
$i18nstrings)) {
   
$i18nstrings = module_exists('i18nstrings');
  }
 
  if (
$i18nstrings) {
    return
tt($name, $string, $langcode, $update);
  }
  else {
    return
t($string, array(), $langcode);
  }
}
?>

This review is powered by Dreditor.

#12

aufumy - October 9, 2009 - 20:05

I like that this uses a static variable instead of calling module_exists('i18nstrings') and function_exists('tt').

However, if one uses
if (! module_exists('i18nstrings') && ! function_exists('tt')) {
then the case that other modules may follow suit could be avoided.

What I like about using module_exists/function_exists way, is that when i18nstrings module is enabled, there is no extra layer of each module instantiating their own function, and each time contribmodule_tt() is called to go through the processing each time.

Thoughts?

#13

Kars-T - October 10, 2009 - 10:34

I think that ! function_exists('tt') is a good idea and less work if you don't want to add a real wrapper. Performance wise I don't think there will be a difference. I feel a wrapper is cleaner but just decide what you want to use :)

#14

Scott Reynolds - October 13, 2009 - 16:35

I like this approach. You do NOT need the static $i18nstrings as module_exists() already does a static cache for you.

This is helpful yet a little short...

http://drupal.org/node/304002

#15

aufumy - October 13, 2009 - 20:35

Alright, I see the light now. If there is a poorly written tt() function from a contrib module with a lower weight, this would cause problems for every other contrib module that calls tt() when i18nstrings is not enabled.

/**
* 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;
  }
}

AttachmentSize
471546.patch 27.46 KB

#16

aufumy - October 13, 2009 - 20:36
Assigned to:alex.k» aufumy
Status:needs work» needs review

#17

alex.k - October 14, 2009 - 16:38
Status:needs review» reviewed & tested by the community

Great work, thanks for the patch and the reviews!

#18

aufumy - October 15, 2009 - 15:25

Committed to cvs DRUPAL-6--1, thanks to Kars-T, Scott Reynolds and Alex.K!

#19

aufumy - October 15, 2009 - 15:28
Status:reviewed & tested by the community» fixed

#20

System Message - October 29, 2009 - 15:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#21

aufumy - November 17, 2009 - 00:06

Kars-T, Scott, if you can pipe in on a related similar issue

http://drupal.org/node/606804

Thanks
Audrey

 
 

Drupal is a registered trademark of Dries Buytaert.