Skip to content

Commit 18450dc

Browse files
committed
Improved performance of toFlat() method
1 parent 3d12330 commit 18450dc

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/Classes/ExportLocalizations.php

+6-17
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,18 @@ public function toArray()
115115
*
116116
* @return array
117117
*/
118-
public function toFlat( $array = [], $prefix = '' )
118+
public function toFlat( $prefix = '.' )
119119
{
120-
function flatten( $array = [], $prefix = '', $default = [] )
121-
{
122-
123-
$array = ( count( $array ) ) ? $array : $default;
124-
$result = [];
120+
$results = [];
121+
foreach ( $this->strings as $lang => $strings ) {
125122

126-
foreach ( $array as $key => $value ) {
127-
$new_key = $prefix . ( empty( $prefix ) ? '' : '.' ) . $key;
123+
foreach ( $strings as $lang_array => $lang_messages ) {
128124

129-
if ( is_array( $value ) ) {
130-
$result = array_merge( $result, flatten( $value, $new_key ) );
131-
} else {
132-
$result[ $new_key ] = $value;
133-
}
125+
$key = $lang . $prefix . $lang_array;
126+
$results[ $key ] = $lang_messages;
134127
}
135-
136-
return $result;
137128
}
138129

139-
$results = flatten( $array, $prefix, $this->strings );
140-
141130
return $results;
142131
}
143132

0 commit comments

Comments
 (0)