I don't know if this belongs in the issue queue for i18n, i18n views, or views, but since it only affects views that are imported through features, I'll start here.

I have a problem with translated views strings (labels, titles etc). Even if the strings are translated, Drupal will show them in their original form until I go into the view and resave it (which I guess causes the view to be moved into the database from the feature file).

This is a problem since as soon as I update a view on my local install, and push it to production I will have to revert the feature on the prod server, which in turn causes the translation to fail again.

Comments

KLicheR’s picture

Problem 1: Views declared in code use t()

A view declared in code, like a Feature, will have the type Default (In code) and will be translated with the "t()" function.
views-7.x-3.3/includes/base.inc line 143

if (!empty($this->view) && $this->view->is_translatable()) {
  // ...
  // bla bla bla, use i18nviews
  // ...
}
// Otherwise, this is a code-based string, so we can use t().
else {
  // use t()
  $storage[$key] = t($value);
}

If you check the function "is_translatable()" you'll see that the type has to be Normal (create with the Views interface and store in the DB) or Overridden (define by code but has been change with the Views interface and so have a entry in the DB).

So you can manually modify the view define in your Feature with the views interface (views_ui) or write a little module to automatically save the view (without any change, $view->save();) so it will exists in the DB and receive the type Overriden.

Problem 2: Translations strings are not created

I'm not sure why but I also have this problem with boxes and i18n_boxes. It's probably because they use externals i18n plugins (i18nviews, i18n_boxes) that don't automatically deal with that.

I've wrote another little module that trigger string refresh process that will create the strings:

/**
 * Implements hook_modules_enabled().
 */
function features_refresh_strings_modules_enabled($modules) {
  foreach ($modules as $module) {
    $path = drupal_get_path('module', $module);
    $info = drupal_parse_info_file($path . '/' . $module . '.info');
    // Check if the module is a feature that contain views or boxes.
    if (isset($info['features'])) {
      if (isset($info['features']['views_view']) && module_exists('i18n_string')) {
        // Use "i18n_string" function to refresh strings.
        i18n_string_refresh_group('views');
      }
      if (isset($info['features']['box']) && module_exists('i18n_boxes')) {
        // Use "i18n_boxes" function to refresh strings.
        i18n_boxes_i18n_string_refresh();
      }
    }
  }
}
Jax’s picture

dbassendine’s picture

In 6.x / Views 3.x, I found that i18nviews actually prevented strings in feature based views from being translated. When i18nviews was disabled, features adds a $translatables array with all the view's strings into the [feature].views_default.inc. These are then available for translation in the standard translation interface. When i18nviews was enabled, drush fu [feature] actually removed those $translatables arrays from the feature.

My solution, therefore, was to remove i18nviews as Views 3.x already has good support for string translation in Features. I'm not sure there's support for translation of Views just in the database.

lecler’s picture

I have tried a hook to resave the views in code (via features) :

function irisa_patches_views_pre_view(&$view, &$display_id, &$args) {
    $views_to_test = array("test_ple");
    if (in_array($view->name, $views_to_test)) {
        if ((strpos(current_path(), "admin/structure/views") !== 0) && isset($view->type) && (strcmp($view->type, t('Default')) == 0)) {
            $view->save();
            cache_clear_all();
        }
    }
}

When I visit a page with the view displayed, the view is saved : Database overriding code. Its title is translated.

But that's not enough : fields labels are not translated. I have to edit the view, click on every field, then apply and save the view to have labels translated.

What am I missing ?

Thanx.