function _webform_localization_component_translation_parse in Webform Localization 7
Same name and namespace in other branches
- 7.4 includes/webform_localization.i18n.inc \_webform_localization_component_translation_parse()
Parse a component renderable array to find the translatable properties.
Create / update or remove translation source for translatable properties of a webform component.
Parameters
array $element: The renderable array to be parsed.
array $component: The component which was rendered.
Return value
An array of translatabled webform properties.
1 call to _webform_localization_component_translation_parse()
- webform_localization_component_update_translation_strings in includes/
webform_localization.i18n.inc - Update / create translation source for all the translatable poperties.
File
- includes/
webform_localization.i18n.inc, line 131 - Webform Localization i18n_string integration.
Code
function _webform_localization_component_translation_parse($element, $component) {
$translated_properies = array();
if (!isset($element['#parents'])) {
$element['#parents'] = array();
}
if (isset($element['#translatable']) && is_array($element['#translatable'])) {
foreach ($element['#translatable'] as $key) {
if (isset($element['#' . $key]) && $element['#' . $key] != '') {
if (isset($element['#parents']) && count($element['#parents'])) {
$property = '[' . implode('][', $element['#parents']) . ']#' . $key;
}
else {
$property = '#' . $key;
}
if (is_array($element['#' . $key])) {
// If the translatable property is an array, we translate the
// children.
foreach ($element['#' . $key] as $elem_key => $elem_value) {
// If the child if an array, we translate the elements.
if (is_array($elem_value)) {
foreach ($elem_value as $k => $v) {
$name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property, '/-' . $elem_key . '/-', $k);
$translated_properies[] = $name;
i18n_string($name, $v, array(
'update' => TRUE,
));
}
$name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property, '/-' . $elem_key . '/-');
$translated_properies[] = $name;
i18n_string($name, $elem_key, array(
'update' => TRUE,
));
}
else {
// If the child is not an array.
$name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property . '-' . $elem_key);
$translated_properies[] = $name;
i18n_string($name, $elem_value, array(
'update' => TRUE,
));
}
}
}
else {
/**
* If the translatable property is not an array,
* it can be treated as a string.
*/
$name = webform_localization_i18n_string_name($component['nid'], $component['cid'], $property);
$translated_properies[] = $name;
i18n_string($name, $element['#' . $key], array(
'update' => TRUE,
));
}
}
}
}
// Recursevly call the function on the children, after adding the children
// name to its #parents array.
foreach (element_children($element) as $child) {
$element[$child]['#parents'] = $element['#parents'];
$element[$child]['#parents'][] = $child;
// Add the translated propertied to the list.
$translated_properies = array_merge($translated_properies, _webform_localization_component_translation_parse($element[$child], $component));
}
return $translated_properies;
}