grid.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @file
  4. * Webform localizations for grid component.
  5. * Translates the analysis component properties that are translatable.
  6. *
  7. * These are found in under 'translated_strings' in the 'extra' array of the
  8. * component, which is build when the component is inserted / updated, or
  9. * when all webform strings are updated from
  10. * admin/config/regional/translate/i18n_string.
  11. */
  12. /**
  13. * Implements _webform_localization_analysis_data_component().
  14. *
  15. * @param array $data
  16. * The data array of component results.
  17. * @param array $node
  18. * The node
  19. * @param array $component
  20. * The component.
  21. *
  22. * @return array
  23. * Translated data array of component results.
  24. */
  25. function _webform_localization_analysis_data_grid($data, $node, $component) {
  26. if (!isset($component['extra']['translated_strings']) || !is_array($component['extra']['translated_strings'])) {
  27. return $data;
  28. }
  29. $options_key_lookup = _webform_localization_string_to_key($component['extra']['options']);
  30. $questions_key_lookup = _webform_localization_string_to_key($component['extra']['questions']);
  31. foreach ($component['extra']['translated_strings'] as $name) {
  32. $name_list = explode(':', $name);
  33. // Translate options / questions.
  34. list (, $key) = explode('-', $name_list[3]);
  35. if (strpos($name_list[3], 'grid_options') && $name_list[3] !== '#title') {
  36. if (isset($options_key_lookup[$key])) {
  37. foreach ($data['table_header'] as $index => $row) {
  38. if ($row == $options_key_lookup[$key]) {
  39. $data['table_header'][$index] = i18n_string($name, $row);
  40. }
  41. }
  42. }
  43. }
  44. if (strpos($name_list[3], 'grid_questions') && $name_list[3] !== '#title') {
  45. if (isset($questions_key_lookup[$key])) {
  46. foreach ($data['table_rows'] as $index => $row) {
  47. if (trim($row[0]) == trim($questions_key_lookup[$key])) {
  48. $data['table_rows'][$index][0] = i18n_string($name, $row[0]);
  49. }
  50. }
  51. }
  52. }
  53. }
  54. return $data;
  55. }