From 50e9461c8717375af957dbdd50d13ca5459e186e Mon Sep 17 00:00:00 2001
From: Kristiaan Van den Eynde <magentix@gmail.com>
Date: Fri, 12 Apr 2013 12:39:15 +0200
Subject: [PATCH] Issue #1968544 by kristiaanvandeneynde: Simple component
 translation

---
 components/date.inc      |   13 +++++++++++--
 components/email.inc     |   13 +++++++++++--
 components/fieldset.inc  |   13 +++++++++++--
 components/file.inc      |   13 +++++++++++--
 components/grid.inc      |   20 ++++++++++++++++----
 components/hidden.inc    |    7 ++++++-
 components/markup.inc    |    7 ++++++-
 components/number.inc    |   13 +++++++++++--
 components/pagebreak.inc |    7 ++++++-
 components/select.inc    |   15 ++++++++++++---
 components/textarea.inc  |   13 +++++++++++--
 components/textfield.inc |   31 +++++++++++++++++++++++++++----
 components/time.inc      |   13 +++++++++++--
 webform.module           |   20 ++++++++++++++++++++
 14 files changed, 170 insertions(+), 28 deletions(-)

diff --git a/components/date.inc b/components/date.inc
index 40d6ded..358b5b9 100644
--- a/components/date.inc
+++ b/components/date.inc
@@ -119,12 +119,21 @@ function _webform_edit_date($component) {
 function _webform_render_date($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
     '#type' => 'date',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#required' => $component['mandatory'],
     '#start_date' => trim($component['extra']['start_date']),
     '#end_date' => trim($component['extra']['end_date']),
diff --git a/components/email.inc b/components/email.inc
index eb6acfa..e973c0c 100644
--- a/components/email.inc
+++ b/components/email.inc
@@ -114,14 +114,23 @@ function _webform_render_email($component, $value = NULL, $filter = TRUE) {
   global $user;
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
     '#type' => 'webform_email',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#default_value' => $filter ? _webform_filter_values($component['value'], $node) : $component['value'],
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#attributes' => $component['extra']['attributes'],
     '#element_validate'  => array('_webform_validate_email'),
     '#theme_wrappers' => array('webform_element'),
diff --git a/components/fieldset.inc b/components/fieldset.inc
index 6233804..f365b5d 100644
--- a/components/fieldset.inc
+++ b/components/fieldset.inc
@@ -54,12 +54,21 @@ function _webform_edit_fieldset($component) {
 function _webform_render_fieldset($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
     '#type' => 'fieldset',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : NULL,
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#collapsible' => $component['extra']['collapsible'],
     '#collapsed' => $component['extra']['collapsed'],
     '#attributes' => array('class' => array('webform-component-fieldset'), 'id' => 'webform-component-' . $component['form_key']),
diff --git a/components/file.inc b/components/file.inc
index 160119b..0a7c749 100644
--- a/components/file.inc
+++ b/components/file.inc
@@ -305,6 +305,15 @@ function theme_webform_edit_file_extensions($variables) {
 function _webform_render_file($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   // Cap the upload size according to the PHP limit.
   $max_filesize = parse_size(file_upload_max_size());
   $set_filesize = $component['extra']['filtering']['size'];
@@ -314,7 +323,7 @@ function _webform_render_file($component, $value = NULL, $filter = TRUE) {
 
   $element = array(
     '#type' => 'managed_file',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#required' => $component['mandatory'],
     '#default_value' => isset($value[0]) ? $value[0] : NULL,
@@ -326,7 +335,7 @@ function _webform_render_file($component, $value = NULL, $filter = TRUE) {
     '#pre_render' => array_merge(element_info_property('managed_file', '#pre_render'), array('webform_file_allow_access')),
     '#upload_location' => $component['extra']['scheme'] . '://webform/' . $component['extra']['directory'],
     '#progress_indicator' => $component['extra']['progress_indicator'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#weight' => $component['weight'],
     '#theme_wrappers' => array('webform_element'),
     '#translatable' => array('title', 'description'),
diff --git a/components/grid.inc b/components/grid.inc
index 955c526..dfa852f 100644
--- a/components/grid.inc
+++ b/components/grid.inc
@@ -146,15 +146,27 @@ function _webform_edit_grid($component) {
 function _webform_render_grid($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
+  $questions = webform_component_array_t(_webform_select_options_from_text($component['extra']['questions'], TRUE));
+  $options = webform_component_array_t(_webform_select_options_from_text($component['extra']['options'], TRUE));
+
   $element = array(
     '#type' => 'webform_grid',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
-    '#grid_questions' => _webform_select_options_from_text($component['extra']['questions'], TRUE),
-    '#grid_options' => _webform_select_options_from_text($component['extra']['options'], TRUE),
+    '#description' => $description,
+    '#grid_questions' => $questions,
+    '#grid_options' => _$options,
     '#optrand' => $component['extra']['optrand'],
     '#qrand' => $component['extra']['qrand'],
     '#theme' => 'webform_grid',
diff --git a/components/hidden.inc b/components/hidden.inc
index 99e3210..5a23823 100644
--- a/components/hidden.inc
+++ b/components/hidden.inc
@@ -70,6 +70,11 @@ function _webform_edit_hidden($component) {
 function _webform_render_hidden($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
   // Set filtering options for "value" types, which are not displayed to the
   // end user so they do not need to be sanitized.
   $strict = $component['extra']['hidden_type'] != 'value';
@@ -79,7 +84,7 @@ function _webform_render_hidden($component, $value = NULL, $filter = TRUE) {
   }
 
   $element = array(
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#weight' => $component['weight'],
     '#translatable' => array('title'),
   );
diff --git a/components/markup.inc b/components/markup.inc
index 522fba2..c347760 100644
--- a/components/markup.inc
+++ b/components/markup.inc
@@ -68,9 +68,14 @@ function _webform_edit_markup_validate($form, &$form_state) {
 function _webform_render_markup($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? NULL
+    : t($component['name'], array(), $context);
+
   $element = array(
     '#type' => 'markup',
-    '#title' => $filter ? NULL : $component['name'],
+    '#title' => $title,
     '#weight' => $component['weight'],
     '#markup' => $filter ? _webform_filter_values(check_markup($component['value'], $component['extra']['format'], '', TRUE), $node, NULL, NULL, FALSE) : $component['value'],
     '#format' => $component['extra']['format'],
diff --git a/components/number.inc b/components/number.inc
index 8134b49..11e27f9 100644
--- a/components/number.inc
+++ b/components/number.inc
@@ -250,15 +250,24 @@ function theme_webform_number($variables) {
 function _webform_render_number($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#default_value' => $filter ? _webform_filter_values($component['value'], $node, NULL, NULL, FALSE) : $component['value'],
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
     '#field_prefix' => empty($component['extra']['field_prefix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_prefix']) : $component['extra']['field_prefix']),
     '#field_suffix' => empty($component['extra']['field_suffix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_suffix']) : $component['extra']['field_suffix']),
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#attributes' => $component['extra']['attributes'],
     '#element_validate' => array('_webform_validate_number'),
     '#theme_wrappers' => array('webform_element'),
diff --git a/components/pagebreak.inc b/components/pagebreak.inc
index 7a5ad2f..58a5ca6 100644
--- a/components/pagebreak.inc
+++ b/components/pagebreak.inc
@@ -79,9 +79,14 @@ function _webform_render_pagebreak($component, $value = NULL, $filter = TRUE) {
  * Implements _webform_render_component().
  */
 function _webform_display_pagebreak($component, $value = NULL, $format = 'html') {
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
   $element = array(
     '#theme' => 'webform_display_pagebreak',
-    '#title' => $component['name'],
+    '#title' => $title,
     '#weight' => $component['weight'],
     '#format' => $format,
     '#translatable' => array('title'),
diff --git a/components/select.inc b/components/select.inc
index 4450dfc..763f19c 100644
--- a/components/select.inc
+++ b/components/select.inc
@@ -288,12 +288,21 @@ function _webform_edit_validate_set_aslist($options, &$form_state) {
 function _webform_render_select($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#theme_wrappers' => array('webform_element'),
     '#pre_render' => array(), // Needed to disable double-wrapping of radios and checkboxes.
     '#translatable' => array('title', 'description', 'options'),
@@ -301,7 +310,7 @@ function _webform_render_select($component, $value = NULL, $filter = TRUE) {
 
   // Convert the user-entered options list into an array.
   $default_value = $filter ? _webform_filter_values($component['value'], $node, NULL, NULL, FALSE) : $component['value'];
-  $options = _webform_select_options($component, !$component['extra']['aslist'], $filter);
+  $options = webform_component_array_t(_webform_select_options($component, !$component['extra']['aslist'], $filter));
 
   if ($component['extra']['optrand']) {
     _webform_shuffle_options($options);
diff --git a/components/textarea.inc b/components/textarea.inc
index 9dd2387..b3a7ca9 100644
--- a/components/textarea.inc
+++ b/components/textarea.inc
@@ -100,14 +100,23 @@ function _webform_edit_textarea($component) {
 function _webform_render_textarea($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
     '#type' => 'textarea',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#default_value' => $filter ? _webform_filter_values($component['value'], $node) : $component['value'],
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#rows' => !empty($component['extra']['rows']) ? $component['extra']['rows'] : 5,
     '#cols' => !empty($component['extra']['cols']) ? $component['extra']['cols'] : 60,
     '#attributes' => $component['extra']['attributes'],
diff --git a/components/textfield.inc b/components/textfield.inc
index 2a04061..a5e44aa 100644
--- a/components/textfield.inc
+++ b/components/textfield.inc
@@ -124,16 +124,39 @@ function _webform_edit_textfield($component) {
 function _webform_render_textfield($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
+  $field_prefix = empty($component['extra']['field_prefix'])
+    ? NULL
+    : ($filter
+      ? t(_webform_filter_xss($component['extra']['field_prefix']), array(), $context)
+      : t($component['extra']['field_prefix'], array(), $context)
+    );
+
+  $field_suffix = empty($component['extra']['field_suffix'])
+    ? NULL
+    : ($filter
+      ? t(_webform_filter_xss($component['extra']['field_suffix']), array(), $context)
+      : t($component['extra']['field_suffix'], array(), $context)
+    );
+
   $element = array(
     '#type' => 'textfield',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#default_value' => $filter ? _webform_filter_values($component['value'], $node, NULL, NULL, FALSE) : $component['value'],
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#field_prefix' => empty($component['extra']['field_prefix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_prefix']) : $component['extra']['field_prefix']),
-    '#field_suffix' => empty($component['extra']['field_suffix']) ? NULL : ($filter ? _webform_filter_xss($component['extra']['field_suffix']) : $component['extra']['field_suffix']),
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#field_prefix' => $field_prefix,
+    '#field_suffix' => $field_suffix,
+    '#description' => $description,
     '#attributes' => $component['extra']['attributes'],
     '#theme_wrappers' => array('webform_element'),
     '#translatable' => array('title', 'description', 'field_prefix', 'field_suffix'),
diff --git a/components/time.inc b/components/time.inc
index 30a9053..9ad1949 100644
--- a/components/time.inc
+++ b/components/time.inc
@@ -100,13 +100,22 @@ function _webform_edit_time($component) {
 function _webform_render_time($component, $value = NULL, $filter = TRUE) {
   $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
 
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
+  $description = $filter
+    ? t(_webform_filter_descriptions($component['extra']['description'], $node), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
     '#type' => 'webform_time',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
+    '#description' => $description,
     '#element_validate' => array('webform_validate_time'),
     '#hourformat' => $component['extra']['hourformat'],
     '#minuteincrements' => $component['extra']['minuteincrements'],
diff --git a/webform.module b/webform.module
index 5ec7400..3b5693e 100644
--- a/webform.module
+++ b/webform.module
@@ -3999,3 +3999,23 @@ function webform_mollom_form_info($form_id) {
 
   return $form_info;
 }
+
+/**
+ * Runs every array element through t().
+ *
+ * Takes an array of strings for component options, questions, ...
+ * and runs them all through t() with the context 'webform component'.
+ *
+ * @param array $array
+ *   The array to run through t().
+ *
+ * @return array
+ *   The translated array.
+ */
+function webform_component_array_t($array) {
+  foreach ($array as &$item) {
+    $item = t($item, array(), array('context' => 'webform component'));
+  }
+
+  return $array;
+}
-- 
1.7.6.1

