The $sort_methods displayed inside Browse by !sort_methodand other places cannot translated. Any idea how to solve this?

Comments

hass’s picture

Title: Untranslateable strings » !sort_method not translateable in "Browse by !sort_method"
dww’s picture

Component: Projects » User interface

The smallest change would probably be to add a new $op to hook_project_sort_methods() that returned an array of method name => translated name mappings for each module, and change various places where we're presenting the sort methods in the UI to use this. Unfortunately, it's a little complicated, since you'd need to make sure you invoked the right module's implementation of the hook for any given sort method.

The larger, but probably better change, would be a more major refactoring of this hook so that:
a) It didn't use module_invoke_all() but invoked the hook manually and created a nested array, with sub arrays for each module that implements the hook.
b) Changed the 'methods' op to return an array more like this:

  $methods = array();
  $methods['name'] = t('name');
  $methods['date'] = t('date');
  if (project_use_taxonomy()) {
    $methods['category'] = t('category');
  }

Then, when a call site invoked the hook, it'd get back an array that looked something like this:

$methods['project']['name'] = t('name');
$methods['project']['date'] = t('date');
$methods['project_usage']['usage'] = t('Number of sites using each project');
$methods['project_release']['downloads'] = t('Number of downloads');
...

Of course, the latter is a bigger change, since it'll hit all the call sites that touch sort_methods, and might create new problems. I haven't thought about this much or looked too closely, so someone who cares will have to do a little more research and come up with a clear, well-thought out proposal.

Cheers,
-Derek

dww’s picture

Wow, that's funny. I just came across nedjo's patch at http://drupal.org/node/66013#comment-104973 and it implemented some of the changes I'm talking about here to make these translatable. Not sure what he's got there will really work if we lose the data about what module each sorting method is from, but anyone who's going to start writing code for this should at least take a look at what he's got there and use that as a starting point for further consideration.

hunmonk’s picture

Priority: Normal » Minor
vladimir.dolgopolov’s picture

Status: Active » Needs review
StatusFileSize
new2.75 KB

This patch based on nedjo's patch.
Added ability to translate "sort method" for users and admin/project/project-settings.

dries’s picture

Status: Needs review » Needs work

1. Taxonomy terms should not be translated using the t() function.

2. I'd expect this code to break functionality -- 'project' refers to the project module and shouldn't be altered:

 -        $methods['category'] = 'project';
+        $methods['category'] = t('category'); 

3.

vladimir.dolgopolov’s picture

1. Yes, my bad

2. I think no, because we had added this to find out the proper module

// Set the $module variable to the module that implements this method.
foreach (module_implements('project_sort_methods') as $module) {
  if (in_array(module_invoke($module, 'project_sort_methods', 'methods'), $sort_methods)) {
    break;
  }
}
vladimir.dolgopolov’s picture

StatusFileSize
new2.46 KB

Here is new patch.

I'd removed translation of taxonomy term.

But about (2) - it's still here. So we need more tests about it.

hass’s picture

Status: Needs work » Needs review

Shouldn't this CNR for now?

aclight’s picture

Status: Needs review » Needs work

This doesn't seem right:

-                 'title' => t('Browse by !sort_method', array('!sort_method' => $sort_method)),
+                 'title' => t('by @sort_method', array('@sort_method' => $sort_methods[$sort_method])),

What happened to the "Browse" part?

hass’s picture

Status: Needs work » Closed (won't fix)

5 years no progress and D6 seems not having these strings. Closing.