I have a multilingual website in Drupal 7. I have a view to display content and this view is in code in one of my custom module. I am not getting translation when view is in code and works fine when it's in database. Let me try to explain:

  • I added content field and rewrite the output of this field, wrapped with t() and excluded from display. I added another Global custom field and used replacement pattern to display that content field. I exported the view and saved it in code in one of custom module.
  • Now view is in code and everything is working fine as expected in default language (English). When I switched the language, it only show English for that content field and everything else showing translation.
  • I saved the view in Views UI without any change and now view is in database. I refreshed the page and I got the translation.

Any idea or help would be appreciated. Thanks!

Comments

atulkamboj’s picture

Category: Support request » Bug report
Issue summary: View changes
dawehner’s picture

How do you rewrite the output of a field using t() . Views itself does not allow to use PHP in there.

hillaryneaf’s picture

Try writing an update script that saves your view that's in code into the database with $view->save();

When you update the view, you will always need an update script that updates the view in the database:

$view->delete();
ctools_include('object-cache');
ctools_object_cache_clear('view', $view->name);
$view->save();
atulkamboj’s picture

Thanks nektir, I really appreciate your help.

@dawehner, thanks for your reply. I understand, views UI doesn't allow to use PHP and I used t() in exported views code in PHP file inside my custom module.

hillaryneaf’s picture

Status: Active » Closed (works as designed)