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

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

diff --git a/components/date.inc b/components/date.inc
index 6121046..4d54344 100644
--- a/components/date.inc
+++ b/components/date.inc
@@ -117,12 +117,21 @@ function _webform_edit_date($component) {
  * Implements _webform_render_component().
  */
 function _webform_render_date($component, $value = NULL, $filter = TRUE) {
+  $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']), 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']) : $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 a096709..db8a384 100644
--- a/components/email.inc
+++ b/components/email.inc
@@ -108,14 +108,24 @@ function _webform_edit_email_validate($element, &$form_state) {
  */
 function _webform_render_email($component, $value = NULL, $filter = TRUE) {
   global $user;
+
+  $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']), array(), $context)
+    : t($component['extra']['description'], 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' => _webform_filter_values($component['value']),
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $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 92875b4..f26ab92 100644
--- a/components/fieldset.inc
+++ b/components/fieldset.inc
@@ -52,11 +52,20 @@ function _webform_edit_fieldset($component) {
  * Implements _webform_render_component().
  */
 function _webform_render_fieldset($component, $value = NULL, $filter = TRUE) {
+  $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']), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   $element = array(
     '#type' => 'fieldset',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $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 c44541c..265548b 100644
--- a/components/file.inc
+++ b/components/file.inc
@@ -306,6 +306,15 @@ function theme_webform_edit_file($variables) {
  * Implements _webform_render_component().
  */
 function _webform_render_file($component, $value = NULL, $filter = TRUE) {
+  $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']), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
   // Normally every file component is given a unique ID based on its key.
   if (isset($component['nid'])) {
     $node = node_load($component['nid']);
@@ -330,9 +339,9 @@ function _webform_render_file($component, $value = NULL, $filter = TRUE) {
   );
   $element['#webform_component'] = $component;
   $element['#weight'] = $component['weight'];
-  $element['#title'] = $filter ? _webform_filter_xss($component['name']) : $component['name'];
+  $element['#title'] = $title;
   $element['#title_display'] = $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before';
-  $element['#description'] = $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'];
+  $element['#description'] = $description;
 
   $element['#theme'] = 'webform_render_file';
   $element['#theme_wrappers'] = array('webform_element');
diff --git a/components/grid.inc b/components/grid.inc
index 548999d..d1e1e81 100644
--- a/components/grid.inc
+++ b/components/grid.inc
@@ -142,15 +142,27 @@ function _webform_edit_grid($component) {
  * Implements _webform_render_component().
  */
 function _webform_render_grid($component, $value = NULL, $filter = TRUE) {
+  $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']), array(), $context)
+    : t($component['extra']['description'], array(), $context);
+
+  $questions = webform_array_t(_webform_select_options_from_text($component['extra']['questions'], TRUE));
+  $options = webform_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']) : $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 5930da6..2ca4afe 100644
--- a/components/hidden.inc
+++ b/components/hidden.inc
@@ -57,9 +57,14 @@ function _webform_edit_hidden($component) {
  * Implements _webform_render_component().
  */
 function _webform_render_hidden($component, $value = NULL, $filter = TRUE) {
+  $context = array('context' => 'webform component');
+  $title = $filter
+    ? t(_webform_filter_xss($component['name']), array(), $context)
+    : t($component['name'], array(), $context);
+
   $element = array(
     '#type' => 'hidden',
-    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
+    '#title' => $title,
     '#default_value' => $filter ? _webform_filter_values($component['value']) : $component['value'],
     '#weight' => $component['weight'],
   );
diff --git a/components/markup.inc b/components/markup.inc
index 064abf5..85512b7 100644
--- a/components/markup.inc
+++ b/components/markup.inc
@@ -57,9 +57,14 @@ function _webform_edit_markup_validate($form, &$form_state) {
  * Implements _webform_render_component().
  */
 function _webform_render_markup($component, $value = NULL, $filter = TRUE) {
+  $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), NULL, NULL, NULL, FALSE) : $component['value'],
     '#format' => $component['extra']['format'],
diff --git a/components/pagebreak.inc b/components/pagebreak.inc
index 95c838c..01fe01b 100644
--- a/components/pagebreak.inc
+++ b/components/pagebreak.inc
@@ -67,7 +67,7 @@ function _webform_render_pagebreak($component, $value = NULL, $filter = TRUE) {
 function _webform_display_pagebreak($component, $value = NULL, $format = 'html') {
   $element = array(
     '#theme' => 'webform_display_pagebreak',
-    '#title' => $component['name'],
+    '#title' => t($component['name'], array(), array('context' => 'webform component')),
     '#weight' => $component['weight'],
     '#format' => $format,
     '#webform_component' => $component,
diff --git a/components/select.inc b/components/select.inc
index 5f32b72..b384e12 100644
--- a/components/select.inc
+++ b/components/select.inc
@@ -262,12 +262,21 @@ function _webform_edit_validate_options($element, &$form_state) {
  * Implements _webform_render_component().
  */
 function _webform_render_select($component, $value = NULL, $filter = TRUE) {
+  $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']), 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']) : $component['extra']['description'],
+    '#description' => $description,
     '#theme_wrappers' => array('webform_element'),
     '#pre_render' => array(), // Needed to disable double-wrapping of radios and checkboxes.
     '#webform_component' => $component,
@@ -275,7 +284,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'], NULL, NULL, NULL, FALSE) : $component['value'];
-  $options = _webform_select_options($component, $filter);
+  $options = webform_array_t(_webform_select_options($component, $filter));
 
   if ($component['extra']['optrand']) {
     _webform_shuffle_options($options);
diff --git a/components/textarea.inc b/components/textarea.inc
index b60c382..0ee952d 100644
--- a/components/textarea.inc
+++ b/components/textarea.inc
@@ -98,14 +98,23 @@ function _webform_edit_textarea($component) {
  * Implements _webform_render_component().
  */
 function _webform_render_textarea($component, $value = NULL, $filter = TRUE) {
+  $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']), 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']) : $component['value'],
     '#required' => $component['mandatory'],
     '#weight' => $component['weight'],
-    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $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 7c45881..db09a78 100644
--- a/components/textfield.inc
+++ b/components/textfield.inc
@@ -122,16 +122,25 @@ function _webform_edit_textfield($component) {
  * Implements _webform_render_component().
  */
 function _webform_render_textfield($component, $value = NULL, $filter = TRUE) {
+  $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']), array(), $context)
+    : t($component['extra']['description'], 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'], NULL, 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']) : $component['extra']['description'],
+    '#description' => $description,
     '#attributes' => $component['extra']['attributes'],
     '#theme_wrappers' => array('webform_element'),
     '#webform_component' => $component,
diff --git a/components/time.inc b/components/time.inc
index f417020..447a638 100644
--- a/components/time.inc
+++ b/components/time.inc
@@ -84,13 +84,22 @@ function _webform_edit_time($component) {
  * Implements _webform_render_component().
  */
 function _webform_render_time($component, $value = NULL, $filter = TRUE) {
+  $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']), 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']) : $component['extra']['description'],
+    '#description' => $description,
     '#element_validate' => array('webform_validate_time'),
     '#hourformat' => $component['extra']['hourformat'],
     '#default_value' => $filter ? _webform_filter_values($component['value'], NULL, NULL, NULL, FALSE) : $component['value'],
diff --git a/webform.module b/webform.module
index e6da934..87fcdda 100644
--- a/webform.module
+++ b/webform.module
@@ -3648,3 +3648,20 @@ function webform_mollom_form_info($form_id) {
 
   return $form_info;
 }
+
+/**
+ * Runs every array element through t().
+ *
+ * @param array $array
+ *   The array to run through t().
+ *
+ * @return array
+ *   The translated array.
+ */
+function webform_array_t($array) {
+  foreach ($array as &$item) {
+    $item = t($item, array(), array('context' => 'webform component'));
+  }
+
+  return $array;
+}
-- 
1.7.6.1

