function _webform_localization_translate_component in Webform Localization 7
Same name and namespace in other branches
- 7.4 includes/webform_localization.i18n.inc \_webform_localization_translate_component()
Translates the component properties that are translatable.
These are found in under 'translated_strings' in the 'extra' array of the component, which is build when the component is inserted / updated, or when all webform strings are updated from admin/config/regional/translate/i18n_string.
Parameters
array $element: The FAPI renderable array of the component instance.
array $component: The component.
2 calls to _webform_localization_translate_component()
File
- includes/
webform_localization.i18n.inc, line 28 - Webform Localization i18n_string integration.
Code
function _webform_localization_translate_component(&$element, $component) {
if (isset($component['extra']['translated_strings']) && is_array($component['extra']['translated_strings'])) {
foreach ($component['extra']['translated_strings'] as $name) {
$name_list = explode(':', $name);
$current_element =& $element;
if (strpos($name_list[3], '[') !== FALSE) {
// The property is deeper in the renderable array, we must extract the
// the place where it is.
list($children, $property) = explode(']#', $name_list[3]);
// Remove the '[' from the begining of the string.
$children = drupal_substr($children, 1);
$children_array = explode('][', $children);
foreach ($children_array as $child) {
if (isset($current_element[$child])) {
$current_element =& $current_element[$child];
}
else {
continue;
}
}
}
else {
// Remove the '#' from the begining of the property, for consistency.
$property = drupal_substr($name_list[3], 1);
}
if (strpos($property, '-') !== FALSE) {
// If property is array, we extract the key from the property.
list($property, $key) = explode('-', $property);
if (isset($current_element['#' . $property][$key])) {
$current_element['#' . $property][$key] = i18n_string($name, $current_element['#' . $property][$key], array(
'sanitize' => FALSE,
));
}
}
else {
// If we are dealing with option groups.
if (isset($name_list[4]) && strpos($name_list[4], '/-') !== FALSE) {
$option_group = str_replace('/-', '', $name_list[4]);
// If it's a element.
if (isset($name_list[5])) {
$current_element['#' . $property][$option_group][$name_list[5]] = i18n_string($name, $current_element['#' . $property][$option_group][$name_list[5]]);
}
else {
// If it's a option group we translate the key.
$translated_option_group = i18n_string($name, $option_group);
if ($translated_option_group != $option_group) {
_webform_localization_array_key_replace($current_element['#' . $property], $option_group, $translated_option_group);
}
}
}
else {
// Else we can treat the property as string.
if (isset($current_element['#' . $property])) {
if ($property == 'markup' && $current_element['#type'] == 'markup') {
$current_element['#' . $property] = i18n_string($name, $current_element['#' . $property], array(
'format' => $current_element['#format'],
));
}
elseif ($property == 'description') {
$current_element['#' . $property] = i18n_string($name, $current_element['#' . $property], array(
'format' => I18N_STRING_FILTER_XSS,
));
}
else {
$current_element['#' . $property] = i18n_string($name, $current_element['#' . $property]);
}
}
}
}
}
}
}