| @@ 35-64 (lines=30) @@ | ||
| 32 | } |
|
| 33 | ||
| 34 | // ...$args works in PHP 5.6+ |
|
| 35 | protected static function translateNestedValues(...$args) |
|
| 36 | { |
|
| 37 | if (count($args) === 0) { |
|
| 38 | trigger_error('Invalid argument count for translation!', E_USER_WARNING); |
|
| 39 | return []; |
|
| 40 | } |
|
| 41 | ||
| 42 | if (count($args) === 1) { |
|
| 43 | return $args[0]; |
|
| 44 | } |
|
| 45 | ||
| 46 | $value = Flynt\Helpers::extractNestedDataFromArray($args); |
|
| 47 | ||
| 48 | if (empty($value)) { |
|
| 49 | return null; |
|
| 50 | } |
|
| 51 | ||
| 52 | if (is_array($value)) { |
|
| 53 | // Loop through array and apply translations while keeping keys intact |
|
| 54 | // NOTE: assuming it's a single dimensional array |
|
| 55 | return array_reduce(array_keys($value), function ($carry, $key) use ($value) { |
|
| 56 | return array_merge($carry, [ |
|
| 57 | $key => _x($value[$key], $key, 'flynt-starter-theme') |
|
| 58 | ]); |
|
| 59 | }, []); |
|
| 60 | } else { |
|
| 61 | $context = array_pop($args); |
|
| 62 | return _x($value, $context, 'flynt-starter-theme'); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| @@ 34-63 (lines=30) @@ | ||
| 31 | } |
|
| 32 | ||
| 33 | // ...$args works in PHP 5.6+ |
|
| 34 | protected static function translateNestedValues(...$args) |
|
| 35 | { |
|
| 36 | if (count($args) === 0) { |
|
| 37 | trigger_error('Invalid argument count for translation!', E_USER_WARNING); |
|
| 38 | return []; |
|
| 39 | } |
|
| 40 | ||
| 41 | if (count($args) === 1) { |
|
| 42 | return $args[0]; |
|
| 43 | } |
|
| 44 | ||
| 45 | $value = Flynt\Helpers::extractNestedDataFromArray($args); |
|
| 46 | ||
| 47 | if (empty($value)) { |
|
| 48 | return null; |
|
| 49 | } |
|
| 50 | ||
| 51 | if (is_array($value)) { |
|
| 52 | // Loop through array and apply translations while keeping keys intact |
|
| 53 | // NOTE: assuming it's a single dimensional array |
|
| 54 | return array_reduce(array_keys($value), function ($carry, $key) use ($value) { |
|
| 55 | return array_merge($carry, [ |
|
| 56 | $key => _x($value[$key], $key, 'flynt-starter-theme') |
|
| 57 | ]); |
|
| 58 | }, []); |
|
| 59 | } else { |
|
| 60 | $context = array_pop($args); |
|
| 61 | return _x($value, $context, 'flynt-starter-theme'); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||