This is a follow-up of https://www.drupal.org/node/1248716.

Issue

When deploying Views with Features and translating those Views with i18nviews default string (next, field-label) are not translatable.

Analysis

When we looked deeper in the translation behaviour of Views + Internationalization Views + Features, one thing came up quite surprisingly:
default values are not translated!

It means that if you create a View with original field-labels or pager texts ("next ›"), then export it to Features and then reset them to the code-state, you have a problem.
This gets very obvious when you enable i18n_string_debug ($ drush vset i18n_string_debug TRUE).
The 'default' values + debug-info won't show up when rendering your view. It does show up as translatable under /admin/config/regional/translate/translate . That makes it only more confusing.
But non-default values (an overridden field-label) do show up (only with patch #5 or #10 from issue https://www.drupal.org/node/1248716 applied, committed in Views -dev version).

The reason that non-default values of a 'default state' View won't get translated is that those values are not exported to code and/or not available when i18n kicks in.
In Drupal 8 this problem is solved by just exporting default values to code (see https://www.drupal.org/node/1938654).
To me, that seems a good solution for 7.x too.

To trigger i18n_string the translatable (a field-label) must be part of the export.

So something like:

/* Field: Content: Title */
  $handler->display->display_options['fields']['title_field']['id'] = 'title_field';
  $handler->display->display_options['fields']['title_field']['table'] = 'field_data_title_field';
  $handler->display->display_options['fields']['title_field']['field'] = 'title_field';

Should be like:

/* Field: Content: Title */
  $handler->display->display_options['fields']['title_field']['id'] = 'title_field';
  $handler->display->display_options['fields']['title_field']['table'] = 'field_data_title_field';
  $handler->display->display_options['fields']['title_field']['field'] = 'title_field';
  $handler->display->display_options['fields']['title_field']['label'] = 'Title';

to trigger i18n_string for the label.

Note: that if you change the default label to something different it will be exported without patching.

Proposed solutions

Export everything that could be translatable

con: UI-strings like 'next, 'previous' must be translated for each View.

Only export user-generated strings that could be translatable

  • Export user-generated default string to code (field-labels)

pro: feels more like a good default behavior
con: what is user-generated: field-labels (sure), text-area messages (no results, summary): guess yes.

Comments

ndf created an issue. See original summary.

ndf’s picture

Issue summary: View changes
ndf’s picture

Patch #11 from issue https://www.drupal.org/node/1248716 . Removed part that is committed.
This patch follows proposed solution 1: Export everything that could be translatable

ndf’s picture

Issue summary: View changes
ndf’s picture

Status: Active » Needs review
chris matthews’s picture

Assigned: ndf » Unassigned
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 3 year old patch in #3 does not apply to the latest views 7.x-3.x-dev and if still relevant needs to be rerolled.

andrew answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new26.42 KB

Patch rerolled.

anrikun’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch at #7 does not apply anymore.
Needs reroll.

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new26.89 KB

Re-rolled the patch. Please have a look.