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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 2564947-9.patch | 26.89 KB | suresh prabhu parkala |
Comments
Comment #2
ndf commentedComment #3
ndf commentedPatch #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
Comment #4
ndf commentedComment #5
ndf commentedComment #6
chris matthews commentedThe 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.
Comment #7
andrew answer commentedPatch rerolled.
Comment #8
anrikun commentedPatch at #7 does not apply anymore.
Needs reroll.
Comment #9
suresh prabhu parkala commentedRe-rolled the patch. Please have a look.