4

As far as I see the view titles are not translatable. As a quick fix I just created a new views-view.tpl.php file and changed the line 32 from:

<?php print $title; ?>

to

<?php print t($title); ?> 

What do you think? Is this a right method?

3

The proper way to use t() with a non-literal is to pass in the string as a replacement like so:

<?php print t('@title', array('@title' => $title)); ?>

The function comments on t() contain a very descriptive explanation of why this is necessary so I won't re-hash it here.

  • 3
    That doesn't solve the OP's problem of translating the title. – Andy Aug 7 '12 at 10:41
  • 2
    @Andy Yep, I was responding to "What do you think? Is this a right method?", which it isn't. There's a discussion here that suggests views titles should be translatable out of the box with the il8n views module, which makes the question moot anyway. – Clive Aug 7 '12 at 10:49
  • thanks for link, there's also the i18nviews project, which probably covers this ground but doesn't have a stable release for 7. Was surprised to see that a Views export didn't wrap string literals in t() - you don't happen to know why that might be do you? (In fact I'm sure it used to, though that might be my memory.) – Andy Aug 7 '12 at 10:55
  • I think it's because a views export is a nested structure and gets evaluated directly as PHP when it's imported...if the t() function was added it would be called when this import happens, which would be wrong (as the strings should only be translated on-demand, not by default). That's just a guess though, could be way off :) – Clive Aug 7 '12 at 10:58
  • thanks clive, I get it done following the link. But I didn´t find the Views Translation module. I just installed the i18nviews module instead and get the view titles translated in admin/config/regional/translate/translate – chefnelone Aug 7 '12 at 12:34
16

I find existing answers rather confusing.

Views (as we know) is extremely cool module. It supports localization plugins. Go to page admin/structure/views/settings/advanced to see for yourself: enter image description here

  1. Preferred way to translate Views is to use Internationalization Views module which depends on i18n_string (i18n package) module.
    How to use? Just enable Internationalization Views and go to translate page for your view. enter image description here
    You also may be interested in i18n_string settings here: admin/config/regional/i18n/strings.

  2. Core localization plugin just do t() for Views titles, headers, footers etc. It's not so flexible and secure, but as a developer you can choose this method in some cases.
    How to use? Nothing special here. Your strings will appear in Drupal translate interface after the first request.

You can disable localisation at all or create your own plugin if you need.

2

Indeed that would not be the the right way to do it. You need to install "Entity Translation", "Internationalization" and "Internationalization Views" modules for doing this. Once you are through with the installation and configuration of these modules, then you can not only translate the title of the views but also the fields in your views as well. Though you will be required to specify the translated strings in the translation interface. Do let me know if you face issues in any of these modules.

1

There is another way to translate "Views" which makes sometimes sense. Have a look at the Viewfield Module. This allows you to embed a view on a node. So you could basically create a content type with some fields and this Viewfield.

Then create a node, choose a view (i recommend to create blocks) and save it. Then translate the node with the usual i18n tools and translate the title and all the other fields you created on this node.

1

I think the right, standard and easy way to translate view title is to install Internationalization views which use Entity type of translation which is newer type of translation in Drupal. I verified it worked well for this purpose. I hope it would be possible translate also view path in future.

1

I've been using entity translation and replaced the title field to0. In a view you need to change the title fields to "Entity translation: Title: translated"

1

May be a tricky way

What I'm doing is by going to Intarface translation (admin/config/regional/translate/translate)-> searching the view title ->Translating as I need Then I edit the view, I click for example on path option and then apply button to get the save's button one.

After saving , the translation will be shown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.