Views titles and text and i18n, a preliminary preface to a dirty hack

Key words and phrases: 
drupal translate views locale localization
Description & Info: 

Internationalization module (i18n) now supports views in a way-- unfortunately I think it hard wires in the

sure how well that works with the preferred "show current language and no language" setting.

And there's still no goddamned "show in the user's preferred language if available, if not in the default language." That's what we need. There shouldn't even be a conceptual hack of "no language" – content is either in a language or it isn't. But all that's another story.

Views.module is not compatible with i18n
http://drupal.org/node/65722

Integration of i18n and views.module = fix translatablity of views
http://drupal.org/node/64004

And the one we're trying to deal with:

i18n Translation and Views: Header/Footer
http://drupal.org/node/89100

A workaround that involves hacking views is offered by JordiTR (May 17, 2006):

I've been facing that trouble on the last two weeks, asking everywhere without solution and it's neither a views.module nor a i18n.module. There are two issues easy to solve:

- the content: needs that you play with Content selection mode on the i18n configuration page, what works best for me is Only current language and no language

- the block title: I've customized the views.module with an extremelly small hack which consists on changing on line 1067 (function views_view_block($vid)) the expression $block['subject'] = '$view->title'; with $block['subject'] = t($view->title); that forces your custom name to that concret view to pass through the locale translator of strings; form here on, after the first time you load that view on your optional language it will add an entry on the locale table which will ready to be translated (and it works!!!) :-)

As far as I know there's no solution in Drupal 5 either.

Places like this will use the tt() function in Drupal 6 for dynamic translatable strings, and maybe this is in the experimental i18n modules Agaric turned off on WSF because they broke the ability to rename custom content (CCK) types.

If we patch views, can we at least do it right and use a call to tt() instead of t() ?

Dirty hacks preferred to

Dirty hacks preferred to experimental i18n modules. This change made to

/**
* This views a view by block. Can be used as a callback or programmatically.
*/
function views_view_block($vid) ...

around line 435 (Drupal 5, final version of Views 1)

  if ($content) {
    $block['content'] = $content;
/* original:
    $block['subject'] = filter_xss_admin(views_get_title($view, 'block'));
*/
// replacement inspired by  http://agaricdesign.com/note/views-titles-and-text-and-i18n-preliminary-...    $block['subject'] = t(views_get_title($view, 'block'));
    return $block;
  }
Posted by Benjamin Melançon on Sat, 2007-11-24 12:17
Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
  _____  __     __   ___    _____   ___ 
|_ _| \ \ / / ( _ ) |___ / |_ _|
| | \ \ / / / _ \ |_ \ | |
| | \ V / | (_) | ___) | | |
|_| \_/ \___/ |____/ |___|
Enter the code depicted in ASCII art style.