Posted by miiimooo on August 6, 2009 at 1:01pm
| Project: | Faceted Search |
| Version: | 6.x-1.0-beta2 |
| Component: | User interface |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Looks like the title gets partly translated. For instance I get News: Afrique du Nord. I can see where it could be changed but I'm not sure what it needs changing to. Should it be tt() if 18n is available?
faceted_search_io.module, 752
<?php
function faceted_search_ui_set_title($env) {
$labels = array();
if ($env->get_text()) {
foreach ($env->get_filters() as $filter) {
if ($filter->is_active()) {
$category = $filter->get_active_category();
// Note: get_label() is responsible for filtering its returned string.
$labels[] = $category->get_label(FALSE);
}
}
}
if (count($labels)) {
drupal_set_title(t('@title: !terms', array('@title' => $env->settings['title'], '!terms' => implode(', ', $labels))));
}
else {
drupal_set_title(check_plain($env->settings['title']));
}
}
?>
Comments
#1
Sorry for bumping this - let me explain a bit more. I currently get the bizarre result where the terms are translated but the title isn't. Should be easy to fix but I don't see how. As I wonder why the terms are correctly translated.
#2
Okay I think I understand how to do this in an i18n way. Here is a possible patch. Note that I'm using an already slightly patched version of the file so let me know if the patch doesn't work. Basically, what it does is this:
<?phpfunction faceted_search_ui_set_title($env) {
$labels = array();
if ($env->get_text()) {
foreach ($env->get_filters() as $filter) {
if ($filter->is_active()) {
$category = $filter->get_active_category();
// Note: get_label() is responsible for filtering its returned string.
$labels[] = $category->get_label(FALSE);
}
}
}
$title = $env->settings['title'];
if (function_exists("tt")) {
$title = tt("faceted_search:title:$title:name", $title);
}
if (count($labels)) {
drupal_set_title(t('@title: !terms', array('@title' => $title, '!terms' => implode(', ', $labels))));
}
else {
drupal_set_title(check_plain($title));
}
}
?>
#3
Hi,
I've just discovered that the environment title and the facet label seem to be the only items that are not translated. The above patch makes the module depend on i18nstrings, which is overkill to the specific problem. The patch included here does not include that dependency and simply wraps the title and facet label in t() calls.
I've tested all the different UI blocks and forms and everything else was translated.
João Ventura
#4
@jcnventura: The documentation for t() clearly states: custom data from user input or other non-code sources should not be passed through t(), so using i18nstrings as proposed by miiimooo is the right way to translate environment names. Similar code is already present in the dev version of Faceted Search.
Translating facets is a separate issue that needs a specific solution for each type of facet, otherwise t() might get called twice on the same text. A specific solution for CCK facets has been committed.
#5
Automatically closed -- issue fixed for 2 weeks with no activity.