? .bzr ? 357529-views_translatable-139.patch ? 635990-views_cache_respect_rewrite_substitutions-v3-3_0.patch ? 669636_0.patch ? 773036-bad-exposed-form-check-in-arguments.patch ? 776830-fix-use-pager-no-whitespace.patch ? 783798-fix-group_by-sort.patch ? 833790-fix-click-sort-on-formula-fields_0_0.patch ? 868990-set-use-pager-now-gone-in-views-3.patch ? 978864_add_area_item.patch ? 979046-views_access-2.patch ? 983460-table-default_sort.patch ? _983606.views_.tabs_on_export_results-D6.patch ? drupal.org files issues views_910864_0.txt ? multiple-views-pager_0.patch ? taxonomy_default_argument-2x-2-684608.patch ? views ? views-date_now_form_validation-dev.patch ? views-links-2.patch ? modules/node/views-make-link-3.0-V2.patch Index: views_ui.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/views_ui.module,v retrieving revision 1.109.2.5 diff -u -p -r1.109.2.5 views_ui.module --- views_ui.module 13 Aug 2010 23:18:53 -0000 1.109.2.5 +++ views_ui.module 30 Nov 2010 23:59:11 -0000 @@ -251,6 +251,10 @@ function views_ui_cache_load($name) { // Check to see if someone else is already editing this view. global $user; $view->locked = db_fetch_object(db_query("SELECT s.uid, v.updated FROM {views_object_cache} v INNER JOIN {sessions} s ON v.sid = s.sid WHERE s.sid != '%s' and v.name = '%s' and v.obj = 'view' ORDER BY v.updated ASC", session_id(), $view->name)); + // Set a flag to indicate that this view is being edited. + // This flag will be used e.g. to determine whether strings + // should be localized. + $view->editing = TRUE; } } Index: help/localization.html =================================================================== RCS file: help/localization.html diff -N help/localization.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ help/localization.html 30 Nov 2010 23:59:11 -0000 @@ -0,0 +1,30 @@ + +

On multilingual sites, custom and overridden views may contain text that could be translated into one or more languages. Views makes this data available for translation.

+ +

You can select which localization plugin to use at Administer >> Site building >> Views >> Tools. By default, Views supports "None" (don't localize these strings) and "Core" (use Drupal core's t() function).

+ +

While it "works", the Core plugin is not recommended, as it doesn't support updates to existing strings. If you need to translate Views labels into other languages, consider installing the Internationalization package's Views translation module.

+ +

To prevent security issues, you may wish to install the PHP translation module, also part of the Internationalization package. + +When this module is installed, PHP code is replaced with placeholders before being passed for translation. For example, a header with the following text + +Welcome, you are visitor number <?php echo visitor_count(); ?>. + +would be passed as + +Welcome, you are visitor number !php0. + +As well as addressing potential security holes, using placeholders in translations avoids presenting confusing code to translators.

+ +

To prevent the possible insertion of additional PHP in translations, translated text is passed through strip_tags(), a function used to strip out PHP and HTML tags from text.

+ +

If you have enabled PHP translation and wish to retain some HTML in e.g. a header or footer that accepts PHP: + +

+ +Following this approach will ensure that you can retain a subset of HTML tags while safely using PHP in translatable Views text.

Index: includes/admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/admin.inc,v retrieving revision 1.154.2.45 diff -u -p -r1.154.2.45 admin.inc --- includes/admin.inc 30 Nov 2010 20:54:05 -0000 1.154.2.45 +++ includes/admin.inc 30 Nov 2010 23:59:14 -0000 @@ -3220,6 +3220,7 @@ function views_ui_config_item_form_submi // Create a new handler and unpack the options from the form onto it. We // can use that for storage. $handler = views_get_handler($item['table'], $item['field'], $type); + $handler->init($form_state['view'], $item); // Add the incoming options to existing options because items using // the extra form may not have everything in the form here. @@ -3685,6 +3686,14 @@ function views_ui_admin_tools() { '#default_value' => variable_get('views_no_javascript', FALSE), ); + $form['views_localization_plugin'] = array( + '#type' => 'radios', + '#title' => t('Translation method'), + '#options' => views_fetch_plugin_names('localization', NULL, array(), TRUE), + '#default_value' => variable_get('views_localization_plugin', 'core'), + '#description' => t('Select a translation method to use for Views data like header, footer, and empty text.'), + ); + $regions = system_region_list(variable_get('theme_default', 'garland')); $regions['watchdog'] = t('Watchdog'); Index: includes/base.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/base.inc,v retrieving revision 1.2.2.6 diff -u -p -r1.2.2.6 base.inc --- includes/base.inc 27 Jul 2010 22:03:10 -0000 1.2.2.6 +++ includes/base.inc 30 Nov 2010 23:59:15 -0000 @@ -76,7 +76,7 @@ class views_object { * Unpack options over our existing defaults, drilling down into arrays * so that defaults don't get totally blown away. */ - function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE) { + function unpack_options(&$storage, $options, $definition = NULL, $all = TRUE, $check = TRUE, $localization_keys = array()) { if ($check && !is_array($options)) { return; } @@ -84,6 +84,12 @@ class views_object { if (!isset($definition)) { $definition = $this->option_definition(); } + + if (!empty($this->view)) { + // Ensure we have a localization plugin. + $this->view->init_localization(); + } + foreach ($options as $key => $value) { if (is_array($value)) { // Ignore arrays with no definition. @@ -103,11 +109,28 @@ class views_object { continue; } - $this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE); - } - else if (!empty($definition[$key]['translatable']) && !empty($value)) { - $storage[$key] = t($value); + $this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE, array_merge($localization_keys, array($key))); } + // Don't localize strings during editing. When editing, we need to work with + // the original data, not the translated version. + else if (empty($this->view->editing) && !empty($definition[$key]['translatable']) && !empty($value) || !empty($definition['contains'][$key]['translatable']) && !empty($value)) { + if (!empty($this->view) && $this->view->is_translatable()) { + // Allow other modules to make changes to the string before it's + // sent for translation. + // The $keys array is built from the view name, any localization keys + // sent in, and the name of the property being processed. + $translation_data = array( + 'value' => $value, + 'format' => isset($options[$key . '_format']) ? $options[$key . '_format'] : NULL, + 'keys' => array_merge(array($this->view->name), $localization_keys, array($key)), + ); + $storage[$key] = $this->view->localization_plugin->translate($translation_data); + } + // Otherwise, this is a code-based string, so we can use t(). + else { + $storage[$key] = t($value); + } + } else if ($all || !empty($definition[$key])) { $storage[$key] = $value; } @@ -196,4 +219,82 @@ class views_object { } return $output; } + + /** + * Unpacks each handler to store translatable texts. + */ + function unpack_translatables(&$translatable, $parents = array()) { + foreach ($this->option_definition() as $option => $definition) { + $this->unpack_translatable($translatable, $this->options, $option, $definition, $parents, array()); + } + } + + /** + * Unpack a single option definition. + * + * This function run's through all suboptions recursive. + * + * @param $translatable + * Stores all availible translatable items. + * @param $storage + * @param $option + * @param $definition + * @param $parents + * @param $keys + */ + function unpack_translatable(&$translatable, $storage, $option, $definition, $parents, $keys = array()) { + // Do not export options for which we have no settings. + if (!isset($storage[$option])) { + return; + } + + // Special handling for some items + if (isset($definition['unpack_translatable']) && method_exists($this, $definition['unpack_translatable'])) { + return $this->{$definition['unpack_translatable']}($translatable, $storage, $option, $definition, $parents, $keys); + } + + if (isset($definition['translatable'])) { + if ($definition['translatable'] === FALSE) { + return; + } + } + + // Add the current option to the parents tree. + $parents[] = $option; + + // If it has child items, unpack those separately. + if (isset($definition['contains'])) { + foreach ($definition['contains'] as $sub_option => $sub_definition) { + $translation_keys = array_merge($keys, array($sub_option)); + $this->unpack_translatable($translatable, $storage[$option], $sub_option, $sub_definition, $parents, $translation_keys); + } + } + + // @todo Figure out this double definition stuff. + $options = $storage[$option]; + if (is_array($options)) { + foreach ($options as $key => $value) { + $translation_keys = array_merge($keys, array($key)); + if (is_array($value)) { + $this->unpack_translatable($translatable, $storage, $key, $definition, $parents, $translation_keys); + } + else if (!empty($definition[$key]['translatable']) && !empty($value)) { + // Build source data and add to the array + $translatable[] = array( + 'value' => $value, + 'keys' => $translation_keys, + 'format' => isset($options[$key . '_format']) ? $options[$key . '_format'] : NULL, + ); + } + } + } + else if (!empty($definition['translatable']) && !empty($options)) { + $value = $options; + // Build source data and add to the array + $translatable[] = array( + 'value' => $value, + 'keys' => isset($translation_keys) ? $translation_keys : $parents, + ); + } + } } Index: includes/plugins.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/plugins.inc,v retrieving revision 1.152.2.12 diff -u -p -r1.152.2.12 plugins.inc --- includes/plugins.inc 18 Nov 2010 21:22:55 -0000 1.152.2.12 +++ includes/plugins.inc 30 Nov 2010 23:59:15 -0000 @@ -329,7 +329,30 @@ function views_views_plugins() { 'parent' => 'full', ), ), + 'localization' => array( + 'parent' => array( + 'no ui' => TRUE, + 'handler' => 'views_plugin_localization', + 'parent' => '', + ), + 'none' => array( + 'title' => t('None'), + 'help' => t('Do not pass admin strings for translation.'), + 'handler' => 'views_plugin_localization_none', + 'help topic' => 'localization-none', + ), + 'core' => array( + 'title' => t('Core'), + 'help' => t("Use Drupal core t() function. Not recommended, as it doesn't support updates to existing strings."), + 'handler' => 'views_plugin_localization_core', + 'help topic' => 'localization-core', + ), + ), ); + // Add a help message pointing to the i18views module if it is not present. + if (!module_exists('i18nviews')) { + $plugins['localization']['core']['help'] .= ' ' . t('If you need to translate Views labels into other languages, consider installing the Internationalization package\'s Views translation module.', array('!path' => url('http://drupal.org/project/i18n', array('absolute' => TRUE)))); + } if (module_invoke('ctools', 'api_version', '1.3')) { $plugins['style']['jump_menu_summary'] = array( Index: includes/view.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/view.inc,v retrieving revision 1.151.2.45 diff -u -p -r1.151.2.45 view.inc --- includes/view.inc 18 Nov 2010 23:05:56 -0000 1.151.2.45 +++ includes/view.inc 30 Nov 2010 23:59:16 -0000 @@ -23,6 +23,7 @@ class view extends views_db_object { // State variables var $built = FALSE; var $executed = FALSE; + var $editing = FALSE; var $args = array(); var $build_info = array(); @@ -1477,6 +1478,15 @@ class view extends views_db_object { $output .= $display->handler->export_options($indent, '$handler->options'); } + // Give the localization system a chance to export translatables to code. + if ($this->init_localization()) { + $this->export_locale_strings('export'); + $translatables = $this->localization_plugin->export_render($indent); + if (!empty($translatables)) { + $output .= $translatables; + } + } + return $output; } @@ -1610,6 +1620,71 @@ class view extends views_db_object { return $errors ? $errors : TRUE; } + + /** + * Find and initialize the localizer plugin. + */ + function init_localization() { + if (isset($this->localization_plugin) && is_object($this->localization_plugin)) { + return TRUE; + } + + $this->localization_plugin = views_get_plugin('localization', variable_get('views_localization_plugin', 'core')); + + if (empty($this->localization_plugin)) { + return FALSE; + } + + /** + * Figure out whether there should be options. + */ + $this->localization_plugin->init($this); + + return $this->localization_plugin->translate; + } + + /** + * Determine whether a view supports admin string translation. + */ + function is_translatable() { + // If the view is normal or overridden, use admin string translation. + // A newly created view won't have a type. Accept this. + return (!isset($this->type) || in_array($this->type, array(t('Normal'), t('Overridden')))) ? TRUE : FALSE; + } + + /** + * Send strings for localization. + */ + function save_locale_strings() { + $this->process_locale_strings('save'); + } + + /** + * Delete localized strings. + */ + function delete_locale_strings() { + $this->process_locale_strings('delete'); + } + + /** + * Export localized strings. + */ + function export_locale_strings() { + $this->process_locale_strings('export'); + } + + /** + * Process strings for localization, deletion or export to code. + */ + function process_locale_strings($op) { + // Ensure this view supports translation, we have a display, and we + // have a localization plugin. + // @fixme Export does not init every handler. + if (($this->is_translatable() || $op == 'export') && $this->init_display() && $this->init_localization()) { + $this->localization_plugin->process_locale_strings($op); + } + } + } /** Index: plugins/views_plugin_display.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/views_plugin_display.inc,v retrieving revision 1.20.2.48 diff -u -p -r1.20.2.48 views_plugin_display.inc --- plugins/views_plugin_display.inc 30 Nov 2010 22:57:50 -0000 1.20.2.48 +++ plugins/views_plugin_display.inc 30 Nov 2010 23:59:19 -0000 @@ -397,12 +397,12 @@ class views_plugin_display extends views // and therefore need special handling. 'access' => array( 'contains' => array( - 'type' => array('default' => 'none', 'export' => 'export_plugin'), + 'type' => array('default' => 'none', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'), ), ), 'cache' => array( 'contains' => array( - 'type' => array('default' => 'none', 'export' => 'export_plugin'), + 'type' => array('default' => 'none', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'), ), ), 'query' => array( @@ -419,13 +419,13 @@ class views_plugin_display extends views // should be copied. 'exposed_form' => array( 'contains' => array( - 'type' => array('default' => 'basic', 'export' => 'export_plugin'), + 'type' => array('default' => 'basic', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'), 'options' => array('default' => array(), 'export' => FALSE), ), ), 'pager' => array( 'contains' => array( - 'type' => array('default' => 'full', 'export' => 'export_plugin'), + 'type' => array('default' => 'full', 'export' => 'export_plugin', 'unpack_translatable' => 'unpack_plugin'), 'options' => array('default' => array(), 'export' => FALSE), ), ), @@ -436,6 +436,7 @@ class views_plugin_display extends views 'style_plugin' => array( 'default' => 'default', 'export' => 'export_style', + 'unpack_translatable' => 'unpack_style', ), 'style_options' => array( 'default' => array(), @@ -444,6 +445,7 @@ class views_plugin_display extends views 'row_plugin' => array( 'default' => 'fields', 'export' => 'export_style', + 'unpack_translatable' => 'unpack_style', ), 'row_options' => array( 'default' => array(), @@ -457,14 +459,17 @@ class views_plugin_display extends views 'header' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', ), 'footer' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', ), 'empty' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', ), // We want these to export last. @@ -472,18 +477,23 @@ class views_plugin_display extends views 'relationships' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', + ), 'fields' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', ), 'sorts' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', ), 'arguments' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', ), 'filter_groups' => array( 'contains' => array( @@ -494,6 +504,7 @@ class views_plugin_display extends views 'filters' => array( 'default' => array(), 'export' => 'export_handler', + 'unpack_translatable' => 'unpack_handler', ), ); @@ -2389,6 +2400,82 @@ class views_plugin_display extends views return $output; } + + function unpack_style($indent, $prefix, $storage, $option, $definition, $parents) { + $output = ''; + $style_plugin = $this->get_plugin(); + if ($option == 'style_plugin') { + $type = 'style'; + $options_field = 'style_options'; + $plugin = $style_plugin; + } + else { + if (!$style_plugin || !$style_plugin->uses_row_plugin()) { + return; + } + + $type = 'row'; + $options_field = 'row_options'; + $plugin = $this->get_plugin('row'); + // If the style plugin doesn't use row plugins, don't even bother. + } + + if ($plugin) { + return $plugin->unpack_translatables($translatable, $parents); + } + } + + /** + * Special handling for plugin unpacking. + */ + function unpack_plugin(&$translatable, $storage, $option, $definition, $parents) { + $plugin_type = end($parents); + $plugin = $this->get_plugin($plugin_type); + if ($plugin) { + // Write which plugin to use. + return $plugin->unpack_translatables($translatable, $parents); + } + } + + /** + * Special method to unpack items that have handlers. + * + * This method was specified in the option_definition() as the method to utilize to + * export fields, filters, sort criteria, relationships and arguments. This passes + * the export off to the individual handlers so that they can export themselves + * properly. + */ + function unpack_handler(&$translatable, $storage, $option, $definition, $parents) { + $output = ''; + + // cut the 's' off because the data is stored as the plural form but we need + // the singular form. Who designed that anyway? Oh yeah, I did. :( + if ($option != 'header' && $option != 'footer' && $option != 'empty') { + $type = substr($option, 0, -1); + } + else { + $type = $option; + } + $types = views_object_types(); + foreach ($storage[$option] as $id => $info) { + if (!empty($types[$type]['type'])) { + $handler_type = $types[$type]['type']; + } + else { + $handler_type = $type; + } + $handler = views_get_handler($info['table'], $info['field'], $handler_type); + if ($handler) { + $handler->init($this->view, $info); + $handler->unpack_translatables($translatable, array_merge($parents, array($handler_type, $info['table'], $info['field']))); + } + + // Prevent reference problems. + unset($handler); + } + + return $output; + } } Index: plugins/views_plugin_exposed_form.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/views_plugin_exposed_form.inc,v retrieving revision 1.1.2.12 diff -u -p -r1.1.2.12 views_plugin_exposed_form.inc --- plugins/views_plugin_exposed_form.inc 13 Aug 2010 22:52:07 -0000 1.1.2.12 +++ plugins/views_plugin_exposed_form.inc 30 Nov 2010 23:59:19 -0000 @@ -165,12 +165,12 @@ class views_plugin_exposed_form extends function exposed_form_alter(&$form, &$form_state) { if (!empty($this->options['reset_button'])) { $form['reset'] = array( - '#value' => t($this->options['reset_button_label']), + '#value' => $this->options['reset_button_label'], '#type' => 'submit', ); } - $form['submit']['#value'] = t($this->options['submit_button']); + $form['submit']['#value'] = $this->options['submit_button']; // Check if there is exposed sorts for this view $exposed_sorts = array(); foreach ($this->view->sort as $id => $handler) { @@ -186,8 +186,8 @@ class views_plugin_exposed_form extends '#title' => t($this->options['exposed_sorts_label']), ); $sort_order = array( - 'ASC' => t($this->options['sort_asc_label']), - 'DESC' => t($this->options['sort_desc_label']), + 'ASC' => $this->options['sort_asc_label'], + 'DESC' => $this->options['sort_desc_label'], ); $first_sort = reset($this->view->sort); $form['sort_order'] = array( @@ -227,7 +227,7 @@ class views_plugin_exposed_form extends * $view->exposed_raw_input */ function exposed_form_submit(&$form, &$form_state, &$exclude) { - if (!empty($form_state['values']['op']) && $form_state['values']['op'] == t($this->options['reset_button_label'])) { + if (!empty($form_state['values']['op']) && $form_state['values']['op'] == $this->options['reset_button_label']) { $this->reset_form($form, $form_state); } if (isset($form_state['pager_plugin'])) { Index: plugins/views_plugin_localization.inc =================================================================== RCS file: plugins/views_plugin_localization.inc diff -N plugins/views_plugin_localization.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ plugins/views_plugin_localization.inc 30 Nov 2010 23:59:19 -0000 @@ -0,0 +1,156 @@ +view = &$view; + } + + /** + * Translate a string / text with format + * + * The $source parameter is an array with the following elements: + * - value, source string + * - format, input format in case the text has some format to be applied + * - keys. An array of keys to identify the string. Generally constructed from + * view name, display_id, and a property, e.g., 'header'. + * + * @param $source + * Full data for the string to be translated. + * + * @return string + * Translated string / text + */ + function translate($source) { + // Allow other modules to make changes to the string before and after translation + $source['pre_process'] = $this->invoke_translation_process($source, 'pre'); + $source['translation'] = $this->translate_string($source['value'], $source['keys']); + $source['post_process'] = $this->invoke_translation_process($source, 'post'); + return $source['translation']; + } + + /** + * Translate a string. + * + * @param $string + * The string to be translated. + * @param $keys + * An array of keys to identify the string. Generally constructed from + * view name, display_id, and a property, e.g., 'header'. + */ + function translate_string($string, $keys = array()) {} + + /** + * Save string source for translation. + * + * @param $source + * Full data for the string to be translated. + */ + function save($source) { + // Allow other modules to make changes to the string before saving + $source['pre_process'] = $this->invoke_translation_process($source, 'pre'); + $this->save_string($source['value'], $source['keys']); + } + + /** + * Save a string for translation + * + * @param $string + * The string to be translated. + * @param $keys + * An array of keys to identify the string. Generally constructed from + * view name, display_id, and a property, e.g., 'header'. + */ + function save_string($string, $keys = array()) {} + + /** + * Delete a string. + * + * @param $source + * Full data for the string to be translated. + */ + function delete($source) { } + + /** + * Collect strings to be exported to code. + * + * @param $source + * Full data for the string to be translated. + */ + function export($source) { } + + /** + * Render any collected exported strings to code. + * + * @param $indent + * An optional indentation for prettifying nested code. + */ + function export_render($indent = ' ') { } + + /** + * Invoke hook_translation_pre_process() or hook_translation_post_process(). + * + * Like node_invoke_nodeapi(), this function is needed to enable both passing + * by reference and fetching return values. + */ + function invoke_translation_process(&$value, $op) { + $return = array(); + $hook = 'translation_' . $op . '_process'; + foreach (module_implements($hook) as $module) { + $function = $module . '_' . $hook; + $result = $function($value); + if (isset($result)) { + $return[$module] = $result; + } + } + return $return; + } + + function process_locale_strings($op) { + $this->view->init_display(); + + foreach ($this->view->display as $display_id => $display) { + $translatable = array(); + // Special handling for display title. + if (isset($display->display_title)) { + $translatable[] = array('value' => $display->display_title, 'keys' => array('display_title')); + } + // Unpack handlers. + $this->view->display[$display_id]->handler->unpack_translatables($translatable); + foreach ($translatable as $data) { + $data['keys'] = array_merge(array($this->view->name, $display_id), $data['keys']); + switch ($op) { + case 'save': + $this->save($data); + break; + case 'delete': + $this->delete($data); + break; + case 'export': + $this->export($data); + break; + } + } + } + } +} Index: plugins/views_plugin_localization_core.inc =================================================================== RCS file: plugins/views_plugin_localization_core.inc diff -N plugins/views_plugin_localization_core.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ plugins/views_plugin_localization_core.inc 30 Nov 2010 23:59:19 -0000 @@ -0,0 +1,104 @@ +language == 'en') { + $changed = TRUE; + $languages = language_list(); + $cached_language = $language; + unset($languages['en']); + $language = current($languages); + } + + t($string); + + if (isset($cached_language)) { + $language = $cached_language; + } + return TRUE; + } + + /** + * Delete a string. + * + * Deletion is not supported. + * + * @param $source + * Full data for the string to be translated. + */ + function delete($source) { + return FALSE; + } + + /** + * Collect strings to be exported to code. + * + * String identifiers are not supported so strings are anonymously in an array. + * + * @param $source + * Full data for the string to be translated. + */ + function export($source) { + if (!empty($source['value'])) { + $this->export_strings[] = $source['value']; + } + } + + /** + * Render any collected exported strings to code. + * + * @param $indent + * An optional indentation for prettifying nested code. + */ + function export_render($indent = ' ') { + $output = ''; + if (!empty($this->export_strings)) { + $this->export_strings = array_unique($this->export_strings); + $output = $indent . '$translatables[\'' . $this->view->name . '\'] = array(' . "\n"; + foreach ($this->export_strings as $string) { + $output .= $indent . " t('" . str_replace("'", "\'", $string) . "'),\n"; + } + $output .= $indent . ");\n"; + } + return $output; + } +} Index: plugins/views_plugin_localization_none.inc =================================================================== RCS file: plugins/views_plugin_localization_none.inc diff -N plugins/views_plugin_localization_none.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ plugins/views_plugin_localization_none.inc 30 Nov 2010 23:59:19 -0000 @@ -0,0 +1,37 @@ +translated_strings[] = $string; + return $string . "-translated"; + } + + /** + * Store the export strings. + */ + function export($source) { + if (!empty($source['value'])) { + $this->export_strings[] = $source['value']; + } + } + + /** + * Return the stored strings for the simpletest. + */ + function get_export_strings() { + return $this->export_strings; + } +} Index: tests/views_query.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/tests/Attic/views_query.test,v retrieving revision 1.1.4.5 diff -u -p -r1.1.4.5 views_query.test --- tests/views_query.test 25 Nov 2010 20:17:11 -0000 1.1.4.5 +++ tests/views_query.test 30 Nov 2010 23:59:19 -0000 @@ -93,7 +93,7 @@ abstract class ViewsTestCase extends Dru abstract class ViewsSqlTest extends ViewsTestCase { protected function setUp() { - parent::setUp('views'); + parent::setUp('views', 'views_ui'); // Define the schema and views data variable before enabling the test module. variable_set('views_test_schema', $this->schemaDefinition()); @@ -255,13 +255,6 @@ abstract class ViewsSqlTest extends View return $data; } - /* - * The views plugin definition. Override it if you test provides a plugin. - */ - protected function viewsPlugins() { - return array(); - } - /** * A very simple test dataset. */ Index: tests/views_translatable.test =================================================================== RCS file: tests/views_translatable.test diff -N tests/views_translatable.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/views_translatable.test 30 Nov 2010 23:59:20 -0000 @@ -0,0 +1,150 @@ + 'Views Translatable Test', + 'description' => 'Tests the pluggable translations', + 'group' => 'Views', + ); + } + + /* + * The views plugin definition. Override it if you test provides a plugin. + */ + public function viewsPlugins() { + return array( + 'localization' => array( + 'test' => array( + 'no ui' => TRUE, + 'title' => t('Test'), + 'help' => t('This is a test description.'), + 'handler' => 'views_plugin_localization_test', + 'parent' => 'parent', + 'path' => drupal_get_path('module', 'views') .'/tests', + ), + ), + ); + } + + public function setUp() { + parent::setUp(); + + variable_set('views_localization_plugin', 'test'); + // Reset the plugin data. + views_fetch_plugin_data(NULL, NULL, TRUE); + $this->strings = array('Defaults1', 'Apply1', 'Sort By1', 'Asc1', 'Desc1', 'more1', 'Reset1', 'Offset1', 'Defaults1', 'title1', 'Items per page1', 'fieldlabel1', 'filterlabel1'); + } + + /** + * Test the unpack translation funtionality. + */ + public function testUnpackTranslatable() { + $view = $this->view_unpack_translatable(); + $view->init_localization(); + + $this->assertEqual('views_plugin_localization_test', get_class($view->localization_plugin), 'Take sure that init_localization initiales the right translation plugin'); + + $view->export_locale_strings(); + + $expected_strings = $this->strings; + $result_strings = $view->localization_plugin->get_export_strings(); + $this->assertEqual(sort($expected_strings), sort($result_strings), 'Take sure that the localisation plugin got every translatable string.'); + } + + public function testUi() { + // Take sure that the string is not translated on the ui. + $view = $this->view_unpack_translatable(); + $view->save(); + views_invalidate_cache(); + + $admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration')); + $this->drupalLogin($admin_user); + + $this->drupalGet("admin/build/views/edit/$view->name"); + $this->assertNoText('-translated', 'Take sure that no strings get\'s translated in the ui.'); + } + + /** + * Take sure that the translations get's into the loaded view. + */ + public function testTranslation() { + $view = $this->view_unpack_translatable(); + $view->set_display('default'); + $view->pre_execute(); + $view->execute(); + + $expected_strings = array(); + foreach ($this->strings as $string) { + $expected_strings[] = $string .= '-translated'; + } + $this->assertEqual(sort($expected_strings), sort($view->localization_plugin->translated_strings), 'Take sure that every string got loaded translated'); + } + + public function view_unpack_translatable() { + $view = new view; + $view->name = 'view_unpack_translatable'; + $view->description = ''; + $view->tag = ''; + $view->base_table = 'node'; + $view->api_version = '3.0-alpha1'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Defaults */ + $handler = $view->new_display('default', 'Defaults1', 'default'); + $handler->display->display_options['title'] = 'title1'; + $handler->display->display_options['use_more_text'] = 'more1'; + $handler->display->display_options['access']['type'] = 'none'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['exposed_form']['options']['submit_button'] = 'Apply1'; + $handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE; + $handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Reset1'; + $handler->display->display_options['exposed_form']['options']['exposed_sorts_label'] = 'Sort By1'; + $handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Asc1'; + $handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Desc1'; + $handler->display->display_options['pager']['type'] = 'full'; + $handler->display->display_options['pager']['options']['items_per_page'] = '10'; + $handler->display->display_options['pager']['options']['offset'] = '0'; + $handler->display->display_options['pager']['options']['id'] = '0'; + $handler->display->display_options['pager']['options']['expose']['items_per_page'] = TRUE; + $handler->display->display_options['pager']['options']['expose']['items_per_page_label'] = 'Items per page1'; + $handler->display->display_options['pager']['options']['expose']['offset'] = TRUE; + $handler->display->display_options['pager']['options']['expose']['offset_label'] = 'Offset1'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'fields'; + /* Field: Node: Nid */ + $handler->display->display_options['fields']['nid']['id'] = 'nid'; + $handler->display->display_options['fields']['nid']['table'] = 'node'; + $handler->display->display_options['fields']['nid']['field'] = 'nid'; + $handler->display->display_options['fields']['nid']['label'] = 'fieldlabel1'; + $handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0; + $handler->display->display_options['fields']['nid']['alter']['make_link'] = 0; + $handler->display->display_options['fields']['nid']['alter']['trim'] = 0; + $handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1; + $handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1; + $handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0; + $handler->display->display_options['fields']['nid']['alter']['html'] = 0; + $handler->display->display_options['fields']['nid']['hide_empty'] = 0; + $handler->display->display_options['fields']['nid']['empty_zero'] = 0; + $handler->display->display_options['fields']['nid']['link_to_node'] = 0; + /* Filter: Node: Nid */ + $handler->display->display_options['filters']['nid']['id'] = 'nid'; + $handler->display->display_options['filters']['nid']['table'] = 'node'; + $handler->display->display_options['filters']['nid']['field'] = 'nid'; + $handler->display->display_options['filters']['nid']['exposed'] = TRUE; + $handler->display->display_options['filters']['nid']['expose']['operator'] = 'nid_op'; + $handler->display->display_options['filters']['nid']['expose']['label'] = 'filterlabel1'; + $handler->display->display_options['filters']['nid']['expose']['identifier'] = 'nid'; + $handler->display->display_options['filters']['nid']['expose']['single'] = 0; + $handler->display->display_options['filters']['nid']['expose']['reduce'] = 0; + + return $view; + } +}