I'm using views to make a list of nodes, filtering by the language chosen with i18n. This works great!

But I also want to translate the View's Header and Footer, the text that appears before and after the list. Right now I can't figure out anyway to do this besides creating a separate view.

I'm having this same problem with some of the other modules as well, for instance the contact form. Translation works fine on the form labels, but I don't know how to translate the instructions in the form header.

Can anyone think how to do this? Thanks

Comments

jorditr’s picture

Hi tkrebs, probably your problem is based on the fact that views has not considered to use the t() function to use l10n (localization module) to translate those elements. I've found that on the title of blocks created by views.module on 4.7 and I already found that on the 4.6 version. Look on the code on the parts that create those header and footer elements and add that function.

jorditr’s picture

You'll find a deeper discussion on that thread: 64004.

drupalxykon’s picture

so, whats the recommended way to do this?

t($view->page_header) doesn't work

light-blue’s picture

youcha’s picture

To get the current language code in 6.x

global $language;
$lc = $language->language;
petrovichby’s picture

To translate Views Header I use such simple snippet (Drupal 6.x):

<h1><?php 
	global $language;
	$lc = $language->language;
	if ($lc=="en") print "Photo Gallery";
	if ($lc=="ru") print "Фотогалерея";
	if ($lc=="be") print "Фотагалерэя";
?></h1>
summit’s picture

Hi,
does this still work with views2 and D6?
greetings,
Martijn

andy inman’s picture

My preferred solution is Language Sections.

alexbk66-’s picture

I'm using Views3, it does add t() around footer/header. But now my problem is that I have html in my header text, which isn't allowed for translation.

<div class="item-list"><ul><li> <a href="node/add/blog">Create new Hobby entry</a> </li></ul></div>
The submitted string contains disallowed HTML: <div class="item-list"><ul><li> <a href="node/add/blog">Добавить запись Хобби</a> </li></ul></div>

So I wonder if there's another way to translate the text only, and add HTML somehow?

adr_p’s picture

I can confirm that, it's definitely a problem. You can use different input filters in header/footer and it's more than likely to have html there, or even PHP code. In combination with Features and translations export things can easily mess up. There should be a options to disable unwanted translations.

alexbk66-’s picture

I ended up adding a function in my module which returns the text for header, footer and "empty text", i.e.

<?php
if (function_exists('_hobby_empty_view_text')) print _hobby_empty_view_text();
?>

You can also pass a view name as argument if you want to use the same function in multiple views.