summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--i18n_string/i18n_string.admin.inc4
-rw-r--r--i18n_string/i18n_string.i18n.inc37
2 files changed, 37 insertions, 4 deletions
diff --git a/i18n_string/i18n_string.admin.inc b/i18n_string/i18n_string.admin.inc
index 19a5182..2042d53 100644
--- a/i18n_string/i18n_string.admin.inc
+++ b/i18n_string/i18n_string.admin.inc
@@ -340,7 +340,7 @@ function i18n_string_module_string_list($module) {
// 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 {
@@ -359,7 +359,7 @@ function i18n_string_module_string_list($module) {
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);
}
}
}
diff --git a/i18n_string/i18n_string.i18n.inc b/i18n_string/i18n_string.i18n.inc
index f923a05..98ada90 100644
--- a/i18n_string/i18n_string.i18n.inc
+++ b/i18n_string/i18n_string.i18n.inc
@@ -33,7 +33,7 @@ function i18n_string_i18n_string_list($group) {
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];
}
}
}
@@ -64,9 +64,42 @@ function i18n_string_object_type_string_list($type) {
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