// If the module defines any textgroup, get all strings for this group
if ($groups = module_invoke($module, 'i18n_string_info')) {
foreach ($groups as $group) {
- $strings = array_merge_recursive($strings, i18n_string_group_string_list($group));
+ $strings = i18n_string_array_merge($strings, i18n_string_group_string_list($group));
}
}
else {
foreach ($object_types as $type => $type_info) {
if (($group = i18n_string_object_info($type, 'textgroup')) && !in_array($group, $groups)) {
if ($group_strings = i18n_string_object_type_string_list($type)) {
- $strings = array_merge_recursive($strings, $group_strings);
+ $strings = i18n_string_array_merge($strings, $group_strings);
}
}
}
foreach (i18n_string_group_object_types($group) as $type) {
$type_strings = i18n_string_object_type_string_list($type);
if ($type_strings && !empty($type_strings[$group])) {
- $strings[$group] = isset($strings[$group]) ? array_merge_recursive($strings[$group], $type_strings[$group]) : $type_strings[$group];
+ $strings[$group] = isset($strings[$group]) ? i18n_string_array_merge($strings[$group], $type_strings[$group]) : $type_strings[$group];
}
}
}
if ($objects = module_invoke_all('i18n_string_objects', $type)) {
foreach ($objects as $object) {
if ($object_strings = i18n_object($type, $object)->get_properties()) {
- $strings = array_merge_recursive($strings, $object_strings);
+ $strings = i18n_string_array_merge($strings, $object_strings);
}
}
}
return $strings;
}
+
+/**
+ * Merges multiple arrays, recursively, and returns the merged array.
+ *
+ * This function is not equivalent to PHP's array_merge_recursive(),
+ * as this version leaves integer keys intact.
+ *
+ * @see drupal_array_merge_deep(), @see array_merge_recursive()
+ *
+ * @param ...
+ * Arrays to merge.
+ * @return
+ * The merged array.
+ */
+function i18n_string_array_merge() {
+ $arrays = func_get_args();
+ $result = array();
+
+ foreach ($arrays as $array) {
+ foreach ($array as $key => $value) {
+ // Recurse when both values are arrays.
+ if (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
+ $result[$key] = i18n_string_array_merge($result[$key], $value);
+ }
+ // Otherwise, use the latter value, overriding any previous value.
+ else {
+ $result[$key] = $value;
+ }
+ }
+ }
+
+ return $result;
+}
\ No newline at end of file